Skip to content

Commit cfb1371

Browse files
committed
Merge branch 'develop'
2 parents 2980ebf + 5fabf15 commit cfb1371

File tree

10 files changed

+5660
-3234
lines changed

10 files changed

+5660
-3234
lines changed

.eslintrc.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
module.exports = {
44
"extends": "eslint:recommended",
55
"env": {
6-
"node": true,
7-
"es6": true
6+
"es6": true,
7+
"jest": true,
8+
"node": true
89
},
910
"parserOptions": {
1011
"ecmaVersion": 6,

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
Create documentation for your React projects in a easy way using regular PropTypes declarations.
1+
Create documentation for your React projects in an easy way using standard PropTypes declarations.
22

3-
Share the documentation in the project repository.
3+
Share the documentation in your project's repository.
44

55
## Demo
66

@@ -49,7 +49,7 @@ react-doc-creator [path] ...[options]
4949

5050
## Use Examples
5151

52-
The options should be added to the `package.json` script.
52+
The options should be added to the corresponding `react-doc-creator` script in `package.json`.
5353

5454
### Exclude specific file
5555
`react-doc-creator src --exclude demo\.jsx`

examples/REACT-PROPTYPES.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ Property | Type | Default value | Description
1919
`optionalEnum`|'News' \| 'Photos'||You can ensure that your prop is limited to specific values by treating it as an enum.
2020
`optionalUnion`|string \| number \| Promise||An object that could be one of many types
2121
`optionalArrayOf`|<number>[]||An array of a certain type
22-
`optionalObjectOf`|objectOf||An object with property values of a certain type
23-
`optionalObjectWithShape`|shape||An object taking on a particular shape
22+
`optionalObjectOf`|{ [key]: <number> }||An object with property values of a certain type
23+
`optionalObjectWithShape`|{ color: string, fontSize: number }||An object taking on a particular shape
2424
`requiredFunc`|func|_required_|You can chain any of the above with `isRequired` to make sure a warning is shown if the prop isn't provided.
2525
`requiredAny`|any|_required_|A value of any data type
2626
`customProp`|custom||
@@ -30,4 +30,4 @@ Property | Type | Default value | Description
3030

3131
-----
3232

33-
<sub>Documentation generated using **React Doc Creator v0.0.7**</sub>
33+
<sub>Documentation generated using **React Doc Creator v0.0.9**</sub>

lib/utils/parse-component.js

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
const propParsers = require('./prop-parsers')
2+
3+
14
exports.parseComponent = originalComponent => {
25

36
const component = {
@@ -52,26 +55,16 @@ function getParsedProp(prop) {
5255
case 'arrayOf':
5356
return `<${prop.type.value.name}>[]`
5457
case 'enum':
55-
return parseEnumProp(prop.type.value)
58+
return propParsers.enum(prop.type.value)
5659
case 'instanceOf':
5760
return `<${prop.type.value}>`
61+
case 'objectOf':
62+
return propParsers.objectOf(prop.type.value)
5863
case 'union':
59-
return parseUnionProp(prop.type.value)
64+
return propParsers.union(prop.type.value)
65+
case 'shape':
66+
return propParsers.shape(prop.type.value)
6067
default:
6168
return prop.type.name
6269
}
6370
}
64-
65-
66-
function parseEnumProp(values) {
67-
return values
68-
.map(value => value.value)
69-
.join(' \\| ')
70-
}
71-
72-
73-
function parseUnionProp(values) {
74-
return values
75-
.map(value => value.name === 'instanceOf' ? value.value : value.name)
76-
.join(' \\| ')
77-
}

lib/utils/prop-parsers.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
exports.enum = values =>
2+
values
3+
.map(value => value.value)
4+
.join(' \\| ')
5+
6+
7+
exports.objectOf = value => `{ [key]: <${value.name}> }`
8+
9+
10+
exports.union = values =>
11+
values
12+
.map(value => value.name === 'instanceOf' ? value.value : value.name)
13+
.join(' \\| ')
14+
15+
16+
exports.shape = values => {
17+
18+
const props = Object.keys(values)
19+
.map(key => `${key}: ${values[key].name}`)
20+
.join(', ')
21+
22+
return `{ ${props} }`
23+
24+
}

0 commit comments

Comments
 (0)