Skip to content

Commit 4780e3f

Browse files
committed
Refactored types, Faker Response added, pass param/query
1 parent 0e5188b commit 4780e3f

File tree

17 files changed

+410
-37
lines changed

17 files changed

+410
-37
lines changed

.eslintrc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@
1111
"react/forbid-prop-types": 0,
1212
"jsx-a11y/alt-text": 0,
1313
"import/prefer-default-export": 0,
14-
"import/no-extraneous-dependencies": 0
14+
"import/no-extraneous-dependencies": 0,
15+
"no-param-reassign": 0,
16+
"no-restricted-syntax": 0,
17+
"guard-for-in": 0
1518
},
1619
"ignorePatterns": "/dist"
1720
}

package-lock.json

Lines changed: 157 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@
1111
"build": "NODE_ENV=production rollup -c rollup.config.js",
1212
"prepublishOnly": "npm run build"
1313
},
14-
"keywords": [ "reactend", "express", "react", "http-server"],
14+
"keywords": [
15+
"reactend",
16+
"express",
17+
"react",
18+
"http-server"
19+
],
1520
"author": "Orkhan Jafarov",
1621
"license": "ISC",
1722
"husky": {
@@ -31,9 +36,10 @@
3136
"compression": "^1.7.4",
3237
"cookie-parser": "^1.4.5",
3338
"express": "^4.17.1",
39+
"faker": "^5.4.0",
3440
"morgan": "^1.10.0",
35-
"react-reconciler": "^0.26.1",
36-
"prop-types": "^15.7.2"
41+
"prop-types": "^15.7.2",
42+
"react-reconciler": "^0.26.1"
3743
},
3844
"peerDependencies": {
3945
"react": "^17.0.1",

src/components/App.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react';
22
import PropTypes from 'prop-types';
33

4-
export const App = ({ children, port }) => <app port={port}>{children}</app>;
4+
export const App = ({ children, port }) => <app$ port={port}>{children}</app$>;
55

66
App.propTypes = {
77
port: PropTypes.number,

src/components/Faker.js

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
import React from 'react';
2+
import PropTypes from 'prop-types';
3+
4+
import { transformFakerMap } from '../utils/fakerUtil';
5+
import { Middleware } from './Middleware';
6+
import { passValues } from '../utils/propsUtil';
7+
8+
export const Faker = ({ map, length, locale }) => (
9+
<Middleware
10+
handler={(req, res) => {
11+
let json;
12+
const params = passValues(req, { length, locale });
13+
14+
if (length) {
15+
json = Array.from({ length: +(params.length || 5) }, () =>
16+
transformFakerMap(map, params.locale || 'en')
17+
);
18+
} else {
19+
json = transformFakerMap(map, params.locale);
20+
}
21+
22+
res.send(json);
23+
}}
24+
/>
25+
);
26+
27+
Faker.propTypes = {
28+
map: PropTypes.oneOfType([PropTypes.object, PropTypes.array]).isRequired,
29+
length: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
30+
locale: PropTypes.oneOfType([
31+
PropTypes.string,
32+
PropTypes.oneOf([
33+
'az',
34+
'cz',
35+
'de',
36+
'de_AT',
37+
'de_CH',
38+
'en',
39+
'en_AU',
40+
'en_AU_ocker',
41+
'en_BORK',
42+
'en_CA',
43+
'en_GB',
44+
'en_IE',
45+
'en_IND',
46+
'en_US',
47+
'en_ZA',
48+
'es',
49+
'es_MX',
50+
'fa',
51+
'fi',
52+
'fr',
53+
'fr_CA',
54+
'fr_CH',
55+
'ge',
56+
'hy',
57+
'hr',
58+
'id_ID',
59+
'it',
60+
'ja',
61+
'ko',
62+
'nb_NO',
63+
'ne',
64+
'nl',
65+
'nl_BE',
66+
'pl',
67+
'pt_BR',
68+
'pt_PT',
69+
'ro',
70+
'ru',
71+
'sk',
72+
'sv',
73+
'tr',
74+
'uk',
75+
'vi',
76+
'zh_CN',
77+
'zh_TW',
78+
]),
79+
]),
80+
};

src/components/Logger.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@ import React from 'react';
22
import PropTypes from 'prop-types';
33

44
/**
5-
*
65
* @param {{
76
* mode: 'skip' | 'stream' | 'combined' | 'common' | 'dev' | 'short' | 'tiny'
87
* disabled: Boolean
98
* }} props
109
*/
11-
export const Logger = ({ mode, disabled }) => <logger mode={mode} disabled={disabled} />;
10+
export const Logger = ({ mode, disabled }) => <logger$ mode={mode} disabled={disabled} />;
1211
Logger.propTypes = {
1312
mode: PropTypes.oneOf(['skip', 'stream', 'combined', 'common', 'dev', 'short', 'tiny'])
1413
.isRequired,

src/components/Middleware.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react';
22
import PropTypes from 'prop-types';
33

4-
export const Middleware = ({ handler }) => <middleware handler={handler} />;
4+
export const Middleware = ({ handler }) => <middleware$ handler={handler} />;
55
Middleware.propTypes = {
66
handler: PropTypes.func.isRequired,
77
};

0 commit comments

Comments
 (0)