{"_id":"react-docgen-typescript-dumi-tmp","_rev":"2893584","name":"react-docgen-typescript-dumi-tmp","description":"[![Build Status](https://travis-ci.org/styleguidist/react-docgen-typescript.svg)](https://travis-ci.org/styleguidist/react-docgen-typescript)","dist-tags":{"latest":"1.22.1-0"},"maintainers":[{"name":"peachscript","email":""}],"time":{"modified":"2022-12-08T07:26:02.000Z","created":"2021-06-28T16:31:44.989Z","1.22.1-0":"2021-06-28T16:31:44.989Z"},"users":{},"repository":{"type":"git","url":"git+https://github.com/styleguidist/react-docgen-typescript.git"},"versions":{"1.22.1-0":{"name":"react-docgen-typescript-dumi-tmp","version":"1.22.1-0","description":"[![Build Status](https://travis-ci.org/styleguidist/react-docgen-typescript.svg)](https://travis-ci.org/styleguidist/react-docgen-typescript)","homepage":"https://github.com/styleguidist/react-docgen-typescript/","bugs":{"url":"https://github.com/styleguidist/react-docgen-typescript/issues"},"main":"lib/index.js","types":"lib/index.d.ts","scripts":{"precommit":"lint-staged","tsc":"tsc","tsc:watch":"tsc -w","test":"tsc && mocha --timeout 10000 ./lib/**/__tests__/**.js","test:debug":"tsc && mocha --debug ./lib/**/__tests__/**.js","print":"npm run tsc && node ./lib/print.js","print:sample1":"npm run tsc && node ./lib/print.js ./src/__tests__/data/ColumnHigherOrderComponent.tsx simple","lint":"eslint -c lint.json 'src/**/*.{ts,tsx}'","lint:fix":"npm run lint -- --fix","prettier:base":"prettier --parser typescript --single-quote --trailing-comma none","prettier:check":"npm run prettier:base -- -l \"src/**/*.{ts,tsx}\"","prettier:write":"npm run prettier:base -- --write \"src/**/*.{ts,tsx}\""},"license":"MIT","peerDependencies":{"typescript":">= 3.x"},"devDependencies":{"@types/chai":"^4.1.0","@types/lodash":"^4.14.137","@types/mocha":"^5.2.5","@types/node":"^10.5.6","@types/prop-types":"^15.5.4","@types/react":"^16.9.34","@types/source-map-support":"^0.4.1","chai":"^4.1.2","eslint":"^7.5.0","husky":"^0.14.3","install":"^0.13.0","lint-staged":"^7.3.0","lodash":"^4.17.15","mocha":"^5.2.0","prettier":"^1.19.1","prop-types":"^15.6.2","react":"^16.4.2","source-map-support":"^0.5.6","typescript":"3.5.2"},"repository":{"type":"git","url":"git+https://github.com/styleguidist/react-docgen-typescript.git"},"dependencies":{},"_id":"react-docgen-typescript-dumi-tmp@1.22.1-0","_nodeVersion":"15.6.0","_npmVersion":"7.4.0","dist":{"shasum":"6f452de05c5c114a6e1dd60b34930afaa7ae39a0","size":39623,"noattachment":false,"key":"/react-docgen-typescript-dumi-tmp/-/react-docgen-typescript-dumi-tmp-1.22.1-0.tgz","tarball":"http://registry.cnpm.dingdandao.com/react-docgen-typescript-dumi-tmp/download/react-docgen-typescript-dumi-tmp-1.22.1-0.tgz"},"_npmUser":{"name":"peachscript","email":"scdzwyxst@gmail.com"},"directories":{},"maintainers":[{"name":"peachscript","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/react-docgen-typescript-dumi-tmp_1.22.1-0_1624897904764_0.48635658085031674"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2021-12-20T07:28:02.253Z","publish_time":1624897904989,"_cnpm_publish_time":1624897904989}},"readme":"# react-docgen-typescript\n\n[![Build Status](https://travis-ci.org/styleguidist/react-docgen-typescript.svg)](https://travis-ci.org/styleguidist/react-docgen-typescript)\n\n![](https://nodei.co/npm/react-docgen-typescript.png?downloadRank=true&downloads=true)\n\nA simple parser for React properties defined in TypeScript instead of propTypes.\n\nIt can be used with [React Styleguidist](https://github.com/styleguidist/react-styleguidist).\n\n## Installation\n\n```bash\nnpm install --save-dev react-docgen-typescript\n```\n\n## Usage\n\nTo parse a file for docgen information use the `parse` function.\n\n```ts\nconst docgen = require(\"react-docgen-typescript\");\n\nconst options = {\n  savePropValueAsString: true,\n};\n\n// Parse a file for docgen info\ndocgen.parse(\"./path/to/component\", options);\n```\n\nIf you want to customize the typescript configuration or docgen options, this package exports a variety of ways to create custom parsers.\n\n```ts\nconst docgen = require(\"react-docgen-typescript\");\n\n// Create a parser with the default typescript config and custom docgen options\nconst customParser = docgen.withDefaultConfig(options);\n\nconst docs = customParser.parse(\"./path/to/component\");\n\n// Create a parser with the custom typescript and custom docgen options\nconst customCompilerOptionsParser = docgen.withCompilerOptions(\n  { esModuleInterop: true },\n  options\n);\n\n// Create a parser with using your typescript config\nconst tsConfigParser = docgen.withCustomConfig(\"./tsconfig.json\", {\n  savePropValueAsString: true,\n});\n```\n\n### React Styleguidist integration\n\nInclude following line in your `styleguide.config.js`:\n\n```javascript\nmodule.exports = {\n  propsParser: require(\"react-docgen-typescript\").withDefaultConfig([\n    parserOptions,\n  ]).parse,\n};\n```\n\nor if you want to use custom tsconfig file\n\n```javascript\nmodule.exports = {\n  propsParser: require(\"react-docgen-typescript\").withCustomConfig(\n    \"./tsconfig.json\",\n    [parserOptions]\n  ).parse,\n};\n```\n\n## Options\n\n### `propFilter`\n\nThe `propFilter` option allows you to omit certain props from documentation generation.\n\nYou can either provide and object with some of our pre-configured filters:\n\n```typescript\ninterface FilterOptions {\n  skipPropsWithName?: string[] | string;\n  skipPropsWithoutDoc?: boolean;\n}\n\nconst options = {\n  propFilter: {\n    skipPropsWithName: ['as', 'id'];\n    skipPropsWithoutDoc: true;\n  }\n}\n```\n\nIf you do not want to print out all the HTML attributes of a component typed like the following:\n\n```typescript\nconst MyComponent: React.FC<React.HTMLAttributes<HTMLDivElement>> = ()...\n```\n\nyou can provide a `propFilter` function and do the filtering logic yourself.\n\n```typescript\ntype PropFilter = (prop: PropItem, component: Component) => boolean;\n\nconst options = {\n  propFilter: (prop: PropItem, component: Component) => {\n    if (prop.declarations !== undefined && prop.declarations.length > 0) {\n      const hasPropAdditionalDescription = prop.declarations.find((declaration) => {\n        return !declaration.fileName.includes(\"node_modules\");\n      });\n\n      return Boolean(hasPropAdditionalDescription);\n    }\n\n    return true;\n  },\n};\n```\n\nNote: `children` without a doc comment will not be documented.\n\n### `componentNameResolver`\n\n```typescript\n(exp: ts.Symbol, source: ts.SourceFile) => string | undefined | null | false;\n```\n\nIf a string is returned, then the component will use that name. Else it will fallback to the default logic of parser.\n\n### `shouldExtractLiteralValuesFromEnum`: boolean\n\nIf set to true, string enums and unions will be converted to docgen enum format. Useful if you use Storybook and want to generate knobs automatically using [addon-smart-knobs](https://github.com/storybookjs/addon-smart-knobs).\n\n### `shouldExtractValuesFromUnion`: boolean\n\nIf set to true, every unions will be converted to docgen enum format.\n\n### `skipChildrenPropWithoutDoc`: boolean (default: `true`)\n\nIf set to false the docs for the `children` prop will be generated even without an explicit description.\n\n### `shouldRemoveUndefinedFromOptional`: boolean\n\nIf set to true, types that are optional will not display \" | undefined\" in the type.\n\n### `savePropValueAsString`: boolean\n\nIf set to true, defaultValue to props will be string.\nExample:\n\n```javascript\nComponent.defaultProps = {\n  counter: 123,\n  disabled: false,\n};\n```\n\nWill return:\n\n```javascript\n  counter: {\n      defaultValue: '123',\n      required: true,\n      type: 'number'\n  },\n  disabled: {\n      defaultValue: 'false',\n      required: true,\n      type: 'boolean'\n  }\n```\n\n**Styled components example:**\n\n```typescript\ncomponentNameResolver: (exp, source) =>\n  exp.getName() === \"StyledComponentClass\" && getDefaultExportForFile(source);\n```\n\n> The parser exports `getDefaultExportForFile` helper through its public API.\n\n## Example\n\nIn the example folder you can see React Styleguidist integration.\n\n**Warning:** only named exports are supported. If your project uses default exports, you still need to include named exports for `react-docgen-typescript`.\n\nThe component [`Column.tsx`](./examples/react-styleguidist-example/components/Column.tsx)\n\n```javascript\nimport * as React from \"react\";\nimport { Component } from \"react\";\n\n/**\n * Column properties.\n */\nexport interface IColumnProps {\n  /** prop1 description */\n  prop1?: string;\n  /** prop2 description */\n  prop2: number;\n  /**\n   * prop3 description\n   */\n  prop3: () => void;\n  /** prop4 description */\n  prop4: \"option1\" | \"option2\" | \"option3\";\n}\n\n/**\n * Form column.\n */\nexport class Column extends Component<IColumnProps, {}> {\n  render() {\n    return <div>Test</div>;\n  }\n}\n```\n\nWill generate the following stylesheet:\n\n![Stylesheet example](https://github.com/styleguidist/react-docgen-typescript/raw/master/stylesheet-example-column.png \"Stylesheet example\")\n\nThe functional component [`Grid.tsx`](./examples/react-styleguidist-example/components/Grid.tsx)\n\n```javascript\nimport * as React from \"react\";\n\n/**\n * Grid properties.\n */\nexport interface IGridProps {\n  /** prop1 description */\n  prop1?: string;\n  /** prop2 description */\n  prop2: number;\n  /**\n   * prop3 description\n   */\n  prop3: () => void;\n  /** Working grid description */\n  prop4: \"option1\" | \"option2\" | \"option3\";\n}\n\n/**\n * Form Grid.\n */\nexport const Grid = (props: IGridProps) => {\n  const smaller = () => {\n    return;\n  };\n  return <div>Grid</div>;\n};\n```\n\nWill generate the following stylesheet:\n\n![Stylesheet example](https://github.com/styleguidist/react-docgen-typescript/raw/master/stylesheet-example-grid.png \"Stylesheet example\")\n\n## Contributions\n\nThe typescript is pretty complex and there are many different ways how\nto define components and their props so it's realy hard to support all\nthese use cases. That means only one thing, contributions are highly\nwelcome. Just keep in mind that each PR should also include tests for\nthe part it's fixing.\n\nThanks to all contributors without their help there wouldn't be a single\nbug fixed or feature implemented. Check the [**contributors**](https://github.com/styleguidist/react-docgen-typescript/graphs/contributors) tab to find out\nmore. All those people supported this project. **THANK YOU!**\n\n## Thanks to others\n\nThe integration with React Styleguidist wouldn't be possible without [Vyacheslav Slinko](https://github.com/vslinko) pull request [#118](https://github.com/styleguidist/react-styleguidist/pull/118) at React Styleguidist.\n","_attachments":{},"homepage":"https://github.com/styleguidist/react-docgen-typescript/","bugs":{"url":"https://github.com/styleguidist/react-docgen-typescript/issues"},"license":"MIT"}