Skip to content

Latest commit

 

History

History
57 lines (50 loc) · 951 Bytes

README.md

File metadata and controls

57 lines (50 loc) · 951 Bytes

component-props-schema

Get schema data based on propTypes and defaultProps.

Usage

let getComponentPropsSchema = require('component-props-schema');
console.log(getComponentPropsSchema('./demo.js'));

Intput

// demo.js
class Video extends React.Component {
  static defaultProps = {
    autoPlay: false,
    maxLoops: 10
  };

  static propTypes = {
    autoPlay: PropTypes.bool.isRequired,
    maxLoops: PropTypes.number,
    posterFrameSrc: PropTypes.string.isRequired,
    videoSrc: PropTypes.string.isRequired
  };
}

export default Video;

Output

{
  name: 'Video',
  propsSchema: {
    type: 'object',
    properties: {
      autoPlay: {
        isRequired: true,
        type: 'bool'
      },
      maxLoops: {
        type: 'number'
      },
      posterFrameSrc: {
        isRequired: true,
        type: 'string'
      },
      src: {
        isRequired: true,
        type: 'string'
      }
    }
  } 
}