@elliemae/ds-props-helpers 2.2.0-next.4 → 2.3.0-alpha.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.
Files changed (59) hide show
  1. package/cjs/defaultProps/index.js +28 -9
  2. package/cjs/defaultProps/index.js.map +7 -0
  3. package/cjs/defaultProps/useMemoMergePropsWithDefault.js +44 -44
  4. package/cjs/defaultProps/useMemoMergePropsWithDefault.js.map +7 -0
  5. package/cjs/getProps/index.js +37 -20
  6. package/cjs/getProps/index.js.map +7 -0
  7. package/cjs/index.js +30 -24
  8. package/cjs/index.js.map +7 -0
  9. package/cjs/tests/test.schema.js +67 -0
  10. package/cjs/tests/test.schema.js.map +7 -0
  11. package/cjs/validation/errorTemplates.js +44 -12
  12. package/cjs/validation/errorTemplates.js.map +7 -0
  13. package/cjs/validation/index.js +30 -15
  14. package/cjs/validation/index.js.map +7 -0
  15. package/cjs/validation/typescriptGuards.js +60 -31
  16. package/cjs/validation/typescriptGuards.js.map +7 -0
  17. package/cjs/validation/typescriptParsers.js +65 -34
  18. package/cjs/validation/typescriptParsers.js.map +7 -0
  19. package/cjs/validation/typescriptValidator.js +99 -135
  20. package/cjs/validation/typescriptValidator.js.map +7 -0
  21. package/cjs/validation/validator.js +43 -24
  22. package/cjs/validation/validator.js.map +7 -0
  23. package/esm/defaultProps/index.js +3 -1
  24. package/esm/defaultProps/index.js.map +7 -0
  25. package/esm/defaultProps/useMemoMergePropsWithDefault.js +14 -34
  26. package/esm/defaultProps/useMemoMergePropsWithDefault.js.map +7 -0
  27. package/esm/getProps/index.js +8 -15
  28. package/esm/getProps/index.js.map +7 -0
  29. package/esm/index.js +5 -7
  30. package/esm/index.js.map +7 -0
  31. package/esm/tests/test.schema.js +38 -0
  32. package/esm/tests/test.schema.js.map +7 -0
  33. package/esm/validation/errorTemplates.js +15 -7
  34. package/esm/validation/errorTemplates.js.map +7 -0
  35. package/esm/validation/index.js +5 -3
  36. package/esm/validation/index.js.map +7 -0
  37. package/esm/validation/typescriptGuards.js +31 -18
  38. package/esm/validation/typescriptGuards.js.map +7 -0
  39. package/esm/validation/typescriptParsers.js +36 -30
  40. package/esm/validation/typescriptParsers.js.map +7 -0
  41. package/esm/validation/typescriptValidator.js +57 -106
  42. package/esm/validation/typescriptValidator.js.map +7 -0
  43. package/esm/validation/validator.js +12 -18
  44. package/esm/validation/validator.js.map +7 -0
  45. package/package.json +1 -17
  46. package/types/index.d.ts +0 -1
  47. package/types/validation/typescriptValidator.d.ts +2 -2
  48. package/cjs/globalProps/constants.js +0 -15
  49. package/cjs/globalProps/globalAttributesPropTypes.js +0 -372
  50. package/cjs/globalProps/index.js +0 -11
  51. package/cjs/globalProps/useGetGlobalAttributes.js +0 -36
  52. package/esm/globalProps/constants.js +0 -11
  53. package/esm/globalProps/globalAttributesPropTypes.js +0 -368
  54. package/esm/globalProps/index.js +0 -2
  55. package/esm/globalProps/useGetGlobalAttributes.js +0 -32
  56. package/types/globalProps/constants.d.ts +0 -3
  57. package/types/globalProps/globalAttributesPropTypes.d.ts +0 -2169
  58. package/types/globalProps/index.d.ts +0 -2
  59. package/types/globalProps/useGetGlobalAttributes.d.ts +0 -5
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../../scripts/build/transpile/react-shim.js", "../../../src/defaultProps/useMemoMergePropsWithDefault.ts"],
4
+ "sourcesContent": ["import * as React from 'react';\nexport { React };\n", "import { useRef } from 'react';\nimport deepequal from 'fast-deep-equal/react';\n\n// Hook\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nconst useMemoCompare = <T = any>(next: T, compare: (prevToCompare: T, nextToCompare: T) => boolean): T => {\n // Ref for storing previous value\n const previousRef = useRef(next);\n const previous = previousRef.current;\n // Pass previous and next value to compare function\n // to determine whether to consider them equal.\n const isEqual = compare(previous, next);\n // If not equal update previousRef to next value.\n // We only update if not equal so that this hook continues to return\n // the same old value if compare keeps returning true.\n if (!isEqual) previousRef.current = next;\n // Finally, if equal then return the previous value\n return isEqual ? previous : next;\n};\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport const useMemoMergePropsWithDefault = <T = Record<string, any>>(\n props: Partial<T>,\n defaultProps: Partial<T>,\n compare = deepequal,\n): T => {\n const mergedProps = { ...defaultProps, ...props } as T;\n\n return useMemoCompare<T>(mergedProps, compare);\n};\n"],
5
+ "mappings": "AAAA;ACAA;AACA;AAIA,MAAM,iBAAiB,CAAU,MAAS,YAAgE;AAExG,QAAM,cAAc,OAAO;AAC3B,QAAM,WAAW,YAAY;AAG7B,QAAM,UAAU,QAAQ,UAAU;AAIlC,MAAI,CAAC;AAAS,gBAAY,UAAU;AAEpC,SAAO,UAAU,WAAW;AAAA;AAIvB,MAAM,+BAA+B,CAC1C,OACA,cACA,UAAU,cACJ;AACN,QAAM,cAAc,KAAK,iBAAiB;AAE1C,SAAO,eAAkB,aAAa;AAAA;",
6
+ "names": []
7
+ }
@@ -1,15 +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/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 };
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
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../../scripts/build/transpile/react-shim.js", "../../../src/getProps/index.ts"],
4
+ "sourcesContent": ["import * as React from 'react';\nexport { React };\n", "export const getAriaProps = (props: Record<string, unknown>): Record<string, unknown> =>\n Object.fromEntries(Object.entries(props).filter(([key]) => key.includes('aria-')));\n\nexport const getDataProps = (props: Record<string, unknown>): Record<string, unknown> =>\n Object.fromEntries(Object.entries(props).filter(([key]) => key.includes('data-')));\n"],
5
+ "mappings": "AAAA;ACAO,MAAM,eAAe,CAAC,UAC3B,OAAO,YAAY,OAAO,QAAQ,OAAO,OAAO,CAAC,CAAC,SAAS,IAAI,SAAS;AAEnE,MAAM,eAAe,CAAC,UAC3B,OAAO,YAAY,OAAO,QAAQ,OAAO,OAAO,CAAC,CAAC,SAAS,IAAI,SAAS;",
6
+ "names": []
7
+ }
package/esm/index.js CHANGED
@@ -1,7 +1,5 @@
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';
6
- export { useGetGlobalAttributes } from './globalProps/useGetGlobalAttributes.js';
7
- export { globalAttributesPropTypes } from './globalProps/globalAttributesPropTypes.js';
1
+ import * as React from "react";
2
+ export * from "./defaultProps";
3
+ export * from "./validation";
4
+ export * from "./getProps";
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../scripts/build/transpile/react-shim.js", "../../src/index.ts"],
4
+ "sourcesContent": ["import * as React from 'react';\nexport { React };\n", "export * from './defaultProps';\nexport * from './validation';\nexport * from './getProps';\n"],
5
+ "mappings": "AAAA;ACAA;AACA;AACA;",
6
+ "names": []
7
+ }
@@ -0,0 +1,38 @@
1
+ import * as React from "react";
2
+ import { PropTypes, describe } from "react-desc";
3
+ const TestSchema = {
4
+ string: PropTypes.string.description("String"),
5
+ number: PropTypes.number.description("Number"),
6
+ boolean: PropTypes.bool.description("Boolean"),
7
+ any: PropTypes.any.description("Any"),
8
+ union: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).description("Union"),
9
+ union2: PropTypes.oneOf(["A", "B"]).description("Union 2"),
10
+ union3: PropTypes.oneOfType([
11
+ PropTypes.string,
12
+ PropTypes.arrayOf(PropTypes.string),
13
+ PropTypes.shape({ string: PropTypes.string })
14
+ ]).description("Union 3"),
15
+ array: PropTypes.arrayOf(PropTypes.string).description("Array"),
16
+ object: PropTypes.object.description("Object"),
17
+ shape: PropTypes.shape({
18
+ string: PropTypes.string.description("String").isRequired,
19
+ number: PropTypes.number.description("Number"),
20
+ boolean: PropTypes.bool.description("Boolean"),
21
+ anotherShape: PropTypes.shape({
22
+ string: PropTypes.string.description("String").isRequired,
23
+ number: PropTypes.number.description("Number"),
24
+ boolean: PropTypes.bool.description("Boolean")
25
+ }).description("Another shape")
26
+ }).description("Shape"),
27
+ function: PropTypes.func.description("Function"),
28
+ jsx: PropTypes.element.description("JSX"),
29
+ node: PropTypes.node.description("Node")
30
+ };
31
+ const TestComponent = () => null;
32
+ const TestComponentWithSchema = describe(TestComponent).description("Test Component");
33
+ TestComponentWithSchema.propTypes = TestSchema;
34
+ const TypescriptSchema = TestComponentWithSchema.toTypescript();
35
+ export {
36
+ TypescriptSchema
37
+ };
38
+ //# sourceMappingURL=test.schema.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../../scripts/build/transpile/react-shim.js", "../../../src/tests/test.schema.js"],
4
+ "sourcesContent": ["import * as React from 'react';\nexport { React };\n", "import { PropTypes, describe } from 'react-desc';\n\nconst TestSchema = {\n string: PropTypes.string.description('String'),\n number: PropTypes.number.description('Number'),\n boolean: PropTypes.bool.description('Boolean'),\n any: PropTypes.any.description('Any'),\n union: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).description('Union'),\n union2: PropTypes.oneOf(['A', 'B']).description('Union 2'),\n union3: PropTypes.oneOfType([\n PropTypes.string,\n PropTypes.arrayOf(PropTypes.string),\n PropTypes.shape({ string: PropTypes.string }),\n ]).description('Union 3'),\n array: PropTypes.arrayOf(PropTypes.string).description('Array'),\n object: PropTypes.object.description('Object'),\n shape: PropTypes.shape({\n string: PropTypes.string.description('String').isRequired,\n number: PropTypes.number.description('Number'),\n boolean: PropTypes.bool.description('Boolean'),\n anotherShape: PropTypes.shape({\n string: PropTypes.string.description('String').isRequired,\n number: PropTypes.number.description('Number'),\n boolean: PropTypes.bool.description('Boolean'),\n }).description('Another shape'),\n }).description('Shape'),\n function: PropTypes.func.description('Function'),\n jsx: PropTypes.element.description('JSX'),\n node: PropTypes.node.description('Node'),\n};\n\nconst TestComponent = () => null;\n\nconst TestComponentWithSchema = describe(TestComponent).description('Test Component');\n\nTestComponentWithSchema.propTypes = TestSchema;\n\nexport const TypescriptSchema = TestComponentWithSchema.toTypescript();\n"],
5
+ "mappings": "AAAA;ACAA;AAEA,MAAM,aAAa;AAAA,EACjB,QAAQ,UAAU,OAAO,YAAY;AAAA,EACrC,QAAQ,UAAU,OAAO,YAAY;AAAA,EACrC,SAAS,UAAU,KAAK,YAAY;AAAA,EACpC,KAAK,UAAU,IAAI,YAAY;AAAA,EAC/B,OAAO,UAAU,UAAU,CAAC,UAAU,QAAQ,UAAU,SAAS,YAAY;AAAA,EAC7E,QAAQ,UAAU,MAAM,CAAC,KAAK,MAAM,YAAY;AAAA,EAChD,QAAQ,UAAU,UAAU;AAAA,IAC1B,UAAU;AAAA,IACV,UAAU,QAAQ,UAAU;AAAA,IAC5B,UAAU,MAAM,EAAE,QAAQ,UAAU;AAAA,KACnC,YAAY;AAAA,EACf,OAAO,UAAU,QAAQ,UAAU,QAAQ,YAAY;AAAA,EACvD,QAAQ,UAAU,OAAO,YAAY;AAAA,EACrC,OAAO,UAAU,MAAM;AAAA,IACrB,QAAQ,UAAU,OAAO,YAAY,UAAU;AAAA,IAC/C,QAAQ,UAAU,OAAO,YAAY;AAAA,IACrC,SAAS,UAAU,KAAK,YAAY;AAAA,IACpC,cAAc,UAAU,MAAM;AAAA,MAC5B,QAAQ,UAAU,OAAO,YAAY,UAAU;AAAA,MAC/C,QAAQ,UAAU,OAAO,YAAY;AAAA,MACrC,SAAS,UAAU,KAAK,YAAY;AAAA,OACnC,YAAY;AAAA,KACd,YAAY;AAAA,EACf,UAAU,UAAU,KAAK,YAAY;AAAA,EACrC,KAAK,UAAU,QAAQ,YAAY;AAAA,EACnC,MAAM,UAAU,KAAK,YAAY;AAAA;AAGnC,MAAM,gBAAgB,MAAM;AAE5B,MAAM,0BAA0B,SAAS,eAAe,YAAY;AAEpE,wBAAwB,YAAY;AAE7B,MAAM,mBAAmB,wBAAwB;",
6
+ "names": []
7
+ }
@@ -1,11 +1,19 @@
1
- import 'core-js/modules/es.string.replace.js';
2
-
3
- /* eslint-disable max-params */
1
+ import * as React from "react";
4
2
  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 "));
