{"id":15491502,"url":"https://github.com/diegohaz/parse-prop-types","last_synced_at":"2025-04-10T00:19:23.136Z","repository":{"id":40295039,"uuid":"120214671","full_name":"diegohaz/parse-prop-types","owner":"diegohaz","description":"Parses React prop-types into a readable object","archived":false,"fork":false,"pushed_at":"2022-12-06T19:46:21.000Z","size":1019,"stargazers_count":69,"open_issues_count":16,"forks_count":5,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-10-19T10:04:57.809Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/diegohaz.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-02-04T19:14:07.000Z","updated_at":"2024-04-27T05:36:56.000Z","dependencies_parsed_at":"2023-01-23T12:25:15.548Z","dependency_job_id":null,"html_url":"https://github.com/diegohaz/parse-prop-types","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/diegohaz%2Fparse-prop-types","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/diegohaz%2Fparse-prop-types/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/diegohaz%2Fparse-prop-types/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/diegohaz%2Fparse-prop-types/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/diegohaz","download_url":"https://codeload.github.com/diegohaz/parse-prop-types/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248131508,"owners_count":21052862,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-02T07:54:04.626Z","updated_at":"2025-04-10T00:19:23.109Z","avatar_url":"https://github.com/diegohaz.png","language":"JavaScript","readme":"# parse-prop-types\n\n[![Generated with nod](https://img.shields.io/badge/generator-nod-2196F3.svg?style=flat-square)](https://github.com/diegohaz/nod)\n[![NPM version](https://img.shields.io/npm/v/parse-prop-types.svg?style=flat-square)](https://npmjs.org/package/parse-prop-types)\n[![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)\n\nParses React `prop-types` into a readable object at runtime.\n\n## Install\n\n    $ npm install --save parse-prop-types\n\n## Usage\n\n```jsx\nimport React from 'react'\nimport PropTypes from 'prop-types'\nimport parsePropTypes from 'parse-prop-types'\n\nconst MyComponent = ({ name, show }) =\u003e (\n  show ? \u003cdiv\u003e{name}\u003c/div\u003e : null\n)\n\nMyComponent.propTypes = {\n  name: PropTypes.string,\n  show: PropTypes.oneOfType([PropTypes.bool, propTypes.string]).isRequired,\n}\n\nMyComponent.defaultProps = {\n  name: 'Haz',\n}\n\nparsePropTypes(MyComponent)\n```\n\nThe returned object is compatible with [`react-docgen`](https://github.com/reactjs/react-docgen):\n\n```js\n{\n  name: {\n    type: {\n      name: 'string',\n    },\n    required: false,\n    defaultValue: {\n      value: 'Haz',\n    },\n  },\n  show: {\n    type: {\n      name: 'oneOfType',\n      value: [\n        { name: 'bool' },\n        { name: 'string' },\n      ],\n    },\n    required: true,\n  },\n}\n```\n\n**IMPORTANT:** To avoid issues reading any component's propTypes, it is recommendable importing this package before defining your components' propTypes or before import any third-party component. Import this package in your entry point file could be a great option.\n\n```\n// index.js (entry point file)\nimport \"parse-prop-types\";\n```\n\n## Why not [`react-docgen`](https://github.com/reactjs/react-docgen)?\n\n[`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.\n\n`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.\n\n## API\n\n\u003c!-- Generated by documentation.js. Update this documentation by updating the source code. --\u003e\n\n#### Table of Contents\n\n-   [parsePropTypes](#parseproptypes)\n\n### parsePropTypes\n\n**Parameters**\n\n-   `$0` **any** \n    -   `$0.propTypes`   (optional, default `{}`)\n    -   `$0.defaultProps`   (optional, default `{}`)\n\nReturns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** \n\n## License\n\nMIT © [Diego Haz](https://github.com/diegohaz)\n","funding_links":[],"categories":["📦 Legacy \u0026 Inactive Projects"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdiegohaz%2Fparse-prop-types","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdiegohaz%2Fparse-prop-types","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdiegohaz%2Fparse-prop-types/lists"}