@elliemae/ds-props-helpers 1.60.0 → 2.0.0-alpha.12
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/defaultProps/index.js +2 -6
- package/cjs/defaultProps/useMemoMergePropsWithDefault.js +13 -9
- package/cjs/getProps/index.js +13 -23
- package/cjs/index.js +13 -21
- package/cjs/validation/errorTemplates.js +4 -9
- package/cjs/validation/index.js +8 -14
- package/cjs/validation/typescriptGuards.js +16 -29
- package/cjs/validation/typescriptParsers.js +12 -9
- package/cjs/validation/typescriptValidator.js +77 -72
- package/cjs/validation/validator.js +13 -18
- package/esm/defaultProps/index.js +0 -4
- package/esm/defaultProps/useMemoMergePropsWithDefault.js +12 -8
- package/esm/getProps/index.js +13 -19
- package/esm/index.js +0 -8
- package/esm/validation/errorTemplates.js +4 -5
- package/esm/validation/index.js +0 -6
- package/esm/validation/typescriptGuards.js +16 -29
- package/esm/validation/typescriptParsers.js +12 -9
- package/esm/validation/typescriptValidator.js +55 -45
- package/esm/validation/validator.js +10 -11
- package/package.json +70 -10
- package/types/defaultProps/index.d.ts +1 -0
- package/types/defaultProps/useMemoMergePropsWithDefault.d.ts +1 -0
- package/types/getProps/index.d.ts +2 -0
- package/types/index.d.ts +3 -0
- package/types/tests/any.validation.test.d.ts +1 -0
- package/types/tests/array.validation.test.d.ts +1 -0
- package/types/tests/boolean.validation.test.d.ts +1 -0
- package/types/tests/function.validation.test.d.ts +1 -0
- package/types/tests/number.validation.test.d.ts +1 -0
- package/types/tests/object.validation.test.d.ts +1 -0
- package/types/tests/schema.validation.test.d.ts +1 -0
- package/types/tests/string.validation.test.d.ts +1 -0
- package/types/tests/test.schema.d.ts +1 -0
- package/types/tests/union.validation.test.d.ts +1 -0
- package/types/validation/errorTemplates.d.ts +2 -0
- package/types/validation/index.d.ts +3 -0
- package/types/validation/typescriptGuards.d.ts +11 -0
- package/types/validation/typescriptParsers.d.ts +1 -0
- package/types/validation/typescriptValidator.d.ts +15 -0
- package/types/validation/validator.d.ts +1 -0
- package/cjs/defaultProps/index.js.map +0 -1
- package/cjs/defaultProps/useMemoMergePropsWithDefault.js.map +0 -1
- package/cjs/getProps/index.js.map +0 -1
- package/cjs/index.js.map +0 -1
- package/cjs/tests/test.schema.js +0 -43
- package/cjs/tests/test.schema.js.map +0 -1
- package/cjs/validation/errorTemplates.js.map +0 -1
- package/cjs/validation/index.js.map +0 -1
- package/cjs/validation/typescriptGuards.js.map +0 -1
- package/cjs/validation/typescriptParsers.js.map +0 -1
- package/cjs/validation/typescriptValidator.js.map +0 -1
- package/cjs/validation/validator.js.map +0 -1
- package/defaultProps/package.json +0 -10
- package/defaultProps/useMemoMergePropsWithDefault/package.json +0 -10
- package/esm/defaultProps/index.js.map +0 -1
- package/esm/defaultProps/useMemoMergePropsWithDefault.js.map +0 -1
- package/esm/getProps/index.js.map +0 -1
- package/esm/index.js.map +0 -1
- package/esm/tests/test.schema.js +0 -39
- package/esm/tests/test.schema.js.map +0 -1
- package/esm/validation/errorTemplates.js.map +0 -1
- package/esm/validation/index.js.map +0 -1
- package/esm/validation/typescriptGuards.js.map +0 -1
- package/esm/validation/typescriptParsers.js.map +0 -1
- package/esm/validation/typescriptValidator.js.map +0 -1
- package/esm/validation/validator.js.map +0 -1
- package/getProps/package.json +0 -10
- package/tests/test.schema/package.json +0 -10
- package/validation/errorTemplates/package.json +0 -10
- package/validation/package.json +0 -10
- package/validation/typescriptGuards/package.json +0 -10
- package/validation/typescriptParsers/package.json +0 -10
- package/validation/typescriptValidator/package.json +0 -10
- package/validation/validator/package.json +0 -10
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
import 'core-js/modules/esnext.async-iterator.filter.js';
|
|
2
|
+
import 'core-js/modules/esnext.iterator.constructor.js';
|
|
3
|
+
import 'core-js/modules/esnext.iterator.filter.js';
|
|
4
|
+
import 'core-js/modules/esnext.async-iterator.for-each.js';
|
|
5
|
+
import 'core-js/modules/esnext.iterator.for-each.js';
|
|
1
6
|
import _defineProperty from '@babel/runtime/helpers/esm/defineProperty';
|
|
2
7
|
import { useRef } from 'react';
|
|
3
8
|
import deepequal from 'fast-deep-equal/react';
|
|
@@ -7,13 +12,13 @@ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (O
|
|
|
7
12
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
8
13
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
9
14
|
|
|
10
|
-
|
|
15
|
+
const useMemoCompare = (next, compare) => {
|
|
11
16
|
// Ref for storing previous value
|
|
12
|
-
|
|
13
|
-
|
|
17
|
+
const previousRef = useRef(next);
|
|
18
|
+
const previous = previousRef.current; // Pass previous and next value to compare function
|
|
14
19
|
// to determine whether to consider them equal.
|
|
15
20
|
|
|
16
|
-
|
|
21
|
+
const isEqual = compare(previous, next); // If not equal update previousRef to next value.
|
|
17
22
|
// We only update if not equal so that this hook continues to return
|
|
18
23
|
// the same old value if compare keeps returning true.
|
|
19
24
|
|
|
@@ -23,13 +28,12 @@ var useMemoCompare = function useMemoCompare(next, compare) {
|
|
|
23
28
|
}; // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
24
29
|
|
|
25
30
|
|
|
26
|
-
|
|
27
|
-
|
|
31
|
+
const useMemoMergePropsWithDefault = function (props, defaultProps) {
|
|
32
|
+
let compare = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : deepequal;
|
|
28
33
|
|
|
29
|
-
|
|
34
|
+
const mergedProps = _objectSpread(_objectSpread({}, defaultProps), props);
|
|
30
35
|
|
|
31
36
|
return useMemoCompare(mergedProps, compare);
|
|
32
37
|
};
|
|
33
38
|
|
|
34
39
|
export { useMemoMergePropsWithDefault };
|
|
35
|
-
//# sourceMappingURL=useMemoMergePropsWithDefault.js.map
|
package/esm/getProps/index.js
CHANGED
|
@@ -1,21 +1,15 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
return
|
|
13
|
-
|
|
14
|
-
key = _ref4[0];
|
|
15
|
-
|
|
16
|
-
return key.includes('data-');
|
|
17
|
-
}));
|
|
18
|
-
};
|
|
1
|
+
import 'core-js/modules/esnext.async-iterator.filter.js';
|
|
2
|
+
import 'core-js/modules/esnext.iterator.constructor.js';
|
|
3
|
+
import 'core-js/modules/esnext.iterator.filter.js';
|
|
4
|
+
import 'core-js/modules/web.dom-collections.iterator.js';
|
|
5
|
+
|
|
6
|
+
const getAriaProps = props => Object.fromEntries(Object.entries(props).filter(_ref => {
|
|
7
|
+
let [key] = _ref;
|
|
8
|
+
return key.includes('aria-');
|
|
9
|
+
}));
|
|
10
|
+
const getDataProps = props => Object.fromEntries(Object.entries(props).filter(_ref2 => {
|
|
11
|
+
let [key] = _ref2;
|
|
12
|
+
return key.includes('data-');
|
|
13
|
+
}));
|
|
19
14
|
|
|
20
15
|
export { getAriaProps, getDataProps };
|
|
21
|
-
//# sourceMappingURL=index.js.map
|
package/esm/index.js
CHANGED
|
@@ -3,11 +3,3 @@ export { useValidatePropTypes } from './validation/validator.js';
|
|
|
3
3
|
export { throwRequiredError, throwTypeError } from './validation/errorTemplates.js';
|
|
4
4
|
export { useValidateTypescriptPropTypes, validateTypescriptPropTypesImplementation } from './validation/typescriptValidator.js';
|
|
5
5
|
export { getAriaProps, getDataProps } from './getProps/index.js';
|
|
6
|
-
import '@babel/runtime/helpers/esm/defineProperty';
|
|
7
|
-
import 'react';
|
|
8
|
-
import 'fast-deep-equal/react';
|
|
9
|
-
import '@babel/runtime/helpers/esm/typeof';
|
|
10
|
-
import '@babel/runtime/helpers/esm/slicedToArray';
|
|
11
|
-
import './validation/typescriptGuards.js';
|
|
12
|
-
import './validation/typescriptParsers.js';
|
|
13
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import
|
|
1
|
+
import 'core-js/modules/es.string.replace.js';
|
|
2
2
|
|
|
3
3
|
/* eslint-disable max-params */
|
|
4
|
-
|
|
5
|
-
throw new Error("".concat(componentName, ":: You are trying to pass a not valid \"").concat(validPropKey, "\" property, \n please provide a valid type.\n\n Received: ").concat(invalidProp, " (").concat(
|
|
4
|
+
const throwTypeError = (componentName, validPropKey, invalidProp, validFormat) => {
|
|
5
|
+
throw new Error("".concat(componentName, ":: You are trying to pass a not valid \"").concat(validPropKey, "\" property, \n please provide a valid type.\n\n Received: ").concat(invalidProp, " (").concat(typeof invalidProp, ")\n Expected: (").concat(validFormat.replace('\n', ' or '), ")\n "));
|
|
6
6
|
};
|
|
7
|
-
|
|
7
|
+
const throwRequiredError = (componentName, validPropKey) => {
|
|
8
8
|
throw new Error("".concat(componentName, ":: Please provide a/an \"").concat(validPropKey, "\" property to use this component. \n This property is required.\n "));
|
|
9
9
|
};
|
|
10
10
|
|
|
11
11
|
export { throwRequiredError, throwTypeError };
|
|
12
|
-
//# sourceMappingURL=errorTemplates.js.map
|
package/esm/validation/index.js
CHANGED
|
@@ -1,9 +1,3 @@
|
|
|
1
1
|
export { useValidatePropTypes } from './validator.js';
|
|
2
2
|
export { throwRequiredError, throwTypeError } from './errorTemplates.js';
|
|
3
3
|
export { useValidateTypescriptPropTypes, validateTypescriptPropTypesImplementation } from './typescriptValidator.js';
|
|
4
|
-
import '@babel/runtime/helpers/esm/typeof';
|
|
5
|
-
import '@babel/runtime/helpers/esm/slicedToArray';
|
|
6
|
-
import 'react';
|
|
7
|
-
import './typescriptGuards.js';
|
|
8
|
-
import './typescriptParsers.js';
|
|
9
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1,35 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
format.split('').forEach(
|
|
1
|
+
import 'core-js/modules/esnext.async-iterator.for-each.js';
|
|
2
|
+
import 'core-js/modules/esnext.iterator.constructor.js';
|
|
3
|
+
import 'core-js/modules/esnext.iterator.for-each.js';
|
|
4
|
+
|
|
5
|
+
const isPrimitiveType = format => ['string', 'number', 'boolean'].includes(format);
|
|
6
|
+
const isUndefined = format => format === '"undefined"';
|
|
7
|
+
const isUnion = format => {
|
|
8
|
+
let depth = 0;
|
|
9
|
+
let satisfies = false;
|
|
10
|
+
format.split('').forEach(char => {
|
|
11
11
|
if (['{', '('].includes(char)) depth += 1;else if (['}', ')'].includes(char)) depth -= 1;else if (char === '|' && depth === 0) satisfies = true;
|
|
12
12
|
});
|
|
13
13
|
return satisfies;
|
|
14
14
|
};
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
var isObject = function isObject(format) {
|
|
22
|
-
return format === 'object' || !isUnion(format) && format[0] === '{' && format.slice(-1) === '}';
|
|
23
|
-
};
|
|
24
|
-
var isFunction = function isFunction(format) {
|
|
25
|
-
return !isUnion(format) && format === '((...args: any[]) => any)';
|
|
26
|
-
};
|
|
27
|
-
var isJSXorNode = function isJSXorNode(format) {
|
|
28
|
-
return !isUnion(format) && ['React.ReactNode', 'JSX.Element'].includes(format);
|
|
29
|
-
};
|
|
30
|
-
var isSomethingWithParenthesis = function isSomethingWithParenthesis(format) {
|
|
31
|
-
return !isUnion(format) && format[0] === '(' && format.slice(-1) === ')';
|
|
32
|
-
};
|
|
15
|
+
const isString = format => !isUnion(format) && format[0] === '"' && format.slice(-1) === '"';
|
|
16
|
+
const isArray = format => !isUnion(format) && format.slice(-2) === '[]';
|
|
17
|
+
const isObject = format => format === 'object' || !isUnion(format) && format[0] === '{' && format.slice(-1) === '}';
|
|
18
|
+
const isFunction = format => !isUnion(format) && format === '((...args: any[]) => any)';
|
|
19
|
+
const isJSXorNode = format => !isUnion(format) && ['React.ReactNode', 'JSX.Element'].includes(format);
|
|
20
|
+
const isSomethingWithParenthesis = format => !isUnion(format) && format[0] === '(' && format.slice(-1) === ')';
|
|
33
21
|
|
|
34
22
|
export { isArray, isFunction, isJSXorNode, isObject, isPrimitiveType, isSomethingWithParenthesis, isString, isUndefined, isUnion };
|
|
35
|
-
//# sourceMappingURL=typescriptGuards.js.map
|
|
@@ -1,12 +1,16 @@
|
|
|
1
|
+
import 'core-js/modules/esnext.async-iterator.for-each.js';
|
|
2
|
+
import 'core-js/modules/esnext.iterator.constructor.js';
|
|
3
|
+
import 'core-js/modules/esnext.iterator.for-each.js';
|
|
4
|
+
|
|
1
5
|
/* eslint-disable complexity */
|
|
2
|
-
|
|
3
|
-
|
|
6
|
+
const typescriptObjectParser = format => {
|
|
7
|
+
const keyValuePairs = []; // State of the algorithm
|
|
4
8
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
9
|
+
let lastKey = '';
|
|
10
|
+
let lastValue = '';
|
|
11
|
+
let shouldAppendToKey = true;
|
|
8
12
|
|
|
9
|
-
|
|
13
|
+
const pushPair = () => {
|
|
10
14
|
if (lastKey) keyValuePairs.push([lastKey, lastValue]);
|
|
11
15
|
lastKey = '';
|
|
12
16
|
lastValue = '';
|
|
@@ -14,8 +18,8 @@ var typescriptObjectParser = function typescriptObjectParser(format) {
|
|
|
14
18
|
}; // Complex -- but working -- logic
|
|
15
19
|
|
|
16
20
|
|
|
17
|
-
|
|
18
|
-
format.split('').forEach(
|
|
21
|
+
let depth = 0;
|
|
22
|
+
format.split('').forEach(char => {
|
|
19
23
|
if (char === '{') {
|
|
20
24
|
depth += 1;
|
|
21
25
|
if (depth > 1) lastValue += char;
|
|
@@ -35,4 +39,3 @@ var typescriptObjectParser = function typescriptObjectParser(format) {
|
|
|
35
39
|
};
|
|
36
40
|
|
|
37
41
|
export { typescriptObjectParser };
|
|
38
|
-
//# sourceMappingURL=typescriptParsers.js.map
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import 'core-js/modules/esnext.async-iterator.for-each.js';
|
|
2
|
+
import 'core-js/modules/esnext.iterator.constructor.js';
|
|
3
|
+
import 'core-js/modules/esnext.iterator.for-each.js';
|
|
4
|
+
import 'core-js/modules/web.dom-collections.iterator.js';
|
|
5
|
+
import { describe } from 'react-desc';
|
|
3
6
|
import { useState, useMemo } from 'react';
|
|
4
7
|
import { throwRequiredError, throwTypeError } from './errorTemplates.js';
|
|
5
8
|
import { isUndefined, isPrimitiveType, isUnion, isString, isArray, isObject, isFunction, isJSXorNode, isSomethingWithParenthesis } from './typescriptGuards.js';
|
|
@@ -11,53 +14,50 @@ import { typescriptObjectParser } from './typescriptParsers.js';
|
|
|
11
14
|
// This functions will validate something from the data
|
|
12
15
|
// and optionally recursively apply `validateValueWithFormat`
|
|
13
16
|
// in smaller parts
|
|
14
|
-
|
|
17
|
+
const validateUndefined = (schemaName, key, value, format) => {
|
|
15
18
|
if (value !== undefined) {
|
|
16
19
|
throwTypeError(schemaName, key, value, format);
|
|
17
20
|
}
|
|
18
21
|
};
|
|
19
22
|
|
|
20
|
-
|
|
21
|
-
if (
|
|
23
|
+
const validatePrimitiveType = (schemaName, key, value, format) => {
|
|
24
|
+
if (typeof value !== format) {
|
|
22
25
|
throwTypeError(schemaName, key, value, format);
|
|
23
26
|
}
|
|
24
27
|
};
|
|
25
28
|
|
|
26
|
-
|
|
29
|
+
const validateString = (schemaName, key, value, format) => {
|
|
27
30
|
if (value !== format.slice(1, -1)) {
|
|
28
31
|
throwTypeError(schemaName, key, value, format);
|
|
29
32
|
}
|
|
30
33
|
};
|
|
31
34
|
|
|
32
|
-
|
|
35
|
+
const validateArray = (schemaName, key, value, format, validationsMemo, nextValidationsMemo) => {
|
|
33
36
|
// Check that we have an array
|
|
34
37
|
if (!Array.isArray(value)) {
|
|
35
38
|
throwTypeError(schemaName, key, value, format);
|
|
36
39
|
} // Check that each element inside satisfies the format
|
|
37
40
|
|
|
38
41
|
|
|
39
|
-
value.forEach(
|
|
42
|
+
value.forEach((val, index) => {
|
|
40
43
|
validateValueWithFormat(schemaName, "".concat(key, "[").concat(index, "]"), val, format.slice(0, -2), validationsMemo, nextValidationsMemo);
|
|
41
44
|
});
|
|
42
45
|
};
|
|
43
46
|
|
|
44
|
-
|
|
47
|
+
const validateObject = (schemaName, key, value, format, validationsMemo, nextValidationsMemo) => {
|
|
45
48
|
// Check that we have an object
|
|
46
|
-
if (
|
|
49
|
+
if (typeof value !== 'object' || Array.isArray(value)) {
|
|
47
50
|
throwTypeError(schemaName, key, value, format);
|
|
48
51
|
}
|
|
49
52
|
|
|
50
53
|
if (format === 'object') return;
|
|
51
|
-
|
|
54
|
+
const keyValuePairs = typescriptObjectParser(format); // Now we have the key - value pairs
|
|
52
55
|
// Each key could either be required or not
|
|
53
56
|
// Just recursively check the object
|
|
54
57
|
|
|
55
|
-
keyValuePairs.forEach(
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
objectValue = _ref2[1];
|
|
59
|
-
|
|
60
|
-
var trueKey = objectKey.slice(-1) === '?' ? objectKey.slice(0, -1) : objectKey;
|
|
58
|
+
keyValuePairs.forEach(_ref => {
|
|
59
|
+
let [objectKey, objectValue] = _ref;
|
|
60
|
+
const trueKey = objectKey.slice(-1) === '?' ? objectKey.slice(0, -1) : objectKey;
|
|
61
61
|
|
|
62
62
|
if (trueKey === objectKey && !(trueKey in value)) {
|
|
63
63
|
throwRequiredError(schemaName, key);
|
|
@@ -69,10 +69,10 @@ var validateObject = function validateObject(schemaName, key, value, format, val
|
|
|
69
69
|
});
|
|
70
70
|
};
|
|
71
71
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
possibilities.forEach(
|
|
72
|
+
const validateUnion = (schemaName, key, value, format, validationsMemo, nextValidationsMemo) => {
|
|
73
|
+
const possibilities = format.split(' | ');
|
|
74
|
+
const errors = [];
|
|
75
|
+
possibilities.forEach(possibility => {
|
|
76
76
|
try {
|
|
77
77
|
validateValueWithFormat(schemaName, key, value, possibility, validationsMemo, nextValidationsMemo);
|
|
78
78
|
} catch (e) {
|
|
@@ -85,15 +85,15 @@ var validateUnion = function validateUnion(schemaName, key, value, format, valid
|
|
|
85
85
|
}
|
|
86
86
|
};
|
|
87
87
|
|
|
88
|
-
|
|
88
|
+
const validateFunction = (schemaName, key, value, format) => {
|
|
89
89
|
// Check that we have a function
|
|
90
90
|
if (typeof value !== 'function') {
|
|
91
91
|
throwTypeError(schemaName, key, value, format);
|
|
92
92
|
}
|
|
93
93
|
};
|
|
94
94
|
|
|
95
|
-
|
|
96
|
-
if (format === 'JSX.Element' && (
|
|
95
|
+
const validateJSXorNode = (schemaName, key, value, format) => {
|
|
96
|
+
if (format === 'JSX.Element' && (typeof value !== 'object' || !('$$typeof' in value))) {
|
|
97
97
|
throwTypeError(schemaName, key, value, format);
|
|
98
98
|
}
|
|
99
99
|
}; // =============================================================================
|
|
@@ -101,7 +101,7 @@ var validateJSXorNode = function validateJSXorNode(schemaName, key, value, forma
|
|
|
101
101
|
// =============================================================================
|
|
102
102
|
|
|
103
103
|
|
|
104
|
-
|
|
104
|
+
const validateValueWithFormat = (schemaName, key, value, format, validationsMemo, nextValidationsMemo) => {
|
|
105
105
|
nextValidationsMemo[value] = format;
|
|
106
106
|
|
|
107
107
|
if (value in validationsMemo) {
|
|
@@ -130,15 +130,19 @@ var validateValueWithFormat = function validateValueWithFormat(schemaName, key,
|
|
|
130
130
|
}
|
|
131
131
|
};
|
|
132
132
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
133
|
+
const validateTypescriptPropTypesImplementation = function (props, schema) {
|
|
134
|
+
let validationsMemo = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
135
|
+
let nextValidationsMemo = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
136
|
+
const {
|
|
137
|
+
properties,
|
|
138
|
+
name: schemaName
|
|
139
|
+
} = schema;
|
|
140
|
+
properties.forEach(property => {
|
|
141
|
+
const {
|
|
142
|
+
name,
|
|
143
|
+
format,
|
|
144
|
+
required
|
|
145
|
+
} = property;
|
|
142
146
|
|
|
143
147
|
if (required && !(name in props)) {
|
|
144
148
|
throwRequiredError(schema.name, name);
|
|
@@ -148,19 +152,25 @@ var validateTypescriptPropTypesImplementation = function validateTypescriptPropT
|
|
|
148
152
|
validateValueWithFormat(schemaName, name, props[name], format, validationsMemo, nextValidationsMemo);
|
|
149
153
|
}
|
|
150
154
|
});
|
|
151
|
-
};
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
155
|
+
}; // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
156
|
+
|
|
157
|
+
const useValidateTypescriptPropTypes = (props, propTypes) => {
|
|
158
|
+
const [validationsMemo, setValidationsMemo] = useState({}); // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
159
|
+
|
|
160
|
+
const ComponentWithSchema = useMemo(() => {
|
|
161
|
+
const Component = () => {}; // eslint-disable-next-line @typescript-eslint/no-unsafe-return, @typescript-eslint/no-unsafe-call
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
return describe(Component);
|
|
165
|
+
}, []); // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-assignment
|
|
166
|
+
|
|
167
|
+
ComponentWithSchema.propTypes = propTypes;
|
|
168
|
+
useMemo(() => {
|
|
169
|
+
const nextValidationsMemo = {};
|
|
170
|
+
validateTypescriptPropTypesImplementation(props, // eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
|
|
171
|
+
ComponentWithSchema.toTypescript(), validationsMemo, nextValidationsMemo);
|
|
161
172
|
setValidationsMemo(nextValidationsMemo); // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
162
173
|
}, [props]);
|
|
163
174
|
};
|
|
164
175
|
|
|
165
176
|
export { useValidateTypescriptPropTypes, validateTypescriptPropTypesImplementation };
|
|
166
|
-
//# sourceMappingURL=typescriptValidator.js.map
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import
|
|
1
|
+
import 'core-js/modules/esnext.async-iterator.for-each.js';
|
|
2
|
+
import 'core-js/modules/esnext.iterator.constructor.js';
|
|
3
|
+
import 'core-js/modules/esnext.iterator.for-each.js';
|
|
2
4
|
import { throwRequiredError, throwTypeError } from './errorTemplates.js';
|
|
3
5
|
|
|
4
|
-
|
|
5
|
-
schema.properties.forEach(
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
const useValidatePropTypes = (props, schema) => {
|
|
7
|
+
schema.properties.forEach(property => {
|
|
8
|
+
const propertyName = property.name;
|
|
9
|
+
const currentProp = props[propertyName];
|
|
10
|
+
const currentPropTypeOf = typeof currentProp; // eslint-disable-next-line max-len
|
|
8
11
|
|
|
9
|
-
|
|
12
|
+
const currentFormat = property.format; // this is csv representing types e.g.: "string"/"string,number"/"[object],string"
|
|
10
13
|
|
|
11
|
-
|
|
12
|
-
var currentFormat = property.format; // this is csv representing types e.g.: "string"/"string,number"/"[object],string"
|
|
13
|
-
|
|
14
|
-
var isValidReactElement = false; // this depends on react desc definition
|
|
14
|
+
let isValidReactElement = false; // this depends on react desc definition
|
|
15
15
|
|
|
16
16
|
if (property.required && !Object.prototype.hasOwnProperty.call(props, property.name)) {
|
|
17
17
|
throwRequiredError(schema.name, property.name);
|
|
@@ -30,4 +30,3 @@ var useValidatePropTypes = function useValidatePropTypes(props, schema) {
|
|
|
30
30
|
};
|
|
31
31
|
|
|
32
32
|
export { useValidatePropTypes };
|
|
33
|
-
//# sourceMappingURL=validator.js.map
|
package/package.json
CHANGED
|
@@ -1,29 +1,89 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elliemae/ds-props-helpers",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0-alpha.12",
|
|
4
4
|
"license": "MIT",
|
|
5
|
-
"description": "
|
|
6
|
-
"module": "esm/index.js",
|
|
7
|
-
"main": "cjs/index.js",
|
|
5
|
+
"description": "ICE MT - Dimsum - Props Helpers",
|
|
6
|
+
"module": "./esm/index.js",
|
|
7
|
+
"main": "./cjs/index.js",
|
|
8
|
+
"types": "./types/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"import": "./esm/index.js",
|
|
12
|
+
"require": "./cjs/index.js"
|
|
13
|
+
},
|
|
14
|
+
"./validation/validator": {
|
|
15
|
+
"import": "./esm/validation/validator.js",
|
|
16
|
+
"require": "./cjs/validation/validator.js"
|
|
17
|
+
},
|
|
18
|
+
"./validation/typescriptValidator": {
|
|
19
|
+
"import": "./esm/validation/typescriptValidator.js",
|
|
20
|
+
"require": "./cjs/validation/typescriptValidator.js"
|
|
21
|
+
},
|
|
22
|
+
"./validation/typescriptParsers": {
|
|
23
|
+
"import": "./esm/validation/typescriptParsers.js",
|
|
24
|
+
"require": "./cjs/validation/typescriptParsers.js"
|
|
25
|
+
},
|
|
26
|
+
"./validation/typescriptGuards": {
|
|
27
|
+
"import": "./esm/validation/typescriptGuards.js",
|
|
28
|
+
"require": "./cjs/validation/typescriptGuards.js"
|
|
29
|
+
},
|
|
30
|
+
"./validation": {
|
|
31
|
+
"import": "./esm/validation/index.js",
|
|
32
|
+
"require": "./cjs/validation/index.js"
|
|
33
|
+
},
|
|
34
|
+
"./validation/errorTemplates": {
|
|
35
|
+
"import": "./esm/validation/errorTemplates.js",
|
|
36
|
+
"require": "./cjs/validation/errorTemplates.js"
|
|
37
|
+
},
|
|
38
|
+
"./tests/test.schema": {
|
|
39
|
+
"import": "./esm/tests/test.schema.js",
|
|
40
|
+
"require": "./cjs/tests/test.schema.js"
|
|
41
|
+
},
|
|
42
|
+
"./getProps": {
|
|
43
|
+
"import": "./esm/getProps/index.js",
|
|
44
|
+
"require": "./cjs/getProps/index.js"
|
|
45
|
+
},
|
|
46
|
+
"./defaultProps/useMemoMergePropsWithDefault": {
|
|
47
|
+
"import": "./esm/defaultProps/useMemoMergePropsWithDefault.js",
|
|
48
|
+
"require": "./cjs/defaultProps/useMemoMergePropsWithDefault.js"
|
|
49
|
+
},
|
|
50
|
+
"./defaultProps": {
|
|
51
|
+
"import": "./esm/defaultProps/index.js",
|
|
52
|
+
"require": "./cjs/defaultProps/index.js"
|
|
53
|
+
}
|
|
54
|
+
},
|
|
8
55
|
"sideEffects": [
|
|
9
56
|
"*.css",
|
|
10
57
|
"*.scss"
|
|
11
58
|
],
|
|
59
|
+
"repository": {
|
|
60
|
+
"type": "git",
|
|
61
|
+
"url": "https://git.elliemae.io/platform-ui/dimsum.git"
|
|
62
|
+
},
|
|
63
|
+
"engines": {
|
|
64
|
+
"npm": ">=7",
|
|
65
|
+
"node": ">=14"
|
|
66
|
+
},
|
|
12
67
|
"scripts": {
|
|
13
68
|
"dev": "cross-env NODE_ENV=development && node ../../scripts/build/build.js -w",
|
|
14
69
|
"prebuild": "exit 0",
|
|
15
70
|
"predev": "exit 0",
|
|
16
71
|
"build": "node ../../scripts/build/build.js"
|
|
17
72
|
},
|
|
73
|
+
"dependencies": {
|
|
74
|
+
"fast-deep-equal": "~3.1.3",
|
|
75
|
+
"react-desc": "^4.1.3"
|
|
76
|
+
},
|
|
77
|
+
"devDependencies": {
|
|
78
|
+
"@testing-library/jest-dom": "~5.15.0"
|
|
79
|
+
},
|
|
18
80
|
"peerDependencies": {
|
|
19
|
-
"react": "
|
|
20
|
-
"react-dom": "^17.0.
|
|
81
|
+
"react": "~17.0.2",
|
|
82
|
+
"react-dom": "^17.0.2"
|
|
21
83
|
},
|
|
22
84
|
"publishConfig": {
|
|
23
85
|
"access": "public",
|
|
24
|
-
"directory": "dist"
|
|
25
|
-
|
|
26
|
-
"dependencies": {
|
|
27
|
-
"fast-deep-equal": "3.1.3"
|
|
86
|
+
"directory": "dist",
|
|
87
|
+
"generateSubmodules": true
|
|
28
88
|
}
|
|
29
89
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './useMemoMergePropsWithDefault';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const useMemoMergePropsWithDefault: <T = Record<string, any>>(props: Partial<T>, defaultProps: Partial<T>, compare?: (a: any, b: any) => boolean) => T;
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const TypescriptSchema: any;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
declare type guardFn = (format: string) => boolean;
|
|
2
|
+
export declare const isPrimitiveType: guardFn;
|
|
3
|
+
export declare const isUndefined: guardFn;
|
|
4
|
+
export declare const isUnion: guardFn;
|
|
5
|
+
export declare const isString: guardFn;
|
|
6
|
+
export declare const isArray: guardFn;
|
|
7
|
+
export declare const isObject: guardFn;
|
|
8
|
+
export declare const isFunction: guardFn;
|
|
9
|
+
export declare const isJSXorNode: guardFn;
|
|
10
|
+
export declare const isSomethingWithParenthesis: guardFn;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const typescriptObjectParser: (format: string) => [string, string][];
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import React, { PropsWithChildren } from 'react';
|
|
2
|
+
interface TypescriptSchema {
|
|
3
|
+
description: string;
|
|
4
|
+
name: string;
|
|
5
|
+
properties: {
|
|
6
|
+
name: string;
|
|
7
|
+
description: string;
|
|
8
|
+
defaultValue?: unknown;
|
|
9
|
+
format: string;
|
|
10
|
+
required?: boolean;
|
|
11
|
+
}[];
|
|
12
|
+
}
|
|
13
|
+
export declare const validateTypescriptPropTypesImplementation: (props: PropsWithChildren<Record<string, unknown>>, schema: TypescriptSchema, validationsMemo?: Record<string, string>, nextValidationsMemo?: Record<string, string>) => void;
|
|
14
|
+
export declare const useValidateTypescriptPropTypes: <T = Record<string, any>>(props: React.PropsWithChildren<T>, propTypes: any) => void;
|
|
15
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const useValidatePropTypes: (props: Record<string, unknown>, schema: any) => void;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;"}
|