introspective-prop-types

introspective-prop-types

Usage no npm install needed!

<script type="module">
  import introspectivePropTypes from 'https://cdn.skypack.dev/introspective-prop-types';
</script>

README

Introspective Prop Types

Add some :sparkles:metadata:sparkles: to your Prop Types.

PropTypes.string.type           // => 'string'
PropTypes.string.required       // => false
PropTypes.oneOf([1, 2, 3]).type // => 'oneOf'
PropTypes.oneOf([1, 2, 3]).arg  // => [1, 2, 3]

Build Status Coverage Status MIT license

Installation

npm install introspective-prop-types

Usage

import PropTypes from 'introspective-prop-types'

propTypes = {
  name: PropTypes.string.isRequired
  color: PropTypes.oneOf(['red', 'green', 'blue']),
  car: PropTypes.shape({
    year: PropTypes.number.isRequired,
    make: PropTypes.string.isRequired
    model: PropTypes.string.isRequired,
  })
}

propTypes.name.type         // => 'string'
propTypes.name.required     // => true

propTypes.color.type        // => 'oneOf'
propTypes.color.required    // => false
propTypes.color.arg         // => ['red', 'green', 'blue']

propTypes.car.type          // => 'shape'
propTypes.car.arg.year.type // => 'number'

This is a drop-in replacement for facebook/prop-types.

You can replace any prop-types import with introspective-prop-types and get prop types with metadata. :beers:

Additional prop-type libraries

This package adds metadata to the following additional libraries. Just replace your current imports with their introspective version.

If you'd like metadata in any other prop-type libraries, please submit an issue.