# parse-prop-types

> Parses React prop-types into a readable object

Latest version **0.3.0** (published 2018-07-10) · MIT license · 0 weekly downloads

## Install

```sh
npm install parse-prop-types
pnpm add parse-prop-types
yarn add parse-prop-types
bun add parse-prop-types
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.3.0 |
| Published | 2018-07-10 |
| First published | 2018-02-04 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=6 |
| Dependencies | 0 |
| Unpacked size | 9.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 69 |
| Author | Diego Haz |
| Maintainers | diegohaz |
| Keywords | parse-prop-types, react, prop-types |

## Links

- npm: https://www.npmjs.com/package/parse-prop-types
- Repository: https://github.com/diegohaz/parse-prop-types
- Homepage: https://github.com/diegohaz/parse-prop-types#readme
- Issues: https://github.com/diegohaz/parse-prop-types/issues
- npm.io page: https://npm.io/package/parse-prop-types

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 0.3.0 (latest) — 2018-07-10
- 0.2.0 — 2018-02-15
- 0.1.1 — 2018-02-04
- 0.1.0 — 2018-02-04

## README

# parse-prop-types

[![Generated with nod](https://img.shields.io/badge/generator-nod-2196F3.svg?style=flat-square)](https://github.com/diegohaz/nod)
[![NPM version](https://img.shields.io/npm/v/parse-prop-types.svg?style=flat-square)](https://npmjs.org/package/parse-prop-types)
[![Build Status](https://img.shields.io/travis/diegohaz/parse-prop-types/master.svg?style=flat-square)](https://travis-ci.org/diegohaz/parse-prop-types) [![Coverage Status](https://img.shields.io/codecov/c/github/diegohaz/parse-prop-types/master.svg?style=flat-square)](https://codecov.io/gh/diegohaz/parse-prop-types/branch/master)

Parses React `prop-types` into a readable object at runtime.

## Install

    $ npm install --save parse-prop-types

## Usage

```jsx
import React from 'react'
import PropTypes from 'prop-types'
import parsePropTypes from 'parse-prop-types'

const MyComponent = ({ name, show }) => (
  show ? <div>{name}</div> : null
)

MyComponent.propTypes = {
  name: PropTypes.string,
  show: PropTypes.oneOfType([PropTypes.bool, propTypes.string]).isRequired,
}

MyComponent.defaultProps = {
  name: 'Haz',
}

parsePropTypes(MyComponent)
```

The returned object is compatible with [`react-docgen`](https://github.com/reactjs/react-docgen):

```js
{
  name: {
    type: {
      name: 'string',
    },
    required: false,
    defaultValue: {
      value: 'Haz',
    },
  },
  show: {
    type: {
      name: 'oneOfType',
      value: [
        { name: 'bool' },
        { name: 'string' },
      ],
    },
    required: true,
  },
}
```

## Why not [`react-docgen`](https://github.com/reactjs/react-docgen)?

[`react-docgen`](https://github.com/reactjs/react-docgen) reads file contents in order to find prop types definitions. It has some limitations, such as not allowing computed prop types and, in several situations, not being able to parse file contents correctly.

`parse-prop-types`, on the other hand, doesn't deal with file contents. Instead, it parses prop types at runtime by receiving the component object itself.

## API

<!-- Generated by documentation.js. Update this documentation by updating the source code. -->

#### Table of Contents

-   [parsePropTypes](#parseproptypes)

### parsePropTypes

**Parameters**

-   `$0` **any** 
    -   `$0.propTypes`   (optional, default `{}`)
    -   `$0.defaultProps`   (optional, default `{}`)

Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** 

## License

MIT © [Diego Haz](https://github.com/diegohaz)

---
_Source: https://npm.io/package/parse-prop-types · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