3
+ throw new Error(`${componentName}:: You are trying to pass a not valid "${validPropKey}" property,
4
+ please provide a valid type.
5
+
6
+ Received: ${invalidProp} (${typeof invalidProp})
7
+ Expected: (${validFormat.replace("\n", " or ")})
8
+ `);
6
9
  };
7
10
  const throwRequiredError = (componentName, validPropKey) => {
8
- throw new Error("".concat(componentName, ":: Please provide a/an \"").concat(validPropKey, "\" property to use this component. \n This property is required.\n "));
11
+ throw new Error(`${componentName}:: Please provide a/an "${validPropKey}" property to use this component.
12
+ This property is required.
13
+ `);
9
14
  };
10
-
11
- export { throwRequiredError, throwTypeError };
15
+ export {
16
+ throwRequiredError,
17
+ throwTypeError
18
+ };
19
+ //# sourceMappingURL=errorTemplates.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../../scripts/build/transpile/react-shim.js", "../../../src/validation/errorTemplates.ts"],
4
+ "sourcesContent": ["import * as React from 'react';\nexport { React };\n", "/* eslint-disable max-params */\nexport const throwTypeError = (\n componentName: string,\n validPropKey: string,\n invalidProp: unknown,\n validFormat: string,\n): void => {\n throw new Error(\n `${componentName}:: You are trying to pass a not valid \"${validPropKey}\" property, \n please provide a valid type.\n\n Received: ${invalidProp} (${typeof invalidProp})\n Expected: (${validFormat.replace('\\n', ' or ')})\n `,\n );\n};\n\nexport const throwRequiredError = (componentName: string, validPropKey: string): void => {\n throw new Error(\n `${componentName}:: Please provide a/an \"${validPropKey}\" property to use this component. \n This property is required.\n `,\n );\n};\n"],
5
+ "mappings": "AAAA;ACCO,MAAM,iBAAiB,CAC5B,eACA,cACA,aACA,gBACS;AACT,QAAM,IAAI,MACR,GAAG,uDAAuD;AAAA;AAAA;AAAA,cAGhD,gBAAgB,OAAO;AAAA,eACtB,YAAY,QAAQ,MAAM;AAAA;AAAA;AAKlC,MAAM,qBAAqB,CAAC,eAAuB,iBAA+B;AACvF,QAAM,IAAI,MACR,GAAG,wCAAwC;AAAA;AAAA;AAAA;",
6
+ "names": []
7
+ }
@@ -1,3 +1,5 @@
1
- export { useValidatePropTypes } from './validator.js';
2
- export { throwRequiredError, throwTypeError } from './errorTemplates.js';
3
- export { useValidateTypescriptPropTypes, validateTypescriptPropTypesImplementation } from './typescriptValidator.js';
1
+ import * as React from "react";
2
+ export * from "./validator";
3
+ export * from "./errorTemplates";
4
+ export * from "./typescriptValidator";
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../../scripts/build/transpile/react-shim.js", "../../../src/validation/index.ts"],
4
+ "sourcesContent": ["import * as React from 'react';\nexport { React };\n", "export * from './validator';\nexport * from './errorTemplates';\nexport * from './typescriptValidator';\n"],
5
+ "mappings": "AAAA;ACAA;AACA;AACA;",
6
+ "names": []
7
+ }
@@ -1,23 +1,36 @@
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 => {
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) => {
9
6
  let depth = 0;
10
7
  let satisfies = false;
11
- format.split('').forEach(char => {
12
- if (['{', '('].includes(char)) depth += 1;else if (['}', ')'].includes(char)) depth -= 1;else if (char === '|' && depth === 0) satisfies = true;
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;
13
15
  });
14
16
  return satisfies;
15
17
  };
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 };
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
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../../scripts/build/transpile/react-shim.js", "../../../src/validation/typescriptGuards.ts"],
4
+ "sourcesContent": ["import * as React from 'react';\nexport { React };\n", "type GuardFn = (format: string) => boolean;\n\nexport const isPrimitiveType: GuardFn = (format) => ['string', 'number', 'boolean'].includes(format);\nexport const isUndefined: GuardFn = (format) => format === '\"undefined\"';\nexport const isNull: GuardFn = (format) => format === '\"null\"';\nexport const isUnion: GuardFn = (format) => {\n let depth = 0;\n let satisfies = false;\n format.split('').forEach((char) => {\n if (['{', '('].includes(char)) depth += 1;\n else if (['}', ')'].includes(char)) depth -= 1;\n else if (char === '|' && depth === 0) satisfies = true;\n });\n return satisfies;\n};\n\nexport const isString: GuardFn = (format) => !isUnion(format) && format[0] === '\"' && format.slice(-1) === '\"';\n\nexport const isArray: GuardFn = (format) => !isUnion(format) && format.slice(-2) === '[]';\n\nexport const isObject: GuardFn = (format) =>\n format === 'object' || (!isUnion(format) && format[0] === '{' && format.slice(-1) === '}');\n\nexport const isFunction: GuardFn = (format) => !isUnion(format) && format === '((...args: any[]) => any)';\n\nexport const isJSXorNode: GuardFn = (format) => !isUnion(format) && ['React.ReactNode', 'JSX.Element'].includes(format);\n\nexport const isSomethingWithParenthesis: GuardFn = (format) =>\n !isUnion(format) && format[0] === '(' && format.slice(-1) === ')';\n"],
5
+ "mappings": "AAAA;ACEO,MAAM,kBAA2B,CAAC,WAAW,CAAC,UAAU,UAAU,WAAW,SAAS;AACtF,MAAM,cAAuB,CAAC,WAAW,WAAW;AACpD,MAAM,SAAkB,CAAC,WAAW,WAAW;AAC/C,MAAM,UAAmB,CAAC,WAAW;AAC1C,MAAI,QAAQ;AACZ,MAAI,YAAY;AAChB,SAAO,MAAM,IAAI,QAAQ,CAAC,SAAS;AACjC,QAAI,CAAC,KAAK,KAAK,SAAS;AAAO,eAAS;AAAA,aAC/B,CAAC,KAAK,KAAK,SAAS;AAAO,eAAS;AAAA,aACpC,SAAS,OAAO,UAAU;AAAG,kBAAY;AAAA;AAEpD,SAAO;AAAA;AAGF,MAAM,WAAoB,CAAC,WAAW,CAAC,QAAQ,WAAW,OAAO,OAAO,OAAO,OAAO,MAAM,QAAQ;AAEpG,MAAM,UAAmB,CAAC,WAAW,CAAC,QAAQ,WAAW,OAAO,MAAM,QAAQ;AAE9E,MAAM,WAAoB,CAAC,WAChC,WAAW,YAAa,CAAC,QAAQ,WAAW,OAAO,OAAO,OAAO,OAAO,MAAM,QAAQ;AAEjF,MAAM,aAAsB,CAAC,WAAW,CAAC,QAAQ,WAAW,WAAW;AAEvE,MAAM,cAAuB,CAAC,WAAW,CAAC,QAAQ,WAAW,CAAC,mBAAmB,eAAe,SAAS;AAEzG,MAAM,6BAAsC,CAAC,WAClD,CAAC,QAAQ,WAAW,OAAO,OAAO,OAAO,OAAO,MAAM,QAAQ;",
6
+ "names": []
7
+ }
@@ -1,41 +1,47 @@
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
- /* eslint-disable complexity */
6
- const typescriptObjectParser = format => {
7
- const keyValuePairs = []; // State of the algorithm
8
-
9
- let lastKey = '';
10
- let lastValue = '';
1
+ import * as React from "react";
2
+ const typescriptObjectParser = (format) => {
3
+ const keyValuePairs = [];
4
+ let lastKey = "";
5
+ let lastValue = "";
11
6
  let shouldAppendToKey = true;
12
-
13
7
  const pushPair = () => {
14
- if (lastKey) keyValuePairs.push([lastKey, lastValue]);
15
- lastKey = '';
16
- lastValue = '';
8
+ if (lastKey)
9
+ keyValuePairs.push([lastKey, lastValue]);
10
+ lastKey = "";
11
+ lastValue = "";
17
12
  shouldAppendToKey = true;
18
- }; // Complex -- but working -- logic
19
-
20
-
13
+ };
21
14
  let depth = 0;
22
- format.split('').forEach(char => {
23
- if (char === '{') {
15
+ format.split("").forEach((char) => {
16
+ if (char === "{") {
24
17
  depth += 1;
25
- if (depth > 1) lastValue += char;
26
- } else if (char === '}') {
27
- if (depth > 1) lastValue += char;
18
+ if (depth > 1)
19
+ lastValue += char;
20
+ } else if (char === "}") {
21
+ if (depth > 1)
22
+ lastValue += char;
28
23
  depth -= 1;
29
- if (depth === 1) pushPair();
30
- } else if (char === ':') {
24
+ if (depth === 1)
25
+ pushPair();
26
+ } else if (char === ":") {
31
27
  shouldAppendToKey = false;
32
- if (depth > 1) lastValue += char;
33
- } else if (char === ',') {
34
- if (depth === 1) pushPair();else lastValue += char;
35
- } else if (char === ' ') ; else if (shouldAppendToKey) lastKey += char;else lastValue += char;
28
+ if (depth > 1)
29
+ lastValue += char;
30
+ } else if (char === ",") {
31
+ if (depth === 1)
32
+ pushPair();
33
+ else
34
+ lastValue += char;
35
+ } else if (char === " ") {
36
+ } else if (shouldAppendToKey)
37
+ lastKey += char;
38
+ else
39
+ lastValue += char;
36
40
  });
37
41
  pushPair();
38
42
  return keyValuePairs;
39
43
  };
40
-
41
- export { typescriptObjectParser };
44
+ export {
45
+ typescriptObjectParser
46
+ };
47
+ //# sourceMappingURL=typescriptParsers.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../../scripts/build/transpile/react-shim.js", "../../../src/validation/typescriptParsers.ts"],
4
+ "sourcesContent": ["import * as React from 'react';\nexport { React };\n", "/* eslint-disable complexity */\nexport const typescriptObjectParser = (format: string): [string, string][] => {\n const keyValuePairs: [string, string][] = [];\n\n // State of the algorithm\n let lastKey = '';\n let lastValue = '';\n let shouldAppendToKey = true;\n\n const pushPair = () => {\n if (lastKey) keyValuePairs.push([lastKey, lastValue]);\n lastKey = '';\n lastValue = '';\n shouldAppendToKey = true;\n };\n\n // Complex -- but working -- logic\n let depth = 0;\n format.split('').forEach((char) => {\n if (char === '{') {\n depth += 1;\n if (depth > 1) lastValue += char;\n } else if (char === '}') {\n if (depth > 1) lastValue += char;\n depth -= 1;\n if (depth === 1) pushPair();\n } else if (char === ':') {\n shouldAppendToKey = false;\n if (depth > 1) lastValue += char;\n } else if (char === ',') {\n if (depth === 1) pushPair();\n else lastValue += char;\n } else if (char === ' ') {\n // Do nothing\n } else if (shouldAppendToKey) lastKey += char;\n else lastValue += char;\n });\n pushPair();\n\n return keyValuePairs;\n};\n"],
5
+ "mappings": "AAAA;ACCO,MAAM,yBAAyB,CAAC,WAAuC;AAC5E,QAAM,gBAAoC;AAG1C,MAAI,UAAU;AACd,MAAI,YAAY;AAChB,MAAI,oBAAoB;AAExB,QAAM,WAAW,MAAM;AACrB,QAAI;AAAS,oBAAc,KAAK,CAAC,SAAS;AAC1C,cAAU;AACV,gBAAY;AACZ,wBAAoB;AAAA;AAItB,MAAI,QAAQ;AACZ,SAAO,MAAM,IAAI,QAAQ,CAAC,SAAS;AACjC,QAAI,SAAS,KAAK;AAChB,eAAS;AACT,UAAI,QAAQ;AAAG,qBAAa;AAAA,eACnB,SAAS,KAAK;AACvB,UAAI,QAAQ;AAAG,qBAAa;AAC5B,eAAS;AACT,UAAI,UAAU;AAAG;AAAA,eACR,SAAS,KAAK;AACvB,0BAAoB;AACpB,UAAI,QAAQ;AAAG,qBAAa;AAAA,eACnB,SAAS,KAAK;AACvB,UAAI,UAAU;AAAG;AAAA;AACZ,qBAAa;AAAA,eACT,SAAS,KAAK;AAAA,eAEd;AAAmB,iBAAW;AAAA;AACpC,mBAAa;AAAA;AAEpB;AAEA,SAAO;AAAA;",
6
+ "names": []
7
+ }
@@ -1,202 +1,153 @@
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';
6
- import { useState, useMemo } from 'react';
7
- import { throwRequiredError, throwTypeError } from './errorTemplates.js';
8
- import { isUndefined, isNull, isPrimitiveType, isUnion, isString, isArray, isObject, isFunction, isJSXorNode, isSomethingWithParenthesis } from './typescriptGuards.js';
9
- import { typescriptObjectParser } from './typescriptParsers.js';
10
-
11
- // =============================================================================
12
- // Atom Validators
13
- // =============================================================================
14
- // This functions will validate something from the data
15
- // and optionally recursively apply `validateValueWithFormat`
16
- // in smaller parts
1
+ import * as React from "react";
2
+ import { describe } from "react-desc";
3
+ import { useMemo, useState } from "react";
4
+ import { throwRequiredError, throwTypeError } from "./errorTemplates";
5
+ import {
6
+ isArray,
7
+ isFunction,
8
+ isJSXorNode,
9
+ isObject,
10
+ isPrimitiveType,
11
+ isSomethingWithParenthesis,
12
+ isString,
13
+ isUnion,
14
+ isUndefined,
15
+ isNull
16
+ } from "./typescriptGuards";
17
+ import { typescriptObjectParser } from "./typescriptParsers";
17
18
  const validateUndefined = (schemaName, key, value, format) => {
18
- if (value !== undefined || value === 'undefined') {
19
+ if (value !== void 0 || value === "undefined") {
19
20
  throwTypeError(schemaName, key, value, format);
20
21
  }
21
22
  };
22
-
23
23
  const validateNull = (schemaName, key, value, format) => {
24
- if (value !== null || value === 'null') {
24
+ if (value !== null || value === "null") {
25
25
  throwTypeError(schemaName, key, value, format);
26
26
  }
27
27
  };
28
-
29
28
  const validatePrimitiveType = (schemaName, key, value, format) => {
30
29
  if (typeof value !== format) {
31
30
  throwTypeError(schemaName, key, value, format);
32
31
  }
33
32
  };
34
-
35
33
  const validateString = (schemaName, key, value, format) => {
36
34
  if (value !== format.slice(1, -1)) {
37
35
  throwTypeError(schemaName, key, value, format);
38
36
  }
39
37
  };
40
-
41
38
  const validateArray = (schemaName, key, value, format, validationsMemo, nextValidationsMemo) => {
42
- // Check that we have an array
43
39
  if (!Array.isArray(value)) {
44
40
  throwTypeError(schemaName, key, value, format);
45
- } // Check that each element inside satisfies the format
46
-
47
-
41
+ }
48
42
  value.forEach((val, index) => {
49
- // this is a recursive func, we need to invoke it before it's defined.
50
- // eslint-disable-next-line @typescript-eslint/no-use-before-define
51
- validateValueWithFormat(schemaName, "".concat(key, "[").concat(index, "]"), val, format.slice(0, -2), validationsMemo, nextValidationsMemo);
43
+ validateValueWithFormat(schemaName, `${key}[${index}]`, val, format.slice(0, -2), validationsMemo, nextValidationsMemo);
52
44
  });
53
45
  };
54
-
55
46
  function isObjectType(value) {
56
- return !(typeof value !== 'object' || Array.isArray(value));
47
+ return !(typeof value !== "object" || Array.isArray(value));
57
48
  }
58
-
59
49
  const validateObject = (schemaName, key, value, format, validationsMemo, nextValidationsMemo) => {
60
- const valuesIsObject = isObjectType(value); // Check that we have an object
61
-
50
+ const valuesIsObject = isObjectType(value);
62
51
  if (!valuesIsObject) {
63
52
  throwTypeError(schemaName, key, value, format);
64
53
  return;
65
54
  }
66
-
67
- if (format === 'object') return;
68
- const keyValuePairs = typescriptObjectParser(format); // Now we have the key - value pairs
69
- // Each key could either be required or not
70
- // Just recursively check the object
71
-
72
- keyValuePairs.forEach(_ref => {
73
- let [objectKey, objectValue] = _ref;
74
- const trueKey = objectKey.slice(-1) === '?' ? objectKey.slice(0, -1) : objectKey;
75
-
55
+ if (format === "object")
56
+ return;
57
+ const keyValuePairs = typescriptObjectParser(format);
58
+ keyValuePairs.forEach(([objectKey, objectValue]) => {
59
+ const trueKey = objectKey.slice(-1) === "?" ? objectKey.slice(0, -1) : objectKey;
76
60
  if (trueKey === objectKey && !(trueKey in value)) {
77
61
  throwRequiredError(schemaName, key);
78
62
  }
79
-
80
63
  if (trueKey in value) {
81
- // this is a recursive func, we need to invoke it before it's defined.
82
- // eslint-disable-next-line @typescript-eslint/no-use-before-define
83
- validateValueWithFormat(schemaName, "".concat(key, "[").concat(trueKey, "]"), value[trueKey], objectValue, validationsMemo, nextValidationsMemo);
64
+ validateValueWithFormat(schemaName, `${key}[${trueKey}]`, value[trueKey], objectValue, validationsMemo, nextValidationsMemo);
84
65
  }
85
66
  });
86
67
  };
87
-
88
68
  const validateUnion = (schemaName, key, value, format, validationsMemo, nextValidationsMemo) => {
89
69
  const possibilities = format.split(/\s?\|\s?/);
90
70
  const errors = [];
91
- possibilities.forEach(possibility => {
71
+ possibilities.forEach((possibility) => {
92
72
  try {
93
- // this is a recursive func, we need to invoke it before it's defined.
94
- // eslint-disable-next-line @typescript-eslint/no-use-before-define
95
73
  validateValueWithFormat(schemaName, key, value, possibility, validationsMemo, nextValidationsMemo);
96
74
  } catch (e) {
97
75
  errors.push(e);
98
76
  }
99
77
  });
100
-
101
78
  if (errors.length === possibilities.length) {
102
79
  throwTypeError(schemaName, key, value, format);
103
80
  }
104
81
  };
105
-
106
82
  const validateFunction = (schemaName, key, value, format) => {
107
- // Check that we have a function
108
- if (typeof value !== 'function') {
83
+ if (typeof value !== "function") {
109
84
  throwTypeError(schemaName, key, value, format);
110
85
  }
111
86
  };
112
-
113
87
  function isJSXElement(value) {
114
- return value === null || typeof value === 'object' && value !== null && '$$typeof' in value;
88
+ return value === null || typeof value === "object" && value !== null && "$$typeof" in value;
115
89
  }
116
-
117
90
  const validateJSXorNode = (schemaName, key, value, format) => {
118
91
  const valueIsJSX = isJSXElement(value);
119
-
120
- if (format === 'JSX.Element' && !valueIsJSX) {
92
+ if (format === "JSX.Element" && !valueIsJSX) {
121
93
  throwTypeError(schemaName, key, value, format);
122
94
  }
123
- }; // =============================================================================
124
- // Schema validator
125
- // =============================================================================
126
-
127
-
95
+ };
128
96
  const validateValueWithFormat = (schemaName, key, value, format, validationsMemo, nextValidationsMemo) => {
129
97
  nextValidationsMemo[value] = format;
130
-
131
98
  if (value in validationsMemo) {
132
- // We already validated this value on this format
133
99
  return;
134
100
  }
135
-
136
101
  if (isUndefined(format)) {
137
- validateUndefined(schemaName, key, value, format);
102
+ validateUndefined(schemaName, key, value, format, validationsMemo, nextValidationsMemo);
138
103
  } else if (isNull(format)) {
139
- validateNull(schemaName, key, value, format);
104
+ validateNull(schemaName, key, value, format, validationsMemo, nextValidationsMemo);
140
105
  } else if (isPrimitiveType(format)) {
141
- validatePrimitiveType(schemaName, key, value, format);
106
+ validatePrimitiveType(schemaName, key, value, format, validationsMemo, nextValidationsMemo);
142
107
  } else if (isUnion(format)) {
143
108
  validateUnion(schemaName, key, value, format, validationsMemo, nextValidationsMemo);
144
109
  } else if (isString(format)) {
145
- validateString(schemaName, key, value, format);
110
+ validateString(schemaName, key, value, format, validationsMemo, nextValidationsMemo);
146
111
  } else if (isArray(format)) {
147
112
  validateArray(schemaName, key, value, format, validationsMemo, nextValidationsMemo);
148
113
  } else if (isObject(format)) {
149
114
  validateObject(schemaName, key, value, format, validationsMemo, nextValidationsMemo);
150
115
  } else if (isFunction(format)) {
151
- validateFunction(schemaName, key, value, format);
116
+ validateFunction(schemaName, key, value, format, validationsMemo, nextValidationsMemo);
152
117
  } else if (isJSXorNode(format)) {
153
- validateJSXorNode(schemaName, key, value, format);
118
+ validateJSXorNode(schemaName, key, value, format, validationsMemo, nextValidationsMemo);
154
119
  } else if (isSomethingWithParenthesis(format)) {
155
120
  validateValueWithFormat(schemaName, key, value, format.slice(1, -1), validationsMemo, nextValidationsMemo);
156
121
  }
157
122
  };
158
-
159
- const validateTypescriptPropTypesImplementation = function (props, schema) {
160
- let validationsMemo = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
161
- let nextValidationsMemo = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
162
- const {
163
- properties,
164
- name: schemaName
165
- } = schema;
166
- properties.forEach(property => {
167
- const {
168
- name,
169
- format,
170
- required
171
- } = property;
172
-
123
+ const validateTypescriptPropTypesImplementation = (props, schema, validationsMemo = {}, nextValidationsMemo = {}) => {
124
+ const { properties, name: schemaName } = schema;
125
+ properties.forEach((property) => {
126
+ const { name, format, required } = property;
173
127
  if (required && !(name in props)) {
174
128
  throwRequiredError(schema.name, name);
175
129
  }
176
-
177
- if (name in props && (props[name] !== undefined || required)) {
130
+ if (name in props && (props[name] !== void 0 || required)) {
178
131
  validateValueWithFormat(schemaName, name, props[name], format, validationsMemo, nextValidationsMemo);
179
132
  }
180
133
  });
181
- }; // eslint-disable-next-line @typescript-eslint/no-explicit-any
182
-
134
+ };
183
135
  const useValidateTypescriptPropTypes = (props, propTypes) => {
184
- const [validationsMemo, setValidationsMemo] = useState({}); // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
185
-
136
+ const [validationsMemo, setValidationsMemo] = useState({});
186
137
  const ComponentWithSchema = useMemo(() => {
187
- const Component = () => {}; // eslint-disable-next-line @typescript-eslint/no-unsafe-return, @typescript-eslint/no-unsafe-call
188
-
189
-
138
+ const Component = () => {
139
+ };
190
140
  return describe(Component);
191
- }, []); // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-assignment
192
-
141
+ }, []);
193
142
  ComponentWithSchema.propTypes = propTypes;
194
143
  useMemo(() => {
195
144
  const nextValidationsMemo = {};
196
- validateTypescriptPropTypesImplementation(props, // eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
197
- ComponentWithSchema.toTypescript(), validationsMemo, nextValidationsMemo);
198
- setValidationsMemo(nextValidationsMemo); // eslint-disable-next-line react-hooks/exhaustive-deps
145
+ validateTypescriptPropTypesImplementation(props, ComponentWithSchema.toTypescript(), validationsMemo, nextValidationsMemo);
146
+ setValidationsMemo(nextValidationsMemo);
199
147
  }, [props]);
200
148
  };
201
-
202
- export { useValidateTypescriptPropTypes, validateTypescriptPropTypesImplementation };
149
+ export {
150
+ useValidateTypescriptPropTypes,
151
+ validateTypescriptPropTypesImplementation
152
+ };
153
+ //# sourceMappingURL=typescriptValidator.js.map