@elliemae/ds-props-helpers 2.0.0-alpha.9 → 2.0.0-next.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/useMemoMergePropsWithDefault.js +8 -1
- package/cjs/getProps/index.js +13 -2
- package/cjs/validation/errorTemplates.js +2 -9
- package/cjs/validation/typescriptGuards.js +4 -0
- package/cjs/validation/typescriptParsers.js +4 -0
- package/cjs/validation/typescriptValidator.js +11 -6
- package/cjs/validation/validator.js +3 -1
- package/esm/defaultProps/useMemoMergePropsWithDefault.js +8 -1
- package/esm/getProps/index.js +13 -2
- package/esm/validation/errorTemplates.js +2 -9
- package/esm/validation/typescriptGuards.js +4 -0
- package/esm/validation/typescriptParsers.js +4 -0
- package/esm/validation/typescriptValidator.js +11 -6
- package/esm/validation/validator.js +3 -1
- package/package.json +2 -2
- package/types/validation/typescriptValidator.d.ts +1 -1
- package/cjs/package.json +0 -7
- package/esm/package.json +0 -7
|
@@ -2,6 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
+
require('core-js/modules/esnext.async-iterator.filter.js');
|
|
6
|
+
require('core-js/modules/esnext.iterator.constructor.js');
|
|
7
|
+
require('core-js/modules/esnext.iterator.filter.js');
|
|
8
|
+
require('core-js/modules/esnext.async-iterator.for-each.js');
|
|
9
|
+
require('core-js/modules/esnext.iterator.for-each.js');
|
|
5
10
|
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
|
|
6
11
|
var react = require('react');
|
|
7
12
|
var deepequal = require('fast-deep-equal/react');
|
|
@@ -32,7 +37,9 @@ const useMemoCompare = (next, compare) => {
|
|
|
32
37
|
}; // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
33
38
|
|
|
34
39
|
|
|
35
|
-
const useMemoMergePropsWithDefault = (props, defaultProps
|
|
40
|
+
const useMemoMergePropsWithDefault = function (props, defaultProps) {
|
|
41
|
+
let compare = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : deepequal__default["default"];
|
|
42
|
+
|
|
36
43
|
const mergedProps = _objectSpread(_objectSpread({}, defaultProps), props);
|
|
37
44
|
|
|
38
45
|
return useMemoCompare(mergedProps, compare);
|
package/cjs/getProps/index.js
CHANGED
|
@@ -2,8 +2,19 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
require('core-js/modules/esnext.async-iterator.filter.js');
|
|
6
|
+
require('core-js/modules/esnext.iterator.constructor.js');
|
|
7
|
+
require('core-js/modules/esnext.iterator.filter.js');
|
|
8
|
+
require('core-js/modules/web.dom-collections.iterator.js');
|
|
9
|
+
|
|
10
|
+
const getAriaProps = props => Object.fromEntries(Object.entries(props).filter(_ref => {
|
|
11
|
+
let [key] = _ref;
|
|
12
|
+
return key.includes('aria-');
|
|
13
|
+
}));
|
|
14
|
+
const getDataProps = props => Object.fromEntries(Object.entries(props).filter(_ref2 => {
|
|
15
|
+
let [key] = _ref2;
|
|
16
|
+
return key.includes('data-');
|
|
17
|
+
}));
|
|
7
18
|
|
|
8
19
|
exports.getAriaProps = getAriaProps;
|
|
9
20
|
exports.getDataProps = getDataProps;
|
|
@@ -6,17 +6,10 @@ require('core-js/modules/es.string.replace.js');
|
|
|
6
6
|
|
|
7
7
|
/* eslint-disable max-params */
|
|
8
8
|
const throwTypeError = (componentName, validPropKey, invalidProp, validFormat) => {
|
|
9
|
-
throw new Error(
|
|
10
|
-
please provide a valid type.
|
|
11
|
-
|
|
12
|
-
Received: ${invalidProp} (${typeof invalidProp})
|
|
13
|
-
Expected: (${validFormat.replace('\n', ' or ')})
|
|
14
|
-
`);
|
|
9
|
+
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 "));
|
|
15
10
|
};
|
|
16
11
|
const throwRequiredError = (componentName, validPropKey) => {
|
|
17
|
-
throw new Error(
|
|
18
|
-
This property is required.
|
|
19
|
-
`);
|
|
12
|
+
throw new Error("".concat(componentName, ":: Please provide a/an \"").concat(validPropKey, "\" property to use this component. \n This property is required.\n "));
|
|
20
13
|
};
|
|
21
14
|
|
|
22
15
|
exports.throwRequiredError = throwRequiredError;
|
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
+
require('core-js/modules/esnext.async-iterator.for-each.js');
|
|
6
|
+
require('core-js/modules/esnext.iterator.constructor.js');
|
|
7
|
+
require('core-js/modules/esnext.iterator.for-each.js');
|
|
8
|
+
|
|
5
9
|
const isPrimitiveType = format => ['string', 'number', 'boolean'].includes(format);
|
|
6
10
|
const isUndefined = format => format === '"undefined"';
|
|
7
11
|
const isUnion = format => {
|
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
+
require('core-js/modules/esnext.async-iterator.for-each.js');
|
|
6
|
+
require('core-js/modules/esnext.iterator.constructor.js');
|
|
7
|
+
require('core-js/modules/esnext.iterator.for-each.js');
|
|
8
|
+
|
|
5
9
|
/* eslint-disable complexity */
|
|
6
10
|
const typescriptObjectParser = format => {
|
|
7
11
|
const keyValuePairs = []; // State of the algorithm
|
|
@@ -2,13 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
+
require('core-js/modules/esnext.async-iterator.for-each.js');
|
|
6
|
+
require('core-js/modules/esnext.iterator.constructor.js');
|
|
7
|
+
require('core-js/modules/esnext.iterator.for-each.js');
|
|
8
|
+
require('core-js/modules/web.dom-collections.iterator.js');
|
|
5
9
|
var react = require('react');
|
|
6
10
|
var errorTemplates = require('./errorTemplates.js');
|
|
7
11
|
var typescriptGuards = require('./typescriptGuards.js');
|
|
8
12
|
var typescriptParsers = require('./typescriptParsers.js');
|
|
9
13
|
|
|
10
|
-
/* eslint-disable complexity */
|
|
11
|
-
|
|
12
14
|
// =============================================================================
|
|
13
15
|
// Atom Validators
|
|
14
16
|
// =============================================================================
|
|
@@ -41,7 +43,7 @@ const validateArray = (schemaName, key, value, format, validationsMemo, nextVali
|
|
|
41
43
|
|
|
42
44
|
|
|
43
45
|
value.forEach((val, index) => {
|
|
44
|
-
validateValueWithFormat(schemaName,
|
|
46
|
+
validateValueWithFormat(schemaName, "".concat(key, "[").concat(index, "]"), val, format.slice(0, -2), validationsMemo, nextValidationsMemo);
|
|
45
47
|
});
|
|
46
48
|
};
|
|
47
49
|
|
|
@@ -56,7 +58,8 @@ const validateObject = (schemaName, key, value, format, validationsMemo, nextVal
|
|
|
56
58
|
// Each key could either be required or not
|
|
57
59
|
// Just recursively check the object
|
|
58
60
|
|
|
59
|
-
keyValuePairs.forEach(
|
|
61
|
+
keyValuePairs.forEach(_ref => {
|
|
62
|
+
let [objectKey, objectValue] = _ref;
|
|
60
63
|
const trueKey = objectKey.slice(-1) === '?' ? objectKey.slice(0, -1) : objectKey;
|
|
61
64
|
|
|
62
65
|
if (trueKey === objectKey && !(trueKey in value)) {
|
|
@@ -64,7 +67,7 @@ const validateObject = (schemaName, key, value, format, validationsMemo, nextVal
|
|
|
64
67
|
}
|
|
65
68
|
|
|
66
69
|
if (trueKey in value) {
|
|
67
|
-
validateValueWithFormat(schemaName,
|
|
70
|
+
validateValueWithFormat(schemaName, "".concat(key, "[").concat(trueKey, "]"), value[trueKey], objectValue, validationsMemo, nextValidationsMemo);
|
|
68
71
|
}
|
|
69
72
|
});
|
|
70
73
|
};
|
|
@@ -130,7 +133,9 @@ const validateValueWithFormat = (schemaName, key, value, format, validationsMemo
|
|
|
130
133
|
}
|
|
131
134
|
};
|
|
132
135
|
|
|
133
|
-
const validateTypescriptPropTypesImplementation = (props, schema
|
|
136
|
+
const validateTypescriptPropTypesImplementation = function (props, schema) {
|
|
137
|
+
let validationsMemo = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
138
|
+
let nextValidationsMemo = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
134
139
|
const {
|
|
135
140
|
properties,
|
|
136
141
|
name: schemaName
|
|
@@ -2,9 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
+
require('core-js/modules/esnext.async-iterator.for-each.js');
|
|
6
|
+
require('core-js/modules/esnext.iterator.constructor.js');
|
|
7
|
+
require('core-js/modules/esnext.iterator.for-each.js');
|
|
5
8
|
var errorTemplates = require('./errorTemplates.js');
|
|
6
9
|
|
|
7
|
-
/* eslint-disable complexity */
|
|
8
10
|
const useValidatePropTypes = (props, schema) => {
|
|
9
11
|
schema.properties.forEach(property => {
|
|
10
12
|
const propertyName = property.name;
|
|
@@ -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';
|
|
@@ -23,7 +28,9 @@ const useMemoCompare = (next, compare) => {
|
|
|
23
28
|
}; // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
24
29
|
|
|
25
30
|
|
|
26
|
-
const useMemoMergePropsWithDefault = (props, defaultProps
|
|
31
|
+
const useMemoMergePropsWithDefault = function (props, defaultProps) {
|
|
32
|
+
let compare = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : deepequal;
|
|
33
|
+
|
|
27
34
|
const mergedProps = _objectSpread(_objectSpread({}, defaultProps), props);
|
|
28
35
|
|
|
29
36
|
return useMemoCompare(mergedProps, compare);
|
package/esm/getProps/index.js
CHANGED
|
@@ -1,4 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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
|
+
}));
|
|
3
14
|
|
|
4
15
|
export { getAriaProps, getDataProps };
|
|
@@ -2,17 +2,10 @@ import 'core-js/modules/es.string.replace.js';
|
|
|
2
2
|
|
|
3
3
|
/* eslint-disable max-params */
|
|
4
4
|
const throwTypeError = (componentName, validPropKey, invalidProp, validFormat) => {
|
|
5
|
-
throw new Error(
|
|
6
|
-
please provide a valid type.
|
|
7
|
-
|
|
8
|
-
Received: ${invalidProp} (${typeof invalidProp})
|
|
9
|
-
Expected: (${validFormat.replace('\n', ' or ')})
|
|
10
|
-
`);
|
|
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 "));
|
|
11
6
|
};
|
|
12
7
|
const throwRequiredError = (componentName, validPropKey) => {
|
|
13
|
-
throw new Error(
|
|
14
|
-
This property is required.
|
|
15
|
-
`);
|
|
8
|
+
throw new Error("".concat(componentName, ":: Please provide a/an \"").concat(validPropKey, "\" property to use this component. \n This property is required.\n "));
|
|
16
9
|
};
|
|
17
10
|
|
|
18
11
|
export { throwRequiredError, throwTypeError };
|
|
@@ -1,3 +1,7 @@
|
|
|
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
|
const isPrimitiveType = format => ['string', 'number', 'boolean'].includes(format);
|
|
2
6
|
const isUndefined = format => format === '"undefined"';
|
|
3
7
|
const isUnion = format => {
|
|
@@ -1,3 +1,7 @@
|
|
|
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
6
|
const typescriptObjectParser = format => {
|
|
3
7
|
const keyValuePairs = []; // State of the algorithm
|
|
@@ -1,10 +1,12 @@
|
|
|
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';
|
|
1
5
|
import { useState, useMemo } from 'react';
|
|
2
6
|
import { throwRequiredError, throwTypeError } from './errorTemplates.js';
|
|
3
7
|
import { isUndefined, isPrimitiveType, isUnion, isString, isArray, isObject, isFunction, isJSXorNode, isSomethingWithParenthesis } from './typescriptGuards.js';
|
|
4
8
|
import { typescriptObjectParser } from './typescriptParsers.js';
|
|
5
9
|
|
|
6
|
-
/* eslint-disable complexity */
|
|
7
|
-
|
|
8
10
|
// =============================================================================
|
|
9
11
|
// Atom Validators
|
|
10
12
|
// =============================================================================
|
|
@@ -37,7 +39,7 @@ const validateArray = (schemaName, key, value, format, validationsMemo, nextVali
|
|
|
37
39
|
|
|
38
40
|
|
|
39
41
|
value.forEach((val, index) => {
|
|
40
|
-
validateValueWithFormat(schemaName,
|
|
42
|
+
validateValueWithFormat(schemaName, "".concat(key, "[").concat(index, "]"), val, format.slice(0, -2), validationsMemo, nextValidationsMemo);
|
|
41
43
|
});
|
|
42
44
|
};
|
|
43
45
|
|
|
@@ -52,7 +54,8 @@ const validateObject = (schemaName, key, value, format, validationsMemo, nextVal
|
|
|
52
54
|
// Each key could either be required or not
|
|
53
55
|
// Just recursively check the object
|
|
54
56
|
|
|
55
|
-
keyValuePairs.forEach(
|
|
57
|
+
keyValuePairs.forEach(_ref => {
|
|
58
|
+
let [objectKey, objectValue] = _ref;
|
|
56
59
|
const trueKey = objectKey.slice(-1) === '?' ? objectKey.slice(0, -1) : objectKey;
|
|
57
60
|
|
|
58
61
|
if (trueKey === objectKey && !(trueKey in value)) {
|
|
@@ -60,7 +63,7 @@ const validateObject = (schemaName, key, value, format, validationsMemo, nextVal
|
|
|
60
63
|
}
|
|
61
64
|
|
|
62
65
|
if (trueKey in value) {
|
|
63
|
-
validateValueWithFormat(schemaName,
|
|
66
|
+
validateValueWithFormat(schemaName, "".concat(key, "[").concat(trueKey, "]"), value[trueKey], objectValue, validationsMemo, nextValidationsMemo);
|
|
64
67
|
}
|
|
65
68
|
});
|
|
66
69
|
};
|
|
@@ -126,7 +129,9 @@ const validateValueWithFormat = (schemaName, key, value, format, validationsMemo
|
|
|
126
129
|
}
|
|
127
130
|
};
|
|
128
131
|
|
|
129
|
-
const validateTypescriptPropTypesImplementation = (props, schema
|
|
132
|
+
const validateTypescriptPropTypesImplementation = function (props, schema) {
|
|
133
|
+
let validationsMemo = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
134
|
+
let nextValidationsMemo = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
130
135
|
const {
|
|
131
136
|
properties,
|
|
132
137
|
name: schemaName
|
|
@@ -1,6 +1,8 @@
|
|
|
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';
|
|
1
4
|
import { throwRequiredError, throwTypeError } from './errorTemplates.js';
|
|
2
5
|
|
|
3
|
-
/* eslint-disable complexity */
|
|
4
6
|
const useValidatePropTypes = (props, schema) => {
|
|
5
7
|
schema.properties.forEach(property => {
|
|
6
8
|
const propertyName = property.name;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elliemae/ds-props-helpers",
|
|
3
|
-
"version": "2.0.0-
|
|
3
|
+
"version": "2.0.0-next.12",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "ICE MT - Dimsum - Props Helpers",
|
|
6
6
|
"module": "./esm/index.js",
|
|
@@ -71,7 +71,7 @@
|
|
|
71
71
|
"build": "node ../../scripts/build/build.js"
|
|
72
72
|
},
|
|
73
73
|
"dependencies": {
|
|
74
|
-
"
|
|
74
|
+
"fast-deep-equal": "~3.1.3"
|
|
75
75
|
},
|
|
76
76
|
"peerDependencies": {
|
|
77
77
|
"react": "~17.0.2",
|
|
@@ -11,5 +11,5 @@ interface TypescriptSchema {
|
|
|
11
11
|
}[];
|
|
12
12
|
}
|
|
13
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: (props: PropsWithChildren<
|
|
14
|
+
export declare const useValidateTypescriptPropTypes: <T = Record<any, any>>(props: PropsWithChildren<T>, schema: TypescriptSchema) => void;
|
|
15
15
|
export {};
|
package/cjs/package.json
DELETED