https://github.com/markalfred/introspective-prop-types
Add some ✨metadata✨ to your Prop Types
https://github.com/markalfred/introspective-prop-types
introspection metadata proptypes react
Last synced: about 1 month ago
JSON representation
Add some ✨metadata✨ to your Prop Types
- Host: GitHub
- URL: https://github.com/markalfred/introspective-prop-types
- Owner: markalfred
- License: mit
- Created: 2019-08-02T06:50:09.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2023-03-04T04:27:39.000Z (over 3 years ago)
- Last Synced: 2025-10-09T23:28:53.622Z (9 months ago)
- Topics: introspection, metadata, proptypes, react
- Language: TypeScript
- Homepage:
- Size: 1.19 MB
- Stars: 1
- Watchers: 1
- Forks: 1
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Introspective Prop Types
Add some :sparkles:metadata:sparkles: to your Prop Types.
```js
PropTypes.string.type // => 'string'
PropTypes.string.required // => false
PropTypes.oneOf([1, 2, 3]).type // => 'oneOf'
PropTypes.oneOf([1, 2, 3]).arg // => [1, 2, 3]
```
[](https://api.travis-ci.org/markalfred/introspective-prop-types.svg?branch=master)
[](https://coveralls.io/github/markalfred/introspective-prop-types?branch=master)
[](http://opensource.org/licenses/MIT)
## Installation
```bash
npm install introspective-prop-types
```
## Usage
```js
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`](https://github.com/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.
- [`react-bootstrap/prop-types-extra`](https://github.com/react-bootstrap/prop-types-extra): `import PropTypesExtra from 'introspective-prop-types/extra'`
If you'd like metadata in any other prop-type libraries, please [submit an issue](https://github.com/markalfred/introspective-prop-types/issues).