@elliemae/ds-props-helpers 2.2.0-alpha.5 → 2.2.0-next.1

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.
Files changed (46) hide show
  1. package/cjs/defaultProps/index.js +9 -28
  2. package/cjs/defaultProps/useMemoMergePropsWithDefault.js +44 -44
  3. package/cjs/getProps/index.js +20 -37
  4. package/cjs/index.js +20 -30
  5. package/cjs/validation/errorTemplates.js +12 -44
  6. package/cjs/validation/index.js +15 -30
  7. package/cjs/validation/typescriptGuards.js +31 -60
  8. package/cjs/validation/typescriptParsers.js +34 -65
  9. package/cjs/validation/typescriptValidator.js +135 -99
  10. package/cjs/validation/validator.js +24 -43
  11. package/esm/defaultProps/index.js +1 -3
  12. package/esm/defaultProps/useMemoMergePropsWithDefault.js +34 -14
  13. package/esm/getProps/index.js +15 -8
  14. package/esm/index.js +5 -5
  15. package/esm/validation/errorTemplates.js +7 -15
  16. package/esm/validation/index.js +3 -5
  17. package/esm/validation/typescriptGuards.js +18 -31
  18. package/esm/validation/typescriptParsers.js +30 -36
  19. package/esm/validation/typescriptValidator.js +106 -57
  20. package/esm/validation/validator.js +18 -12
  21. package/package.json +1 -1
  22. package/types/validation/typescriptValidator.d.ts +2 -2
  23. package/cjs/defaultProps/index.js.map +0 -7
  24. package/cjs/defaultProps/useMemoMergePropsWithDefault.js.map +0 -7
  25. package/cjs/getProps/index.js.map +0 -7
  26. package/cjs/index.js.map +0 -7
  27. package/cjs/tests/test.schema.js +0 -67
  28. package/cjs/tests/test.schema.js.map +0 -7
  29. package/cjs/validation/errorTemplates.js.map +0 -7
  30. package/cjs/validation/index.js.map +0 -7
  31. package/cjs/validation/typescriptGuards.js.map +0 -7
  32. package/cjs/validation/typescriptParsers.js.map +0 -7
  33. package/cjs/validation/typescriptValidator.js.map +0 -7
  34. package/cjs/validation/validator.js.map +0 -7
  35. package/esm/defaultProps/index.js.map +0 -7
  36. package/esm/defaultProps/useMemoMergePropsWithDefault.js.map +0 -7
  37. package/esm/getProps/index.js.map +0 -7
  38. package/esm/index.js.map +0 -7
  39. package/esm/tests/test.schema.js +0 -38
  40. package/esm/tests/test.schema.js.map +0 -7
  41. package/esm/validation/errorTemplates.js.map +0 -7
  42. package/esm/validation/index.js.map +0 -7
  43. package/esm/validation/typescriptGuards.js.map +0 -7
  44. package/esm/validation/typescriptParsers.js.map +0 -7
  45. package/esm/validation/typescriptValidator.js.map +0 -7
  46. package/esm/validation/validator.js.map +0 -7
