🚨 Shai-Hulud Strikes Again:834 Packages Compromised.Technical Analysis →
Socket
Book a DemoInstallSign in
Socket

react-docgen-to-json-schema

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-docgen-to-json-schema

Converts react-docgen output to JSON Schema.

latest
Source
npmnpm
Version
0.2.0
Version published
Maintainers
1
Created
Source

react-docgen-to-json-schema

Converts react-docgen output to JSON Schema.

NPM Build Status JavaScript Style Guide

Install

This module requires node >= 6.

npm install --save react-docgen-to-json-schema

Usage

Take this example React component.

import { Component } from 'react'
import PropTypes from 'prop-types'

/**
 * General component description.
 */
export default class MyComponent extends Component {
  static propTypes = {
    /**
     * Description foo.
     */
    foo: PropTypes.number.isRequired,

    /**
     * Description bar.
     *
     * - markdown list-item 1
     * - markdown list-item 2
     */
    bar: PropTypes.string,

    /**
     * Description baz.
     */
    baz: PropTypes.bool
  }

  static defaultProps = {
    bar: 'bar'
  }

  render: () => { }
}

react-docgen generates the following JSON:

{
  "description": "General component description.",
  "displayName": "MyComponent",
  "methods": [],
  "props": {
    "foo": {
      "type": {
        "name": "number"
      },
      "required": true,
      "description": "Description foo."
    },
    "bar": {
      "type": {
        "name": "string"
      },
      "required": false,
      "description": "Description bar.\n\n- markdown list-item 1\n- markdown list-item 2",
      "defaultValue": {
        "value": "'bar'",
        "computed": false
      }
    },
    "baz": {
      "type": {
        "name": "bool"
      },
      "required": false,
      "description": "Description baz."
    }
  }
}

react-docgen-to-json-schema takes in this JSON and converts it to the following JSON Schema:

{
  "title": "MyComponent",
  "type": "object",
  "properties": {
    "foo": {
      "type": "number",
      "description": "Description foo."
    },
    "bar": {
      "type": "string",
      "description": "Description bar.\n\n- markdown list-item 1\n- markdown list-item 2",
      "default": "bar"
    },
    "baz": {
      "type": "boolean",
      "description": "Description baz."
    }
  },
  "required": [
    "foo"
  ]
}

API

reactDocgenToJSONSchema

Converts a single JSON object extracted by react-docgen to JSON Schema.

  • input object JSON object documenting a single component.

Status

  • PropTypes
  • PropTypes.array
  • PropTypes.bool
  • PropTypes.func
  • PropTypes.number
  • PropTypes.object
  • PropTypes.string
  • PropTypes.symbol
  • PropTypes.node
  • PropTypes.element
  • PropTypes.instanceOf
  • PropTypes.oneOf (enums)
  • PropTypes.oneOfType (unions)
  • PropTypes.arrayOf
  • PropTypes.objectOf
  • PropTypes.shape
  • PropTypes.any
  • PropTypes isRequired
  • PropTypes custom function
  • PropTypes default values

License

MIT © Hydrate

Keywords

react

FAQs

Package last updated on 06 Feb 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts