@elliemae/ds-props-helpers 1.53.4-rc.2 → 1.53.4

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.
@@ -5,7 +5,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
  var defaultProps_useMemoMergePropsWithDefault = require('./useMemoMergePropsWithDefault.js');
6
6
  require('@babel/runtime/helpers/defineProperty');
7
7
  require('react');
8
- require('dequal');
8
+ require('fast-deep-equal/react');
9
9
 
10
10
 
11
11
 
@@ -4,11 +4,12 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var _defineProperty = require('@babel/runtime/helpers/defineProperty');
6
6
  var react = require('react');
7
- var dequal = require('dequal');
7
+ var deepequal = require('fast-deep-equal/react');
8
8
 
9
9
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
10
10
 
11
11
  var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
12
+ var deepequal__default = /*#__PURE__*/_interopDefaultLegacy(deepequal);
12
13
 
13
14
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
14
15
 
@@ -36,9 +37,11 @@ var useMemoCompare = function useMemoCompare(next, compare) {
36
37
 
37
38
 
38
39
  var useMemoMergePropsWithDefault = function useMemoMergePropsWithDefault(props, defaultProps) {
40
+ var compare = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : deepequal__default['default'];
41
+
39
42
  var mergedProps = _objectSpread(_objectSpread({}, defaultProps), props);
40
43
 
41
- return useMemoCompare(mergedProps, dequal.dequal);
44
+ return useMemoCompare(mergedProps, compare);
42
45
  };
43
46
 
44
47
  exports.useMemoMergePropsWithDefault = useMemoMergePropsWithDefault;
@@ -1 +1 @@
1
- {"version":3,"file":"useMemoMergePropsWithDefault.js","sources":["../../../src/defaultProps/useMemoMergePropsWithDefault.ts"],"sourcesContent":["import { useEffect, useRef } from 'react';\nimport { dequal } from 'dequal';\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<T>();\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 useEffect(() => {\n if (!isEqual) {\n previousRef.current = next;\n }\n });\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<any, any>>(\n props: Partial<T>,\n defaultProps: Partial<T>,\n): Partial<T> => {\n const mergedProps = { ...defaultProps, ...props };\n\n return useMemoCompare<Partial<T>>(mergedProps, dequal);\n};\n"],"names":["useMemoCompare","next","compare","previousRef","useRef","previous","current","isEqual","useEffect","useMemoMergePropsWithDefault","props","defaultProps","mergedProps","dequal"],"mappings":";;;;;;;;;;;;;;;AAIA;;AACA,IAAMA,cAAc,GAAG,SAAjBA,cAAiB,CAAUC,IAAV,EAAmBC,OAAnB,EAAmF;AACxG;AACA,MAAMC,WAAW,GAAGC,YAAM,EAA1B;AACA,MAAMC,QAAQ,GAAGF,WAAW,CAACG,OAA7B,CAHwG;AAKxG;;AACA,MAAMC,OAAO,GAAGL,OAAO,CAACG,QAAD,EAAWJ,IAAX,CAAvB,CANwG;AAQxG;AACA;;AACAO,EAAAA,eAAS,CAAC,YAAM;AACd,QAAI,CAACD,OAAL,EAAc;AACZJ,MAAAA,WAAW,CAACG,OAAZ,GAAsBL,IAAtB;AACD;AACF,GAJQ,CAAT,CAVwG;;AAgBxG,SAAOM,OAAO,GAAGF,QAAH,GAAcJ,IAA5B;AACD,CAjBD;;;IAoBaQ,4BAA4B,GAAG,SAA/BA,4BAA+B,CAC1CC,KAD0C,EAE1CC,YAF0C,EAG3B;AACf,MAAMC,WAAW,mCAAQD,YAAR,GAAyBD,KAAzB,CAAjB;;AAEA,SAAOV,cAAc,CAAaY,WAAb,EAA0BC,aAA1B,CAArB;AACD;;;;"}
1
+ {"version":3,"file":"useMemoMergePropsWithDefault.js","sources":["../../../src/defaultProps/useMemoMergePropsWithDefault.ts"],"sourcesContent":["import { useEffect, 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<T>();\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 useEffect(() => {\n if (!isEqual) {\n previousRef.current = next;\n }\n });\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<any, any>>(\n props: Partial<T>,\n defaultProps: Partial<T>,\n compare = deepequal,\n): Partial<T> => {\n const mergedProps = { ...defaultProps, ...props };\n\n return useMemoCompare<Partial<T>>(mergedProps, compare);\n};\n"],"names":["useMemoCompare","next","compare","previousRef","useRef","previous","current","isEqual","useEffect","useMemoMergePropsWithDefault","props","defaultProps","deepequal","mergedProps"],"mappings":";;;;;;;;;;;;;;;;AAIA;;AACA,IAAMA,cAAc,GAAG,SAAjBA,cAAiB,CAAUC,IAAV,EAAmBC,OAAnB,EAAmF;AACxG;AACA,MAAMC,WAAW,GAAGC,YAAM,EAA1B;AACA,MAAMC,QAAQ,GAAGF,WAAW,CAACG,OAA7B,CAHwG;AAKxG;;AACA,MAAMC,OAAO,GAAGL,OAAO,CAACG,QAAD,EAAWJ,IAAX,CAAvB,CANwG;AAQxG;AACA;;AACAO,EAAAA,eAAS,CAAC,YAAM;AACd,QAAI,CAACD,OAAL,EAAc;AACZJ,MAAAA,WAAW,CAACG,OAAZ,GAAsBL,IAAtB;AACD;AACF,GAJQ,CAAT,CAVwG;;AAgBxG,SAAOM,OAAO,GAAGF,QAAH,GAAcJ,IAA5B;AACD,CAjBD;;;IAoBaQ,4BAA4B,GAAG,SAA/BA,4BAA+B,CAC1CC,KAD0C,EAE1CC,YAF0C,EAI3B;AAAA,MADfT,OACe,uEADLU,6BACK;;AACf,MAAMC,WAAW,mCAAQF,YAAR,GAAyBD,KAAzB,CAAjB;;AAEA,SAAOV,cAAc,CAAaa,WAAb,EAA0BX,OAA1B,CAArB;AACD;;;;"}
package/cjs/index.js CHANGED
@@ -7,7 +7,7 @@ var validation_validator = require('./validation/validator.js');
7
7
  var validation_errorTemplates = require('./validation/errorTemplates.js');
8
8
  require('@babel/runtime/helpers/defineProperty');
9
9
  require('react');
10
- require('dequal');
10
+ require('fast-deep-equal/react');
11
11
  require('@babel/runtime/helpers/typeof');
12
12
 
13
13
 
@@ -11,13 +11,27 @@ var _typeof__default = /*#__PURE__*/_interopDefaultLegacy(_typeof);
11
11
 
12
12
  var useValidatePropTypes = function useValidatePropTypes(props, schema) {
13
13
  schema.properties.forEach(function (property) {
14
+ var propertyName = property.name;
15
+ var currentProp = props[propertyName];
16
+
17
+ var currentPropTypeOf = _typeof__default['default'](currentProp); // eslint-disable-next-line max-len
18
+
19
+
20
+ var currentFormat = property.format; // this is csv representing types e.g.: "string"/"string,number"/"[object],string"
21
+
22
+ var isValidReactElement = false; // this depends on react desc definition
23
+
14
24
  if (property.required && !Object.prototype.hasOwnProperty.call(props, property.name)) {
15
25
  validation_errorTemplates.throwRequiredError(schema.name, property.name);
16
26
  }
17
27
 
18
- if (typeof props[property.name] !== 'undefined' && props[property.name] !== null) {
19
- if (!property.format.includes(_typeof__default['default'](props[property.name])) && !property.format.includes(props[property.name])) {
20
- validation_errorTemplates.throwTypeError(schema.name, property.name, props[property.name], property.format);
28
+ if (currentPropTypeOf !== 'undefined' && currentProp !== null) {
29
+ if (currentPropTypeOf === 'object' && Object.prototype.hasOwnProperty.call(currentProp, '$$typeof') && (currentFormat.includes('node') || currentFormat.includes('element'))) {
30
+ isValidReactElement = true;
31
+ }
32
+
33
+ if (!currentFormat.includes(currentPropTypeOf) && !currentFormat.includes(currentProp) && !isValidReactElement) {
34
+ validation_errorTemplates.throwTypeError(schema.name, propertyName, currentProp, currentFormat);
21
35
  }
22
36
  }
23
37
  });
@@ -1 +1 @@
1
- {"version":3,"file":"validator.js","sources":["../../../src/validation/validator.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/explicit-module-boundary-types */\nimport { throwRequiredError, throwTypeError } from './errorTemplates';\n\nexport const useValidatePropTypes = (props: Record<string, unknown>, schema): void => {\n schema.properties.forEach((property) => {\n if (property.required && !Object.prototype.hasOwnProperty.call(props, property.name)) {\n throwRequiredError(schema.name, property.name);\n }\n if (typeof props[property.name] !== 'undefined' && props[property.name] !== null) {\n if (!property.format.includes(typeof props[property.name]) && !property.format.includes(props[property.name])) {\n throwTypeError(schema.name, property.name, props[property.name], property.format);\n }\n }\n });\n};\n"],"names":["useValidatePropTypes","props","schema","properties","forEach","property","required","Object","prototype","hasOwnProperty","call","name","throwRequiredError","format","includes","throwTypeError"],"mappings":";;;;;;;;;;;IAGaA,oBAAoB,GAAG,SAAvBA,oBAAuB,CAACC,KAAD,EAAiCC,MAAjC,EAAkD;AACpFA,EAAAA,MAAM,CAACC,UAAP,CAAkBC,OAAlB,CAA0B,UAACC,QAAD,EAAc;AACtC,QAAIA,QAAQ,CAACC,QAAT,IAAqB,CAACC,MAAM,CAACC,SAAP,CAAiBC,cAAjB,CAAgCC,IAAhC,CAAqCT,KAArC,EAA4CI,QAAQ,CAACM,IAArD,CAA1B,EAAsF;AACpFC,MAAAA,4CAAkB,CAACV,MAAM,CAACS,IAAR,EAAcN,QAAQ,CAACM,IAAvB,CAAlB;AACD;;AACD,QAAI,OAAOV,KAAK,CAACI,QAAQ,CAACM,IAAV,CAAZ,KAAgC,WAAhC,IAA+CV,KAAK,CAACI,QAAQ,CAACM,IAAV,CAAL,KAAyB,IAA5E,EAAkF;AAChF,UAAI,CAACN,QAAQ,CAACQ,MAAT,CAAgBC,QAAhB,6BAAgCb,KAAK,CAACI,QAAQ,CAACM,IAAV,CAArC,EAAD,IAA0D,CAACN,QAAQ,CAACQ,MAAT,CAAgBC,QAAhB,CAAyBb,KAAK,CAACI,QAAQ,CAACM,IAAV,CAA9B,CAA/D,EAA+G;AAC7GI,QAAAA,wCAAc,CAACb,MAAM,CAACS,IAAR,EAAcN,QAAQ,CAACM,IAAvB,EAA6BV,KAAK,CAACI,QAAQ,CAACM,IAAV,CAAlC,EAAmDN,QAAQ,CAACQ,MAA5D,CAAd;AACD;AACF;AACF,GATD;AAUD;;;;"}
1
+ {"version":3,"file":"validator.js","sources":["../../../src/validation/validator.ts"],"sourcesContent":["/* eslint-disable complexity */\n/* eslint-disable @typescript-eslint/explicit-module-boundary-types */\nimport { throwRequiredError, throwTypeError } from './errorTemplates';\n\nexport const useValidatePropTypes = (props: Record<string, unknown>, schema): void => {\n schema.properties.forEach((property) => {\n const propertyName = property.name;\n const currentProp = props[propertyName];\n const currentPropTypeOf = typeof currentProp;\n // eslint-disable-next-line max-len\n const currentFormat = property.format; // this is csv representing types e.g.: \"string\"/\"string,number\"/\"[object],string\"\n let isValidReactElement = false;\n // this depends on react desc definition\n if (property.required && !Object.prototype.hasOwnProperty.call(props, property.name)) {\n throwRequiredError(schema.name, property.name);\n }\n if (currentPropTypeOf !== 'undefined' && currentProp !== null) {\n if (\n currentPropTypeOf === 'object' &&\n Object.prototype.hasOwnProperty.call(currentProp, '$$typeof') &&\n (currentFormat.includes('node') || currentFormat.includes('element'))\n ) {\n isValidReactElement = true;\n }\n\n if (!currentFormat.includes(currentPropTypeOf) && !currentFormat.includes(currentProp) && !isValidReactElement) {\n throwTypeError(schema.name, propertyName, currentProp, currentFormat);\n }\n }\n });\n};\n"],"names":["useValidatePropTypes","props","schema","properties","forEach","property","propertyName","name","currentProp","currentPropTypeOf","currentFormat","format","isValidReactElement","required","Object","prototype","hasOwnProperty","call","throwRequiredError","includes","throwTypeError"],"mappings":";;;;;;;;;;;IAIaA,oBAAoB,GAAG,SAAvBA,oBAAuB,CAACC,KAAD,EAAiCC,MAAjC,EAAkD;AACpFA,EAAAA,MAAM,CAACC,UAAP,CAAkBC,OAAlB,CAA0B,UAACC,QAAD,EAAc;AACtC,QAAMC,YAAY,GAAGD,QAAQ,CAACE,IAA9B;AACA,QAAMC,WAAW,GAAGP,KAAK,CAACK,YAAD,CAAzB;;AACA,QAAMG,iBAAiB,+BAAUD,WAAV,CAAvB,CAHsC;;;AAKtC,QAAME,aAAa,GAAGL,QAAQ,CAACM,MAA/B,CALsC;;AAMtC,QAAIC,mBAAmB,GAAG,KAA1B,CANsC;;AAQtC,QAAIP,QAAQ,CAACQ,QAAT,IAAqB,CAACC,MAAM,CAACC,SAAP,CAAiBC,cAAjB,CAAgCC,IAAhC,CAAqChB,KAArC,EAA4CI,QAAQ,CAACE,IAArD,CAA1B,EAAsF;AACpFW,MAAAA,4CAAkB,CAAChB,MAAM,CAACK,IAAR,EAAcF,QAAQ,CAACE,IAAvB,CAAlB;AACD;;AACD,QAAIE,iBAAiB,KAAK,WAAtB,IAAqCD,WAAW,KAAK,IAAzD,EAA+D;AAC7D,UACEC,iBAAiB,KAAK,QAAtB,IACAK,MAAM,CAACC,SAAP,CAAiBC,cAAjB,CAAgCC,IAAhC,CAAqCT,WAArC,EAAkD,UAAlD,CADA,KAECE,aAAa,CAACS,QAAd,CAAuB,MAAvB,KAAkCT,aAAa,CAACS,QAAd,CAAuB,SAAvB,CAFnC,CADF,EAIE;AACAP,QAAAA,mBAAmB,GAAG,IAAtB;AACD;;AAED,UAAI,CAACF,aAAa,CAACS,QAAd,CAAuBV,iBAAvB,CAAD,IAA8C,CAACC,aAAa,CAACS,QAAd,CAAuBX,WAAvB,CAA/C,IAAsF,CAACI,mBAA3F,EAAgH;AAC9GQ,QAAAA,wCAAc,CAAClB,MAAM,CAACK,IAAR,EAAcD,YAAd,EAA4BE,WAA5B,EAAyCE,aAAzC,CAAd;AACD;AACF;AACF,GAxBD;AAyBD;;;;"}
@@ -1,5 +1,5 @@
1
1
  export { useMemoMergePropsWithDefault } from './useMemoMergePropsWithDefault.js';
2
2
  import '@babel/runtime/helpers/esm/defineProperty';
3
3
  import 'react';
4
- import 'dequal';
4
+ import 'fast-deep-equal/react';
5
5
  //# sourceMappingURL=index.js.map
@@ -1,6 +1,6 @@
1
1
  import _defineProperty from '@babel/runtime/helpers/esm/defineProperty';
2
2
  import { useRef, useEffect } from 'react';
3
- import { dequal } from 'dequal';
3
+ import deepequal from 'fast-deep-equal/react';
4
4
 
5
5
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
6
6
 
@@ -28,9 +28,11 @@ var useMemoCompare = function useMemoCompare(next, compare) {
28
28
 
29
29
 
30
30
  var useMemoMergePropsWithDefault = function useMemoMergePropsWithDefault(props, defaultProps) {
31
+ var compare = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : deepequal;
32
+
31
33
  var mergedProps = _objectSpread(_objectSpread({}, defaultProps), props);
32
34
 
33
- return useMemoCompare(mergedProps, dequal);
35
+ return useMemoCompare(mergedProps, compare);
34
36
  };
35
37
 
36
38
  export { useMemoMergePropsWithDefault };
@@ -1 +1 @@
1
- {"version":3,"file":"useMemoMergePropsWithDefault.js","sources":["../../../src/defaultProps/useMemoMergePropsWithDefault.ts"],"sourcesContent":["import { useEffect, useRef } from 'react';\nimport { dequal } from 'dequal';\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<T>();\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 useEffect(() => {\n if (!isEqual) {\n previousRef.current = next;\n }\n });\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<any, any>>(\n props: Partial<T>,\n defaultProps: Partial<T>,\n): Partial<T> => {\n const mergedProps = { ...defaultProps, ...props };\n\n return useMemoCompare<Partial<T>>(mergedProps, dequal);\n};\n"],"names":["useMemoCompare","next","compare","previousRef","useRef","previous","current","isEqual","useEffect","useMemoMergePropsWithDefault","props","defaultProps","mergedProps","dequal"],"mappings":";;;;;;;AAIA;;AACA,IAAMA,cAAc,GAAG,SAAjBA,cAAiB,CAAUC,IAAV,EAAmBC,OAAnB,EAAmF;AACxG;AACA,MAAMC,WAAW,GAAGC,MAAM,EAA1B;AACA,MAAMC,QAAQ,GAAGF,WAAW,CAACG,OAA7B,CAHwG;AAKxG;;AACA,MAAMC,OAAO,GAAGL,OAAO,CAACG,QAAD,EAAWJ,IAAX,CAAvB,CANwG;AAQxG;AACA;;AACAO,EAAAA,SAAS,CAAC,YAAM;AACd,QAAI,CAACD,OAAL,EAAc;AACZJ,MAAAA,WAAW,CAACG,OAAZ,GAAsBL,IAAtB;AACD;AACF,GAJQ,CAAT,CAVwG;;AAgBxG,SAAOM,OAAO,GAAGF,QAAH,GAAcJ,IAA5B;AACD,CAjBD;;;IAoBaQ,4BAA4B,GAAG,SAA/BA,4BAA+B,CAC1CC,KAD0C,EAE1CC,YAF0C,EAG3B;AACf,MAAMC,WAAW,mCAAQD,YAAR,GAAyBD,KAAzB,CAAjB;;AAEA,SAAOV,cAAc,CAAaY,WAAb,EAA0BC,MAA1B,CAArB;AACD;;;;"}
1
+ {"version":3,"file":"useMemoMergePropsWithDefault.js","sources":["../../../src/defaultProps/useMemoMergePropsWithDefault.ts"],"sourcesContent":["import { useEffect, 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<T>();\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 useEffect(() => {\n if (!isEqual) {\n previousRef.current = next;\n }\n });\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<any, any>>(\n props: Partial<T>,\n defaultProps: Partial<T>,\n compare = deepequal,\n): Partial<T> => {\n const mergedProps = { ...defaultProps, ...props };\n\n return useMemoCompare<Partial<T>>(mergedProps, compare);\n};\n"],"names":["useMemoCompare","next","compare","previousRef","useRef","previous","current","isEqual","useEffect","useMemoMergePropsWithDefault","props","defaultProps","deepequal","mergedProps"],"mappings":";;;;;;;AAIA;;AACA,IAAMA,cAAc,GAAG,SAAjBA,cAAiB,CAAUC,IAAV,EAAmBC,OAAnB,EAAmF;AACxG;AACA,MAAMC,WAAW,GAAGC,MAAM,EAA1B;AACA,MAAMC,QAAQ,GAAGF,WAAW,CAACG,OAA7B,CAHwG;AAKxG;;AACA,MAAMC,OAAO,GAAGL,OAAO,CAACG,QAAD,EAAWJ,IAAX,CAAvB,CANwG;AAQxG;AACA;;AACAO,EAAAA,SAAS,CAAC,YAAM;AACd,QAAI,CAACD,OAAL,EAAc;AACZJ,MAAAA,WAAW,CAACG,OAAZ,GAAsBL,IAAtB;AACD;AACF,GAJQ,CAAT,CAVwG;;AAgBxG,SAAOM,OAAO,GAAGF,QAAH,GAAcJ,IAA5B;AACD,CAjBD;;;IAoBaQ,4BAA4B,GAAG,SAA/BA,4BAA+B,CAC1CC,KAD0C,EAE1CC,YAF0C,EAI3B;AAAA,MADfT,OACe,uEADLU,SACK;;AACf,MAAMC,WAAW,mCAAQF,YAAR,GAAyBD,KAAzB,CAAjB;;AAEA,SAAOV,cAAc,CAAaa,WAAb,EAA0BX,OAA1B,CAArB;AACD;;;;"}
package/esm/index.js CHANGED
@@ -3,6 +3,6 @@ export { useValidatePropTypes } from './validation/validator.js';
3
3
  export { throwRequiredError, throwTypeError } from './validation/errorTemplates.js';
4
4
  import '@babel/runtime/helpers/esm/defineProperty';
5
5
  import 'react';
6
- import 'dequal';
6
+ import 'fast-deep-equal/react';
7
7
  import '@babel/runtime/helpers/esm/typeof';
8
8
  //# sourceMappingURL=index.js.map
@@ -3,13 +3,27 @@ import { throwRequiredError, throwTypeError } from './errorTemplates.js';
3
3
 
4
4
  var useValidatePropTypes = function useValidatePropTypes(props, schema) {
5
5
  schema.properties.forEach(function (property) {
6
+ var propertyName = property.name;
7
+ var currentProp = props[propertyName];
8
+
9
+ var currentPropTypeOf = _typeof(currentProp); // eslint-disable-next-line max-len
10
+
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
15
+
6
16
  if (property.required && !Object.prototype.hasOwnProperty.call(props, property.name)) {
7
17
  throwRequiredError(schema.name, property.name);
8
18
  }
9
19
 
10
- if (typeof props[property.name] !== 'undefined' && props[property.name] !== null) {
11
- if (!property.format.includes(_typeof(props[property.name])) && !property.format.includes(props[property.name])) {
12
- throwTypeError(schema.name, property.name, props[property.name], property.format);
20
+ if (currentPropTypeOf !== 'undefined' && currentProp !== null) {
21
+ if (currentPropTypeOf === 'object' && Object.prototype.hasOwnProperty.call(currentProp, '$$typeof') && (currentFormat.includes('node') || currentFormat.includes('element'))) {
22
+ isValidReactElement = true;
23
+ }
24
+
25
+ if (!currentFormat.includes(currentPropTypeOf) && !currentFormat.includes(currentProp) && !isValidReactElement) {
26
+ throwTypeError(schema.name, propertyName, currentProp, currentFormat);
13
27
  }
14
28
  }
15
29
  });
@@ -1 +1 @@
1
- {"version":3,"file":"validator.js","sources":["../../../src/validation/validator.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/explicit-module-boundary-types */\nimport { throwRequiredError, throwTypeError } from './errorTemplates';\n\nexport const useValidatePropTypes = (props: Record<string, unknown>, schema): void => {\n schema.properties.forEach((property) => {\n if (property.required && !Object.prototype.hasOwnProperty.call(props, property.name)) {\n throwRequiredError(schema.name, property.name);\n }\n if (typeof props[property.name] !== 'undefined' && props[property.name] !== null) {\n if (!property.format.includes(typeof props[property.name]) && !property.format.includes(props[property.name])) {\n throwTypeError(schema.name, property.name, props[property.name], property.format);\n }\n }\n });\n};\n"],"names":["useValidatePropTypes","props","schema","properties","forEach","property","required","Object","prototype","hasOwnProperty","call","name","throwRequiredError","format","includes","throwTypeError"],"mappings":";;;IAGaA,oBAAoB,GAAG,SAAvBA,oBAAuB,CAACC,KAAD,EAAiCC,MAAjC,EAAkD;AACpFA,EAAAA,MAAM,CAACC,UAAP,CAAkBC,OAAlB,CAA0B,UAACC,QAAD,EAAc;AACtC,QAAIA,QAAQ,CAACC,QAAT,IAAqB,CAACC,MAAM,CAACC,SAAP,CAAiBC,cAAjB,CAAgCC,IAAhC,CAAqCT,KAArC,EAA4CI,QAAQ,CAACM,IAArD,CAA1B,EAAsF;AACpFC,MAAAA,kBAAkB,CAACV,MAAM,CAACS,IAAR,EAAcN,QAAQ,CAACM,IAAvB,CAAlB;AACD;;AACD,QAAI,OAAOV,KAAK,CAACI,QAAQ,CAACM,IAAV,CAAZ,KAAgC,WAAhC,IAA+CV,KAAK,CAACI,QAAQ,CAACM,IAAV,CAAL,KAAyB,IAA5E,EAAkF;AAChF,UAAI,CAACN,QAAQ,CAACQ,MAAT,CAAgBC,QAAhB,SAAgCb,KAAK,CAACI,QAAQ,CAACM,IAAV,CAArC,EAAD,IAA0D,CAACN,QAAQ,CAACQ,MAAT,CAAgBC,QAAhB,CAAyBb,KAAK,CAACI,QAAQ,CAACM,IAAV,CAA9B,CAA/D,EAA+G;AAC7GI,QAAAA,cAAc,CAACb,MAAM,CAACS,IAAR,EAAcN,QAAQ,CAACM,IAAvB,EAA6BV,KAAK,CAACI,QAAQ,CAACM,IAAV,CAAlC,EAAmDN,QAAQ,CAACQ,MAA5D,CAAd;AACD;AACF;AACF,GATD;AAUD;;;;"}
1
+ {"version":3,"file":"validator.js","sources":["../../../src/validation/validator.ts"],"sourcesContent":["/* eslint-disable complexity */\n/* eslint-disable @typescript-eslint/explicit-module-boundary-types */\nimport { throwRequiredError, throwTypeError } from './errorTemplates';\n\nexport const useValidatePropTypes = (props: Record<string, unknown>, schema): void => {\n schema.properties.forEach((property) => {\n const propertyName = property.name;\n const currentProp = props[propertyName];\n const currentPropTypeOf = typeof currentProp;\n // eslint-disable-next-line max-len\n const currentFormat = property.format; // this is csv representing types e.g.: \"string\"/\"string,number\"/\"[object],string\"\n let isValidReactElement = false;\n // this depends on react desc definition\n if (property.required && !Object.prototype.hasOwnProperty.call(props, property.name)) {\n throwRequiredError(schema.name, property.name);\n }\n if (currentPropTypeOf !== 'undefined' && currentProp !== null) {\n if (\n currentPropTypeOf === 'object' &&\n Object.prototype.hasOwnProperty.call(currentProp, '$$typeof') &&\n (currentFormat.includes('node') || currentFormat.includes('element'))\n ) {\n isValidReactElement = true;\n }\n\n if (!currentFormat.includes(currentPropTypeOf) && !currentFormat.includes(currentProp) && !isValidReactElement) {\n throwTypeError(schema.name, propertyName, currentProp, currentFormat);\n }\n }\n });\n};\n"],"names":["useValidatePropTypes","props","schema","properties","forEach","property","propertyName","name","currentProp","currentPropTypeOf","currentFormat","format","isValidReactElement","required","Object","prototype","hasOwnProperty","call","throwRequiredError","includes","throwTypeError"],"mappings":";;;IAIaA,oBAAoB,GAAG,SAAvBA,oBAAuB,CAACC,KAAD,EAAiCC,MAAjC,EAAkD;AACpFA,EAAAA,MAAM,CAACC,UAAP,CAAkBC,OAAlB,CAA0B,UAACC,QAAD,EAAc;AACtC,QAAMC,YAAY,GAAGD,QAAQ,CAACE,IAA9B;AACA,QAAMC,WAAW,GAAGP,KAAK,CAACK,YAAD,CAAzB;;AACA,QAAMG,iBAAiB,WAAUD,WAAV,CAAvB,CAHsC;;;AAKtC,QAAME,aAAa,GAAGL,QAAQ,CAACM,MAA/B,CALsC;;AAMtC,QAAIC,mBAAmB,GAAG,KAA1B,CANsC;;AAQtC,QAAIP,QAAQ,CAACQ,QAAT,IAAqB,CAACC,MAAM,CAACC,SAAP,CAAiBC,cAAjB,CAAgCC,IAAhC,CAAqChB,KAArC,EAA4CI,QAAQ,CAACE,IAArD,CAA1B,EAAsF;AACpFW,MAAAA,kBAAkB,CAAChB,MAAM,CAACK,IAAR,EAAcF,QAAQ,CAACE,IAAvB,CAAlB;AACD;;AACD,QAAIE,iBAAiB,KAAK,WAAtB,IAAqCD,WAAW,KAAK,IAAzD,EAA+D;AAC7D,UACEC,iBAAiB,KAAK,QAAtB,IACAK,MAAM,CAACC,SAAP,CAAiBC,cAAjB,CAAgCC,IAAhC,CAAqCT,WAArC,EAAkD,UAAlD,CADA,KAECE,aAAa,CAACS,QAAd,CAAuB,MAAvB,KAAkCT,aAAa,CAACS,QAAd,CAAuB,SAAvB,CAFnC,CADF,EAIE;AACAP,QAAAA,mBAAmB,GAAG,IAAtB;AACD;;AAED,UAAI,CAACF,aAAa,CAACS,QAAd,CAAuBV,iBAAvB,CAAD,IAA8C,CAACC,aAAa,CAACS,QAAd,CAAuBX,WAAvB,CAA/C,IAAsF,CAACI,mBAA3F,EAAgH;AAC9GQ,QAAAA,cAAc,CAAClB,MAAM,CAACK,IAAR,EAAcD,YAAd,EAA4BE,WAA5B,EAAyCE,aAAzC,CAAd;AACD;AACF;AACF,GAxBD;AAyBD;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elliemae/ds-props-helpers",
3
- "version": "1.53.4-rc.2",
3
+ "version": "1.53.4",
4
4
  "license": "MIT",
5
5
  "description": "Ellie Mae - Dim Sum - Validation Helpers",
6
6
  "module": "esm/index.js",