Skip to content
This repository was archived by the owner on Nov 27, 2023. It is now read-only.

Commit 87b5a98

Browse files
committed
docs: Updated API docs
1 parent 8b27145 commit 87b5a98

File tree

1 file changed

+42
-8
lines changed

1 file changed

+42
-8
lines changed

README.md

Lines changed: 42 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,49 @@ cat <some/react/component.jsx> |react2dts --name module-name
4040

4141
## API
4242

43+
Functions:
4344
```js
44-
import * as react2dts from 'react-to-typescript-definitions';
45+
/**
46+
* Returns the typescript definition for the given file.
47+
*
48+
* @param name The name of the generated module
49+
* @param path The path to the file to parse
50+
* @param options The options to use
51+
* @return The type definition as string
52+
*/
53+
function generateFromFile(name, path, options)
54+
```
4555

46-
// react2dts.generateFromFile('<module-name>', '<path/to/react-component>');
47-
react2dts.generateFromFile('component', path.join(__dirname, 'component.jsx'));
56+
```js
57+
/**
58+
* Returns the typescript definition for the given source.
59+
*
60+
* @param name The name of the generated module
61+
* @param code The code to parse
62+
* @param options The options to use
63+
* @return The type definition as string
64+
*/
65+
function generateFromSource(name, code, options)
66+
```
4867

49-
// react2dts.generateFromSource('<module-name>', '<code of the component>');
50-
react2dts.generateFromSource('component', 'component-code');
68+
```js
69+
/**
70+
* Returns the typescript definition for the given babylon AST object.
71+
*
72+
* @param name The name of the generated module
73+
* @param ast The babylon ASt to parse
74+
* @param options The options to use
75+
* @return The type definition as string
76+
*/
77+
function generateFromAst(name, ast, options)
78+
```
5179

52-
// react2dts.generateFromAst('<module-name>', babylonAstObject);
53-
react2dts.generateFromAst('component', babylonAstObject);
54-
```
80+
Options:
81+
* writer
82+
An instance of the exported writer class. This options is usefull to write
83+
multiple declarations into one .d.ts file. The writer could be used
84+
for consecutive function calls.
85+
* instanceOfResolver
86+
A function which gets a type name (as string) and should return the path
87+
to the file defining the type or undefined if the type is not resolvable.
88+
This function is required to generate instanceOf PropTypes.

0 commit comments

Comments
 (0)