@@ -1,171 +1,207 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __reExport = (target, module2, copyDefault, desc) => {
13
- if (module2 && typeof module2 === "object" || typeof module2 === "function") {
14
- for (let key of __getOwnPropNames(module2))
15
- if (!__hasOwnProp.call(target, key) && (copyDefault || key !== "default"))
16
- __defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
17
- }
18
- return target;
19
- };
20
- var __toESM = (module2, isNodeMode) => {
21
- return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", !isNodeMode && module2 && module2.__esModule ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
22
- };
23
- var __toCommonJS = /* @__PURE__ */ ((cache) => {
24
- return (module2, temp) => {
25
- return cache && cache.get(module2) || (temp = __reExport(__markAsModule({}), module2, 1), cache && cache.set(module2, temp), temp);
26
- };
27
- })(typeof WeakMap !== "undefined" ? /* @__PURE__ */ new WeakMap() : 0);
28
- var typescriptValidator_exports = {};
29
- __export(typescriptValidator_exports, {
30
- useValidateTypescriptPropTypes: () => useValidateTypescriptPropTypes,
31
- validateTypescriptPropTypesImplementation: () => validateTypescriptPropTypesImplementation
32
- });
33
- var React = __toESM(require("react"));
34
- var import_react_desc = require("react-desc");
35
- var import_react = require("react");
36
- var import_errorTemplates = require("./errorTemplates");
37
- var import_typescriptGuards = require("./typescriptGuards");
38
- var import_typescriptParsers = require("./typescriptParsers");
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
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');
9
+ var reactDesc = require('react-desc');
10
+ var react = require('react');
11
+ var errorTemplates = require('./errorTemplates.js');
12
+ var typescriptGuards = require('./typescriptGuards.js');
13
+ var typescriptParsers = require('./typescriptParsers.js');
14
+
15
+ // =============================================================================
16
+ // Atom Validators
17
+ // =============================================================================
18
+ // This functions will validate something from the data
19
+ // and optionally recursively apply `validateValueWithFormat`
20
+ // in smaller parts
39
21
  const validateUndefined = (schemaName, key, value, format) => {
40
- if (value !== void 0 || value === "undefined") {
41
- (0, import_errorTemplates.throwTypeError)(schemaName, key, value, format);
22
+ if (value !== undefined || value === 'undefined') {
23
+ errorTemplates.throwTypeError(schemaName, key, value, format);
42
24
  }
43
25
  };
26
+
44
27
  const validateNull = (schemaName, key, value, format) => {
45
- if (value !== null || value === "null") {
46
- (0, import_errorTemplates.throwTypeError)(schemaName, key, value, format);
28
+ if (value !== null || value === 'null') {
29
+ errorTemplates.throwTypeError(schemaName, key, value, format);
47
30
  }
48
31
  };
32
+
49
33
  const validatePrimitiveType = (schemaName, key, value, format) => {
50
34
  if (typeof value !== format) {
51
- (0, import_errorTemplates.throwTypeError)(schemaName, key, value, format);
35
+ errorTemplates.throwTypeError(schemaName, key, value, format);
52
36
  }
53
37
  };
38
+
54
39
  const validateString = (schemaName, key, value, format) => {
55
40
  if (value !== format.slice(1, -1)) {
56
- (0, import_errorTemplates.throwTypeError)(schemaName, key, value, format);
41
+ errorTemplates.throwTypeError(schemaName, key, value, format);
57
42
  }
58
43
  };
44
+
59
45
  const validateArray = (schemaName, key, value, format, validationsMemo, nextValidationsMemo) => {
46
+ // Check that we have an array
60
47
  if (!Array.isArray(value)) {
61
- (0, import_errorTemplates.throwTypeError)(schemaName, key, value, format);
62
- }
48
+ errorTemplates.throwTypeError(schemaName, key, value, format);
49
+ } // Check that each element inside satisfies the format
50
+
51
+
63
52
  value.forEach((val, index) => {
64
- validateValueWithFormat(schemaName, `${key}[${index}]`, val, format.slice(0, -2), validationsMemo, nextValidationsMemo);
53
+ // this is a recursive func, we need to invoke it before it's defined.
54
+ // eslint-disable-next-line @typescript-eslint/no-use-before-define
55
+ validateValueWithFormat(schemaName, "".concat(key, "[").concat(index, "]"), val, format.slice(0, -2), validationsMemo, nextValidationsMemo);
65
56
  });
66
57
  };
58
+
67
59
  function isObjectType(value) {
68
- return !(typeof value !== "object" || Array.isArray(value));
60
+ return !(typeof value !== 'object' || Array.isArray(value));
69
61
  }
62
+
70
63
  const validateObject = (schemaName, key, value, format, validationsMemo, nextValidationsMemo) => {
71
- const valuesIsObject = isObjectType(value);
64
+ const valuesIsObject = isObjectType(value); // Check that we have an object
65
+
72
66
  if (!valuesIsObject) {
73
- (0, import_errorTemplates.throwTypeError)(schemaName, key, value, format);
67
+ errorTemplates.throwTypeError(schemaName, key, value, format);
74
68
  return;
75
69
  }
76
- if (format === "object")
77
- return;
78
- const keyValuePairs = (0, import_typescriptParsers.typescriptObjectParser)(format);
79
- keyValuePairs.forEach(([objectKey, objectValue]) => {
80
- const trueKey = objectKey.slice(-1) === "?" ? objectKey.slice(0, -1) : objectKey;
70
+
71
+ if (format === 'object') return;
72
+ const keyValuePairs = typescriptParsers.typescriptObjectParser(format); // Now we have the key - value pairs
73
+ // Each key could either be required or not
74
+ // Just recursively check the object
75
+
76
+ keyValuePairs.forEach(_ref => {
77
+ let [objectKey, objectValue] = _ref;
78
+ const trueKey = objectKey.slice(-1) === '?' ? objectKey.slice(0, -1) : objectKey;
79
+
81
80
  if (trueKey === objectKey && !(trueKey in value)) {
82
- (0, import_errorTemplates.throwRequiredError)(schemaName, key);
81
+ errorTemplates.throwRequiredError(schemaName, key);
83
82
  }
83
+
84
84
  if (trueKey in value) {
85
- validateValueWithFormat(schemaName, `${key}[${trueKey}]`, value[trueKey], objectValue, validationsMemo, nextValidationsMemo);
85
+ // this is a recursive func, we need to invoke it before it's defined.
86
+ // eslint-disable-next-line @typescript-eslint/no-use-before-define
87
+ validateValueWithFormat(schemaName, "".concat(key, "[").concat(trueKey, "]"), value[trueKey], objectValue, validationsMemo, nextValidationsMemo);
86
88
  }
87
89
  });
88
90
  };
91
+
89
92
  const validateUnion = (schemaName, key, value, format, validationsMemo, nextValidationsMemo) => {
90
93
  const possibilities = format.split(/\s?\|\s?/);
91
94
  const errors = [];
92
- possibilities.forEach((possibility) => {
95
+ possibilities.forEach(possibility => {
93
96
  try {
97
+ // this is a recursive func, we need to invoke it before it's defined.
98
+ // eslint-disable-next-line @typescript-eslint/no-use-before-define
94
99
  validateValueWithFormat(schemaName, key, value, possibility, validationsMemo, nextValidationsMemo);
95
100
  } catch (e) {
96
101
  errors.push(e);
97
102
  }
98
103
  });
104
+
99
105
  if (errors.length === possibilities.length) {
100
- (0, import_errorTemplates.throwTypeError)(schemaName, key, value, format);
106
+ errorTemplates.throwTypeError(schemaName, key, value, format);
101
107
  }
102
108
  };
109
+
103
110
  const validateFunction = (schemaName, key, value, format) => {
104
- if (typeof value !== "function") {
105
- (0, import_errorTemplates.throwTypeError)(schemaName, key, value, format);
111
+ // Check that we have a function
112
+ if (typeof value !== 'function') {
113
+ errorTemplates.throwTypeError(schemaName, key, value, format);
106
114
  }
107
115
  };
116
+
108
117
  function isJSXElement(value) {
109
- return value === null || typeof value === "object" && value !== null && "$$typeof" in value;
118
+ return value === null || typeof value === 'object' && value !== null && '$$typeof' in value;
110
119
  }
120
+
111
121
  const validateJSXorNode = (schemaName, key, value, format) => {
112
122
  const valueIsJSX = isJSXElement(value);
113
- if (format === "JSX.Element" && !valueIsJSX) {
114
- (0, import_errorTemplates.throwTypeError)(schemaName, key, value, format);
123
+
124
+ if (format === 'JSX.Element' && !valueIsJSX) {
125
+ errorTemplates.throwTypeError(schemaName, key, value, format);
115
126
  }
116
- };
127
+ }; // =============================================================================
128
+ // Schema validator
129
+ // =============================================================================
130
+
131
+
117
132
  const validateValueWithFormat = (schemaName, key, value, format, validationsMemo, nextValidationsMemo) => {
118
133
  nextValidationsMemo[value] = format;
134
+
119
135
  if (value in validationsMemo) {
136
+ // We already validated this value on this format
120
137
  return;
121
138
  }
122
- if ((0, import_typescriptGuards.isUndefined)(format)) {
123
- validateUndefined(schemaName, key, value, format, validationsMemo, nextValidationsMemo);
124
- } else if ((0, import_typescriptGuards.isNull)(format)) {
125
- validateNull(schemaName, key, value, format, validationsMemo, nextValidationsMemo);
126
- } else if ((0, import_typescriptGuards.isPrimitiveType)(format)) {
127
- validatePrimitiveType(schemaName, key, value, format, validationsMemo, nextValidationsMemo);
128
- } else if ((0, import_typescriptGuards.isUnion)(format)) {
139
+
140
+ if (typescriptGuards.isUndefined(format)) {
141
+ validateUndefined(schemaName, key, value, format);
142
+ } else if (typescriptGuards.isNull(format)) {
143
+ validateNull(schemaName, key, value, format);
144
+ } else if (typescriptGuards.isPrimitiveType(format)) {
145
+ validatePrimitiveType(schemaName, key, value, format);
146
+ } else if (typescriptGuards.isUnion(format)) {
129
147
  validateUnion(schemaName, key, value, format, validationsMemo, nextValidationsMemo);
130
- } else if ((0, import_typescriptGuards.isString)(format)) {
131
- validateString(schemaName, key, value, format, validationsMemo, nextValidationsMemo);
132
- } else if ((0, import_typescriptGuards.isArray)(format)) {
148
+ } else if (typescriptGuards.isString(format)) {
149
+ validateString(schemaName, key, value, format);
150
+ } else if (typescriptGuards.isArray(format)) {
133
151
  validateArray(schemaName, key, value, format, validationsMemo, nextValidationsMemo);
134
- } else if ((0, import_typescriptGuards.isObject)(format)) {
152
+ } else if (typescriptGuards.isObject(format)) {
135
153
  validateObject(schemaName, key, value, format, validationsMemo, nextValidationsMemo);
136
- } else if ((0, import_typescriptGuards.isFunction)(format)) {
137
- validateFunction(schemaName, key, value, format, validationsMemo, nextValidationsMemo);
138
- } else if ((0, import_typescriptGuards.isJSXorNode)(format)) {
139
- validateJSXorNode(schemaName, key, value, format, validationsMemo, nextValidationsMemo);
140
- } else if ((0, import_typescriptGuards.isSomethingWithParenthesis)(format)) {
154
+ } else if (typescriptGuards.isFunction(format)) {
155
+ validateFunction(schemaName, key, value, format);
156
+ } else if (typescriptGuards.isJSXorNode(format)) {
157
+ validateJSXorNode(schemaName, key, value, format);
158
+ } else if (typescriptGuards.isSomethingWithParenthesis(format)) {
141
159
  validateValueWithFormat(schemaName, key, value, format.slice(1, -1), validationsMemo, nextValidationsMemo);
142
160
  }
143
161
  };
144
- const validateTypescriptPropTypesImplementation = (props, schema, validationsMemo = {}, nextValidationsMemo = {}) => {
145
- const { properties, name: schemaName } = schema;
146
- properties.forEach((property) => {
147
- const { name, format, required } = property;
162
+
163
+ const validateTypescriptPropTypesImplementation = function (props, schema) {
164
+ let validationsMemo = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
165
+ let nextValidationsMemo = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
166
+ const {
167
+ properties,
168
+ name: schemaName
169
+ } = schema;
170
+ properties.forEach(property => {
171
+ const {
172
+ name,
173
+ format,
174
+ required
175
+ } = property;
176
+
148
177
  if (required && !(name in props)) {
149
- (0, import_errorTemplates.throwRequiredError)(schema.name, name);
178
+ errorTemplates.throwRequiredError(schema.name, name);
150
179
  }
151
- if (name in props && (props[name] !== void 0 || required)) {
180
+
181
+ if (name in props && (props[name] !== undefined || required)) {
152
182
  validateValueWithFormat(schemaName, name, props[name], format, validationsMemo, nextValidationsMemo);
153
183
  }
154
184
  });
155
- };
185
+ }; // eslint-disable-next-line @typescript-eslint/no-explicit-any
186
+
156
187
  const useValidateTypescriptPropTypes = (props, propTypes) => {
157
- const [validationsMemo, setValidationsMemo] = (0, import_react.useState)({});
158
- const ComponentWithSchema = (0, import_react.useMemo)(() => {
159
- const Component = () => {
160
- };
161
- return (0, import_react_desc.describe)(Component);
162
- }, []);
188
+ const [validationsMemo, setValidationsMemo] = react.useState({}); // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
189
+
190
+ const ComponentWithSchema = react.useMemo(() => {
191
+ const Component = () => {}; // eslint-disable-next-line @typescript-eslint/no-unsafe-return, @typescript-eslint/no-unsafe-call
192
+
193
+
194
+ return reactDesc.describe(Component);
195
+ }, []); // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-assignment
196
+
163
197
  ComponentWithSchema.propTypes = propTypes;
164
- (0, import_react.useMemo)(() => {
198
+ react.useMemo(() => {
165
199
  const nextValidationsMemo = {};
166
- validateTypescriptPropTypesImplementation(props, ComponentWithSchema.toTypescript(), validationsMemo, nextValidationsMemo);
167
- setValidationsMemo(nextValidationsMemo);
200
+ validateTypescriptPropTypesImplementation(props, // eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
201
+ ComponentWithSchema.toTypescript(), validationsMemo, nextValidationsMemo);
202
+ setValidationsMemo(nextValidationsMemo); // eslint-disable-next-line react-hooks/exhaustive-deps
168
203
  }, [props]);
169
204
  };
170
- module.exports = __toCommonJS(typescriptValidator_exports);
171
- //# sourceMappingURL=typescriptValidator.js.map
205
+
206
+ exports.useValidateTypescriptPropTypes = useValidateTypescriptPropTypes;
207
+ exports.validateTypescriptPropTypesImplementation = validateTypescriptPropTypesImplementation;
@@ -1,55 +1,36 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __reExport = (target, module2, copyDefault, desc) => {
13
- if (module2 && typeof module2 === "object" || typeof module2 === "function") {
14
- for (let key of __getOwnPropNames(module2))
15
- if (!__hasOwnProp.call(target, key) && (copyDefault || key !== "default"))
16
- __defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
17
- }
18
- return target;
19
- };
20
- var __toESM = (module2, isNodeMode) => {
21
- return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", !isNodeMode && module2 && module2.__esModule ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
22
- };
23
- var __toCommonJS = /* @__PURE__ */ ((cache) => {
24
- return (module2, temp) => {
25
- return cache && cache.get(module2) || (temp = __reExport(__markAsModule({}), module2, 1), cache && cache.set(module2, temp), temp);
26
- };
27
- })(typeof WeakMap !== "undefined" ? /* @__PURE__ */ new WeakMap() : 0);
28
- var validator_exports = {};
29
- __export(validator_exports, {
30
- useValidatePropTypes: () => useValidatePropTypes
31
- });
32
- var React = __toESM(require("react"));
33
- var import_errorTemplates = require("./errorTemplates");
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
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
+ var errorTemplates = require('./errorTemplates.js');
9
+
34
10
  const useValidatePropTypes = (props, schema) => {
35
- schema.properties.forEach((property) => {
11
+ schema.properties.forEach(property => {
36
12
  const propertyName = property.name;
37
13
  const currentProp = props[propertyName];
38
- const currentPropTypeOf = typeof currentProp;
39
- const currentFormat = property.format;
40
- let isValidReactElement = false;
14
+ const currentPropTypeOf = typeof currentProp; // eslint-disable-next-line max-len
15
+
16
+ const currentFormat = property.format; // this is csv representing types e.g.: "string"/"string,number"/"[object],string"
17
+
18
+ let isValidReactElement = false; // this depends on react desc definition
19
+
41
20
  if (property.required && !Object.prototype.hasOwnProperty.call(props, property.name)) {
42
- (0, import_errorTemplates.throwRequiredError)(schema.name, property.name);
21
+ errorTemplates.throwRequiredError(schema.name, property.name);
43
22
  }
44
- if (currentPropTypeOf !== "undefined" && currentProp !== null) {
45
- if (currentPropTypeOf === "object" && Object.prototype.hasOwnProperty.call(currentProp, "$$typeof") && (currentFormat.includes("node") || currentFormat.includes("element"))) {
23
+
24
+ if (currentPropTypeOf !== 'undefined' && currentProp !== null) {
25
+ if (currentPropTypeOf === 'object' && Object.prototype.hasOwnProperty.call(currentProp, '$$typeof') && (currentFormat.includes('node') || currentFormat.includes('element'))) {
46
26
  isValidReactElement = true;
47
27
  }
28
+
48
29
  if (!currentFormat.includes(currentPropTypeOf) && !currentFormat.includes(currentProp) && !isValidReactElement) {
49
- (0, import_errorTemplates.throwTypeError)(schema.name, propertyName, currentProp, currentFormat);
30
+ errorTemplates.throwTypeError(schema.name, propertyName, currentProp, currentFormat);
50
31
  }
51
32
  }
52
33
  });
53
34
  };
54
- module.exports = __toCommonJS(validator_exports);
55
- //# sourceMappingURL=validator.js.map
35
+
36
+ exports.useValidatePropTypes = useValidatePropTypes;
@@ -1,3 +1 @@
1
- import * as React from "react";
2
- export * from "./useMemoMergePropsWithDefault";
3
- //# sourceMappingURL=index.js.map
1
+ export { useMemoMergePropsWithDefault } from './useMemoMergePropsWithDefault.js';
@@ -1,19 +1,39 @@
1
- import * as React from "react";
2
- import { useRef } from "react";
3
- import deepequal from "fast-deep-equal/react";
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';
6
+ import _defineProperty from '@babel/runtime/helpers/esm/defineProperty';
7
+ import { useRef } from 'react';
8
+ import deepequal from 'fast-deep-equal/react';
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
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
14
+
4
15
  const useMemoCompare = (next, compare) => {
16
+ // Ref for storing previous value
5
17
  const previousRef = useRef(next);
6
- const previous = previousRef.current;
7
- const isEqual = compare(previous, next);
8
- if (!isEqual)
9
- previousRef.current = next;
18
+ const previous = previousRef.current; // Pass previous and next value to compare function
19
+ // to determine whether to consider them equal.
20
+
21
+ const isEqual = compare(previous, next); // If not equal update previousRef to next value.
22
+ // We only update if not equal so that this hook continues to return
23
+ // the same old value if compare keeps returning true.
24
+
25
+ if (!isEqual) previousRef.current = next; // Finally, if equal then return the previous value
26
+
10
27
  return isEqual ? previous : next;
11
- };
12
- const useMemoMergePropsWithDefault = (props, defaultProps, compare = deepequal) => {
13
- const mergedProps = { ...defaultProps, ...props };
28
+ }; // eslint-disable-next-line @typescript-eslint/no-explicit-any
29
+
30
+
31
+ const useMemoMergePropsWithDefault = function (props, defaultProps) {
32
+ let compare = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : deepequal;
33
+
34
+ const mergedProps = _objectSpread(_objectSpread({}, defaultProps), props);
35
+
14
36
  return useMemoCompare(mergedProps, compare);
15
37
  };
16
- export {
17
- useMemoMergePropsWithDefault
18
- };
19
- //# sourceMappingURL=useMemoMergePropsWithDefault.js.map
38
+
39
+ export { useMemoMergePropsWithDefault };
@@ -1,8 +1,15 @@
1
- import * as React from "react";
2
- const getAriaProps = (props) => Object.fromEntries(Object.entries(props).filter(([key]) => key.includes("aria-")));
3
- const getDataProps = (props) => Object.fromEntries(Object.entries(props).filter(([key]) => key.includes("data-")));
4
- export {
5
- getAriaProps,
6
- getDataProps
7
- };
8
- //# sourceMappingURL=index.js.map
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
+ }));
14
+
15
+ export { getAriaProps, getDataProps };
package/esm/index.js CHANGED
@@ -1,5 +1,5 @@
1
- import * as React from "react";
2
- export * from "./defaultProps";
3
- export * from "./validation";
4
- export * from "./getProps";
5
- //# sourceMappingURL=index.js.map
1
+ export { useMemoMergePropsWithDefault } from './defaultProps/useMemoMergePropsWithDefault.js';
2
+ export { useValidatePropTypes } from './validation/validator.js';
3
+ export { throwRequiredError, throwTypeError } from './validation/errorTemplates.js';
4
+ export { useValidateTypescriptPropTypes, validateTypescriptPropTypesImplementation } from './validation/typescriptValidator.js';
5
+ export { getAriaProps, getDataProps } from './getProps/index.js';
@@ -1,19 +1,11 @@
1
- import * as React from "react";
2
- const throwTypeError = (componentName, validPropKey, invalidProp, validFormat) => {
3
- throw new Error(`${componentName}:: You are trying to pass a not valid "${validPropKey}" property,
4
- please provide a valid type.
1
+ import 'core-js/modules/es.string.replace.js';
5
2
 
6
- Received: ${invalidProp} (${typeof invalidProp})
7
- Expected: (${validFormat.replace("\n", " or ")})
8
- `);
3
+ /* eslint-disable max-params */
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 "));
9
6
  };
10
7
  const throwRequiredError = (componentName, validPropKey) => {
11
- throw new Error(`${componentName}:: Please provide a/an "${validPropKey}" property to use this component.
12
- This property is required.
13
- `);
8
+ throw new Error("".concat(componentName, ":: Please provide a/an \"").concat(validPropKey, "\" property to use this component. \n This property is required.\n "));
14
9
  };
15
- export {
16
- throwRequiredError,
17
- throwTypeError
18
- };
19
- //# sourceMappingURL=errorTemplates.js.map
10
+
11
+ export { throwRequiredError, throwTypeError };
@@ -1,5 +1,3 @@
1
- import * as React from "react";
2
- export * from "./validator";
3
- export * from "./errorTemplates";
4
- export * from "./typescriptValidator";
5
- //# sourceMappingURL=index.js.map
1
+ export { useValidatePropTypes } from './validator.js';
2
+ export { throwRequiredError, throwTypeError } from './errorTemplates.js';
3
+ export { useValidateTypescriptPropTypes, validateTypescriptPropTypesImplementation } from './typescriptValidator.js';
@@ -1,36 +1,23 @@
1
- import * as React from "react";
2
- const isPrimitiveType = (format) => ["string", "number", "boolean"].includes(format);
3
- const isUndefined = (format) => format === '"undefined"';
4
- const isNull = (format) => format === '"null"';
5
- const isUnion = (format) => {
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 isNull = format => format === '"null"';
8
+ const isUnion = format => {
6
9
  let depth = 0;
7
10
  let satisfies = false;
8
- format.split("").forEach((char) => {
9
- if (["{", "("].includes(char))
10
- depth += 1;
11
- else if (["}", ")"].includes(char))
12
- depth -= 1;
13
- else if (char === "|" && depth === 0)
14
- satisfies = true;
11
+ format.split('').forEach(char => {
12
+ if (['{', '('].includes(char)) depth += 1;else if (['}', ')'].includes(char)) depth -= 1;else if (char === '|' && depth === 0) satisfies = true;
15
13
  });
16
14
  return satisfies;
17
15
  };
18
- const isString = (format) => !isUnion(format) && format[0] === '"' && format.slice(-1) === '"';
19
- const isArray = (format) => !isUnion(format) && format.slice(-2) === "[]";
20
- const isObject = (format) => format === "object" || !isUnion(format) && format[0] === "{" && format.slice(-1) === "}";
21
- const isFunction = (format) => !isUnion(format) && format === "((...args: any[]) => any)";
22
- const isJSXorNode = (format) => !isUnion(format) && ["React.ReactNode", "JSX.Element"].includes(format);
23
- const isSomethingWithParenthesis = (format) => !isUnion(format) && format[0] === "(" && format.slice(-1) === ")";
24
- export {
25
- isArray,
26
- isFunction,
27
- isJSXorNode,
28
- isNull,
29
- isObject,
30
- isPrimitiveType,
31
- isSomethingWithParenthesis,
32
- isString,
33
- isUndefined,
34
- isUnion
35
- };
36
- //# sourceMappingURL=typescriptGuards.js.map
16
+ const isString = format => !isUnion(format) && format[0] === '"' && format.slice(-1) === '"';
17
+ const isArray = format => !isUnion(format) && format.slice(-2) === '[]';
18
+ const isObject = format => format === 'object' || !isUnion(format) && format[0] === '{' && format.slice(-1) === '}';
19
+ const isFunction = format => !isUnion(format) && format === '((...args: any[]) => any)';
20
+ const isJSXorNode = format => !isUnion(format) && ['React.ReactNode', 'JSX.Element'].includes(format);
21
+ const isSomethingWithParenthesis = format => !isUnion(format) && format[0] === '(' && format.slice(-1) === ')';
22
+
23
+ export { isArray, isFunction, isJSXorNode, isNull, isObject, isPrimitiveType, isSomethingWithParenthesis, isString, isUndefined, isUnion };