npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@structured-types/prop-types-plugin

v3.46.12

Published

react prop-types plugin for structured-types

Downloads

83

Readme

Table of contents

Overview

structured-types plugin to extract react prop-types specific properties. If you are using typescript props for your react components, please see the react plugin.

Getting started

1. Installation

$ npm install @structured-types/prop-types-plugin --save-dev

2. Your API source file (Component.tsx):

import React from 'react';
import PropTypes from 'prop-types';

/**
 * MyComponent special component
 */
export const MyComponent = ({ stringProp }) => <div>{stringProp}</div>;

MyComponent.propTypes = {
  /** stringProp description */
  stringProp: PropTypes.string,
  /** numberProp description */
  numberProp: PropTypes.number.isRequired,
};

MyComponent.defaultProps = {
  stringProp: 'test',
};

3. Your documentation extraction

import { parseFiles } from '@structured-types/api';
import propTypesPlugin from '@structured-types/prop-types-plugin';
//optional you can also use react plugin for any typescript react props
import reactPlugin from '@structured-types/react-plugin';

const docs = parseFiles(['../src/components/Component.tsx'], {
  plugins: [propTypesPlugin, reactPlugin],
});

4. The result

{
  "MyComponent": {
    "kind": 11,
    "extension": "react-prop-types",
    "properties": [
      {
        "name": "stringProp",
        "kind": 1,
        "optional": true,
        "description": "stringProp description",
        "value": "test"
      },
      {
        "name": "numberProp",
        "kind": 2,
        "description": "numberProp description"
      }
    ],
    "description": "MyComponent special component",
    "name": "MyComponent"
  }
}

Configuration

The react-prop-types typescript uses the default configurations from the react plugin, and you can also add or modify some of the other parsing options that will be specific only for the found react components. For other typescript/jsdoc types, the global options passed to parseFiles will still apply.

Enable the children props.

By default, the plugin removes the children property that is part of most react components, here is an example of how to re-enable the children properties by disabling the default filter:

import { parseFiles } from '@structured-types/api';
import propTypesPlugin from '@structured-types/prop-types-plugin';

const docs = parseFiles(['../src/components/Component.tsx'], {
  plugins: [{ ...propTypesPlugin, filter: undefined }],
});

ParsePlugin

type

Plugin type - provides the plugin name and the type resolver

defined in @structured-types/api/packages/api/src/ts-utils.ts

properties

| Name | Type | Parent | Default | Description | | ------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------- | ------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | tsOptions | ts.CompilerOptions | DocsOptions | | | | internalTypes | Record<string, PropKind> | ParseOptions | | internal types - libs by default includes classes such as String , Function ... | | extract | string[] | ParseOptions | | list of export names to be extracted. by default all exports are extracted | | filter | function (prop*kind: name: stringalias: stringparentname*: stringloc: SourceLocationlocfilePath: stringloc: SourcePositionsoptional: booleanreadonly: booleanabstract: booleanasync: booleanvisibility: "private" | "protected" | "public"static: booleantype: stringextension: stringdescription: stringfires: string[]see: string[]examples: JSDocExample[]tags: JSDocPropTag[]summary: stringdeprecated: string | trueignore: booleanusage: type[]) => boolean | ParseOptions | | filter properties function. By default filter out all props with ignore === true | | maxDepth | number | ParseOptions | 6 | max depth for extracting child props. | | collectHelpers | boolean | ParseOptions | | whether to save "helper" props that are used by the main parsed props if set to false will result in a smaller result set | | collectGenerics | boolean | ParseOptions | true | whether to collect generics parameters | | collectParameters | boolean