@elliemae/ds-props-helpers 2.2.0 → 2.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/globalProps/constants.js +15 -0
- package/cjs/globalProps/globalAttributesPropTypes.js +382 -0
- package/cjs/globalProps/index.js +11 -0
- package/cjs/globalProps/useGetGlobalAttributes.js +36 -0
- package/cjs/index.js +8 -0
- package/cjs/propTypes/PropTypes.js +130 -0
- package/cjs/propTypes/customPropTypes.js +21 -0
- package/cjs/propTypes/describe.js +64 -0
- package/cjs/propTypes/describeConversions.js +104 -0
- package/cjs/propTypes/describeGuards.js +21 -0
- package/cjs/propTypes/index.js +11 -0
- package/cjs/propTypes/toTypescript.js +160 -0
- package/cjs/propTypes/types.js +2 -0
- package/cjs/validation/typescriptValidator.js +3 -2
- package/esm/globalProps/constants.js +11 -0
- package/esm/globalProps/globalAttributesPropTypes.js +378 -0
- package/esm/globalProps/index.js +2 -0
- package/esm/globalProps/useGetGlobalAttributes.js +32 -0
- package/esm/index.js +4 -0
- package/esm/propTypes/PropTypes.js +124 -0
- package/esm/propTypes/customPropTypes.js +17 -0
- package/esm/propTypes/describe.js +62 -0
- package/esm/propTypes/describeConversions.js +96 -0
- package/esm/propTypes/describeGuards.js +10 -0
- package/esm/propTypes/index.js +2 -0
- package/esm/propTypes/toTypescript.js +154 -0
- package/esm/propTypes/types.js +1 -0
- package/esm/validation/typescriptValidator.js +2 -1
- package/package.json +56 -4
- package/types/globalProps/constants.d.ts +3 -0
- package/types/globalProps/globalAttributesPropTypes.d.ts +363 -0
- package/types/globalProps/index.d.ts +2 -0
- package/types/globalProps/useGetGlobalAttributes.d.ts +5 -0
- package/types/index.d.ts +2 -0
- package/types/propTypes/PropTypes.d.ts +3 -0
- package/types/propTypes/customPropTypes.d.ts +2 -0
- package/types/propTypes/describe.d.ts +3 -0
- package/types/propTypes/describeConversions.d.ts +3 -0
- package/types/propTypes/describeGuards.d.ts +9 -0
- package/types/propTypes/index.d.ts +3 -0
- package/types/propTypes/toTypescript.d.ts +3 -0
- package/types/propTypes/types.d.ts +96 -0
- package/types/tests/globalProps/TestComponent.d.ts +1 -0
- package/types/tests/{any.validation.test.d.ts → globalProps/globalAttributes.test.d.ts} +0 -0
- package/types/tests/{array.validation.test.d.ts → validation/any.validation.test.d.ts} +0 -0
- package/types/tests/{boolean.validation.test.d.ts → validation/array.validation.test.d.ts} +0 -0
- package/types/tests/{function.validation.test.d.ts → validation/boolean.validation.test.d.ts} +0 -0
- package/types/tests/{number.validation.test.d.ts → validation/function.validation.test.d.ts} +0 -0
- package/types/tests/{object.validation.test.d.ts → validation/number.validation.test.d.ts} +0 -0
- package/types/tests/{schema.validation.test.d.ts → validation/object.validation.test.d.ts} +0 -0
- package/types/tests/{string.validation.test.d.ts → validation/schema.validation.test.d.ts} +0 -0
- package/types/tests/{union.validation.test.d.ts → validation/string.validation.test.d.ts} +0 -0
- package/types/tests/{test.schema.d.ts → validation/test.schema.d.ts} +0 -0
- package/types/tests/validation/union.validation.test.d.ts +1 -0
- package/types/validation/typescriptValidator.d.ts +2 -2
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import 'core-js/modules/web.dom-collections.iterator.js';
|
|
2
|
+
import 'core-js/modules/esnext.async-iterator.map.js';
|
|
3
|
+
import 'core-js/modules/esnext.iterator.map.js';
|
|
4
|
+
import 'core-js/modules/esnext.async-iterator.for-each.js';
|
|
5
|
+
import 'core-js/modules/esnext.iterator.constructor.js';
|
|
6
|
+
import 'core-js/modules/esnext.iterator.for-each.js';
|
|
7
|
+
import PropTypes from 'prop-types';
|
|
8
|
+
import { tupleValidator } from './customPropTypes.js';
|
|
9
|
+
import { hasArguments, isOneOfType, isArrayOf, isShape, isInstanceOf, isOneOf, isObjectOf, isExact } from './describeGuards.js';
|
|
10
|
+
|
|
11
|
+
const enrichPropType = (propType, reactDesc) => {
|
|
12
|
+
const func = function (props, propName, componentName) {
|
|
13
|
+
if (reactDesc && reactDesc.deprecated && propName in props && !reactDesc.warned) {
|
|
14
|
+
const {
|
|
15
|
+
version = '',
|
|
16
|
+
message = ''
|
|
17
|
+
} = reactDesc.deprecated;
|
|
18
|
+
const warning = "\"".concat(propName, "\" property of \"").concat(componentName, "\" will be deprecated on VERSION: ").concat(version, ".\n").concat(message);
|
|
19
|
+
console.warn(warning);
|
|
20
|
+
reactDesc.warned = true;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
for (var _len = arguments.length, rest = new Array(_len > 3 ? _len - 3 : 0), _key = 3; _key < _len; _key++) {
|
|
24
|
+
rest[_key - 3] = arguments[_key];
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return propType(props, propName, componentName, ...rest);
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
Object.defineProperty(func, 'isRequired', Object.getOwnPropertyDescriptor(propType, 'isRequired'));
|
|
31
|
+
return func;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const convertArray = array => array.map(type => convertPropType(type));
|
|
35
|
+
|
|
36
|
+
const convertShape = _shape => {
|
|
37
|
+
const result = {};
|
|
38
|
+
Object.keys(_shape).forEach(key => {
|
|
39
|
+
result[key] = convertPropType(_shape[key]);
|
|
40
|
+
});
|
|
41
|
+
return result;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const convertPropType = propType => {
|
|
45
|
+
if (!propType || !propType.type) {
|
|
46
|
+
throw new Error("react-desc: unknown error -- proptype is not well defined");
|
|
47
|
+
} // DimSum PropTypes conversion
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
if (propType.type === 'tuple') {
|
|
51
|
+
return enrichPropType(PropTypes.arrayOf(tupleValidator(convertArray(propType.args))), propType.reactDesc);
|
|
52
|
+
} // Default PropType conversion
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
const realPropType = PropTypes[propType.type];
|
|
56
|
+
|
|
57
|
+
if (!realPropType) {
|
|
58
|
+
throw new Error("react-desc: unknown type ".concat(propType.type));
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (hasArguments(propType)) {
|
|
62
|
+
if (isOneOfType(propType)) {
|
|
63
|
+
return enrichPropType(realPropType(convertArray(propType.args)), propType.reactDesc);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (isArrayOf(propType)) {
|
|
67
|
+
return enrichPropType(realPropType(convertPropType(propType.args)), propType.reactDesc);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (isShape(propType)) {
|
|
71
|
+
return enrichPropType(realPropType(convertShape(propType.args)), propType.reactDesc);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if (isInstanceOf(propType)) {
|
|
75
|
+
return enrichPropType(realPropType(propType.args), propType.reactDesc);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (isOneOf(propType)) {
|
|
79
|
+
return enrichPropType(realPropType(propType.args), propType.reactDesc);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (isObjectOf(propType)) {
|
|
83
|
+
return enrichPropType(realPropType(propType.args), propType.reactDesc);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (isExact(propType)) {
|
|
87
|
+
return enrichPropType(realPropType(propType.args), propType.reactDesc);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
throw new Error("react-desc: unknown error -- proptype with args is not matching");
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return enrichPropType(realPropType, propType.reactDesc);
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
export { convertPropType };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
const hasArguments = (propType, realPropType) => !!propType.args;
|
|
2
|
+
const isOneOfType = (propType, realPropType) => propType.type === 'oneOfType';
|
|
3
|
+
const isArrayOf = (propType, realPropType) => propType.type === 'arrayOf';
|
|
4
|
+
const isShape = (propType, realPropType) => propType.type === 'shape';
|
|
5
|
+
const isInstanceOf = (propType, realPropType) => propType.type === 'instanceOf';
|
|
6
|
+
const isOneOf = (propType, realPropType) => propType.type === 'oneOf';
|
|
7
|
+
const isObjectOf = (propType, realPropType) => propType.type === 'objectOf';
|
|
8
|
+
const isExact = (propType, realPropType) => propType.type === 'exact';
|
|
9
|
+
|
|
10
|
+
export { hasArguments, isArrayOf, isExact, isInstanceOf, isObjectOf, isOneOf, isOneOfType, isShape };
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import 'core-js/modules/esnext.async-iterator.filter.js';
|
|
2
|
+
import 'core-js/modules/esnext.iterator.filter.js';
|
|
3
|
+
import _defineProperty from '@babel/runtime/helpers/esm/defineProperty';
|
|
4
|
+
import 'core-js/modules/esnext.async-iterator.map.js';
|
|
5
|
+
import 'core-js/modules/esnext.iterator.map.js';
|
|
6
|
+
import 'core-js/modules/esnext.async-iterator.for-each.js';
|
|
7
|
+
import 'core-js/modules/esnext.iterator.constructor.js';
|
|
8
|
+
import 'core-js/modules/esnext.iterator.for-each.js';
|
|
9
|
+
|
|
10
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
11
|
+
|
|
12
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
13
|
+
|
|
14
|
+
/* eslint-disable @typescript-eslint/restrict-template-expressions */
|
|
15
|
+
|
|
16
|
+
/* eslint-disable @typescript-eslint/no-use-before-define */
|
|
17
|
+
|
|
18
|
+
/* eslint-disable complexity */
|
|
19
|
+
|
|
20
|
+
/* eslint-disable react/forbid-foreign-prop-types */
|
|
21
|
+
const arrayFormat = array => array.map(propType => propTypeFormat(propType));
|
|
22
|
+
|
|
23
|
+
const shapeFormat = shape => {
|
|
24
|
+
const props = Object.keys(shape).map(key => {
|
|
25
|
+
const value = shape[key];
|
|
26
|
+
let valueFormat;
|
|
27
|
+
|
|
28
|
+
if (value.type && (value.type === 'arrayOf' || value.type === 'oneOfType' || value.type === 'oneOf') && Array.isArray(value.args)) {
|
|
29
|
+
valueFormat = "".concat(propTypeFormat(value));
|
|
30
|
+
} else if (value.type === 'shape') {
|
|
31
|
+
valueFormat = "".concat(propTypeFormat(value));
|
|
32
|
+
} else {
|
|
33
|
+
valueFormat = propTypeFormat(value);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return "".concat(key).concat(value.reactDesc && value.reactDesc.required ? '' : '?', ": ").concat(valueFormat);
|
|
37
|
+
});
|
|
38
|
+
return "{".concat(props.join(','), "}");
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const propTypeFormat = function (propType) {
|
|
42
|
+
let joinWith = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
|
43
|
+
let result;
|
|
44
|
+
|
|
45
|
+
if (Array.isArray(propType)) {
|
|
46
|
+
result = arrayFormat(propType).join(joinWith);
|
|
47
|
+
} else if (typeof propType !== 'function' && propType.type) {
|
|
48
|
+
switch (propType.type) {
|
|
49
|
+
case 'array':
|
|
50
|
+
result = 'any[]';
|
|
51
|
+
break;
|
|
52
|
+
|
|
53
|
+
case 'arrayOf':
|
|
54
|
+
if (propType.args.type === 'oneOfType') {
|
|
55
|
+
result = "(".concat(propTypeFormat(propType.args, ' | '), ")[]");
|
|
56
|
+
} else {
|
|
57
|
+
result = "".concat(propTypeFormat(propType.args, '\n'), "[]");
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
break;
|
|
61
|
+
|
|
62
|
+
case 'tuple':
|
|
63
|
+
result = "[".concat(propTypeFormat(propType.args, ', '), "]");
|
|
64
|
+
break;
|
|
65
|
+
|
|
66
|
+
case 'bool':
|
|
67
|
+
result = 'boolean';
|
|
68
|
+
break;
|
|
69
|
+
|
|
70
|
+
case 'func':
|
|
71
|
+
result = '((...args: any[]) => any)';
|
|
72
|
+
break;
|
|
73
|
+
|
|
74
|
+
case 'node':
|
|
75
|
+
result = 'React.ReactNode';
|
|
76
|
+
break;
|
|
77
|
+
|
|
78
|
+
case 'element':
|
|
79
|
+
result = 'JSX.Element';
|
|
80
|
+
break;
|
|
81
|
+
|
|
82
|
+
case 'instanceOf':
|
|
83
|
+
result = 'any';
|
|
84
|
+
break;
|
|
85
|
+
|
|
86
|
+
case 'symbol':
|
|
87
|
+
result = 'any';
|
|
88
|
+
break;
|
|
89
|
+
|
|
90
|
+
case 'objectOf':
|
|
91
|
+
result = "{ [key: string]: ".concat(propTypeFormat(propType.args), " }");
|
|
92
|
+
break;
|
|
93
|
+
|
|
94
|
+
case 'oneOf':
|
|
95
|
+
result = propType.args.map(a => "\"".concat(a, "\"")).join(' | ');
|
|
96
|
+
break;
|
|
97
|
+
|
|
98
|
+
case 'oneOfType':
|
|
99
|
+
result = "".concat(propTypeFormat(propType.args, ' | '));
|
|
100
|
+
break;
|
|
101
|
+
|
|
102
|
+
case 'shape':
|
|
103
|
+
result = "".concat(shapeFormat(propType.args));
|
|
104
|
+
break;
|
|
105
|
+
|
|
106
|
+
default:
|
|
107
|
+
result = "".concat(propType.type);
|
|
108
|
+
break;
|
|
109
|
+
}
|
|
110
|
+
} else {
|
|
111
|
+
result = 'any';
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
return result;
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
const propTypeAsTypescript = (propType, propName) => {
|
|
118
|
+
const documentation = _objectSpread(_objectSpread({}, propType.reactDesc), {}, {
|
|
119
|
+
name: propName
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
documentation.format = propTypeFormat(propType);
|
|
123
|
+
return documentation;
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
function descToTypescript(component, reactDesc) {
|
|
127
|
+
if (!component) {
|
|
128
|
+
throw new Error('react-desc: component is required');
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
const documentation = _objectSpread({
|
|
132
|
+
name: component.displayName || component.name
|
|
133
|
+
}, reactDesc);
|
|
134
|
+
|
|
135
|
+
if (reactDesc) {
|
|
136
|
+
delete documentation.propTypes;
|
|
137
|
+
|
|
138
|
+
if (reactDesc.propTypes) {
|
|
139
|
+
const propTypes = [];
|
|
140
|
+
Object.keys(reactDesc.propTypes).forEach(propName => {
|
|
141
|
+
const propType = reactDesc.propTypes[propName];
|
|
142
|
+
propTypes.push(propTypeAsTypescript(propType, propName));
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
if (propTypes.length > 0) {
|
|
146
|
+
documentation.properties = propTypes;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
return documentation;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
export { descToTypescript as default };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -2,8 +2,9 @@ import 'core-js/modules/esnext.async-iterator.for-each.js';
|
|
|
2
2
|
import 'core-js/modules/esnext.iterator.constructor.js';
|
|
3
3
|
import 'core-js/modules/esnext.iterator.for-each.js';
|
|
4
4
|
import 'core-js/modules/web.dom-collections.iterator.js';
|
|
5
|
-
import { describe } from 'react-desc';
|
|
6
5
|
import { useState, useMemo } from 'react';
|
|
6
|
+
import '../propTypes/PropTypes.js';
|
|
7
|
+
import describe from '../propTypes/describe.js';
|
|
7
8
|
import { throwRequiredError, throwTypeError } from './errorTemplates.js';
|
|
8
9
|
import { isUndefined, isNull, isPrimitiveType, isUnion, isString, isArray, isObject, isFunction, isJSXorNode, isSomethingWithParenthesis } from './typescriptGuards.js';
|
|
9
10
|
import { typescriptObjectParser } from './typescriptParsers.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elliemae/ds-props-helpers",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.2",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "ICE MT - Dimsum - Props Helpers",
|
|
6
6
|
"module": "./esm/index.js",
|
|
@@ -35,9 +35,61 @@
|
|
|
35
35
|
"import": "./esm/validation/errorTemplates.js",
|
|
36
36
|
"require": "./cjs/validation/errorTemplates.js"
|
|
37
37
|
},
|
|
38
|
-
"./tests/test.schema": {
|
|
39
|
-
"import": "./esm/tests/test.schema.js",
|
|
40
|
-
"require": "./cjs/tests/test.schema.js"
|
|
38
|
+
"./tests/validation/test.schema": {
|
|
39
|
+
"import": "./esm/tests/validation/test.schema.js",
|
|
40
|
+
"require": "./cjs/tests/validation/test.schema.js"
|
|
41
|
+
},
|
|
42
|
+
"./tests/globalProps/TestComponent": {
|
|
43
|
+
"import": "./esm/tests/globalProps/TestComponent.js",
|
|
44
|
+
"require": "./cjs/tests/globalProps/TestComponent.js"
|
|
45
|
+
},
|
|
46
|
+
"./propTypes/types": {
|
|
47
|
+
"import": "./esm/propTypes/types.js",
|
|
48
|
+
"require": "./cjs/propTypes/types.js"
|
|
49
|
+
},
|
|
50
|
+
"./propTypes/toTypescript": {
|
|
51
|
+
"import": "./esm/propTypes/toTypescript.js",
|
|
52
|
+
"require": "./cjs/propTypes/toTypescript.js"
|
|
53
|
+
},
|
|
54
|
+
"./propTypes/PropTypes": {
|
|
55
|
+
"import": "./esm/propTypes/PropTypes.js",
|
|
56
|
+
"require": "./cjs/propTypes/PropTypes.js"
|
|
57
|
+
},
|
|
58
|
+
"./propTypes": {
|
|
59
|
+
"import": "./esm/propTypes/index.js",
|
|
60
|
+
"require": "./cjs/propTypes/index.js"
|
|
61
|
+
},
|
|
62
|
+
"./propTypes/describeGuards": {
|
|
63
|
+
"import": "./esm/propTypes/describeGuards.js",
|
|
64
|
+
"require": "./cjs/propTypes/describeGuards.js"
|
|
65
|
+
},
|
|
66
|
+
"./propTypes/describeConversions": {
|
|
67
|
+
"import": "./esm/propTypes/describeConversions.js",
|
|
68
|
+
"require": "./cjs/propTypes/describeConversions.js"
|
|
69
|
+
},
|
|
70
|
+
"./propTypes/describe": {
|
|
71
|
+
"import": "./esm/propTypes/describe.js",
|
|
72
|
+
"require": "./cjs/propTypes/describe.js"
|
|
73
|
+
},
|
|
74
|
+
"./propTypes/customPropTypes": {
|
|
75
|
+
"import": "./esm/propTypes/customPropTypes.js",
|
|
76
|
+
"require": "./cjs/propTypes/customPropTypes.js"
|
|
77
|
+
},
|
|
78
|
+
"./globalProps/useGetGlobalAttributes": {
|
|
79
|
+
"import": "./esm/globalProps/useGetGlobalAttributes.js",
|
|
80
|
+
"require": "./cjs/globalProps/useGetGlobalAttributes.js"
|
|
81
|
+
},
|
|
82
|
+
"./globalProps": {
|
|
83
|
+
"import": "./esm/globalProps/index.js",
|
|
84
|
+
"require": "./cjs/globalProps/index.js"
|
|
85
|
+
},
|
|
86
|
+
"./globalProps/globalAttributesPropTypes": {
|
|
87
|
+
"import": "./esm/globalProps/globalAttributesPropTypes.js",
|
|
88
|
+
"require": "./cjs/globalProps/globalAttributesPropTypes.js"
|
|
89
|
+
},
|
|
90
|
+
"./globalProps/constants": {
|
|
91
|
+
"import": "./esm/globalProps/constants.js",
|
|
92
|
+
"require": "./cjs/globalProps/constants.js"
|
|
41
93
|
},
|
|
42
94
|
"./getProps": {
|
|
43
95
|
"import": "./esm/getProps/index.js",
|