Skip to content

boiawang/component-props-schema

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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'
      }
    }
  } 
}

About

get component props schema

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published