yummies 7.10.0 → 7.12.0

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 (154) hide show
  1. package/async.cjs +162 -48
  2. package/async.cjs.map +1 -1
  3. package/async.d.ts +112 -13
  4. package/async.js +163 -54
  5. package/async.js.map +1 -1
  6. package/chunk-CVq3Gv4J.cjs +50 -0
  7. package/chunk-YKewjYmz.js +37 -0
  8. package/common.cjs +48 -8
  9. package/common.cjs.map +1 -1
  10. package/common.d.ts +35 -2
  11. package/common.js +49 -11
  12. package/common.js.map +1 -1
  13. package/complex.cjs +275 -104
  14. package/complex.cjs.map +1 -1
  15. package/complex.d.ts +133 -13
  16. package/complex.js +275 -109
  17. package/complex.js.map +1 -1
  18. package/cookie.cjs +17 -7
  19. package/cookie.cjs.map +1 -1
  20. package/cookie.d.ts +8 -0
  21. package/cookie.js +18 -9
  22. package/cookie.js.map +1 -1
  23. package/css.cjs +147 -39
  24. package/css.cjs.map +1 -1
  25. package/css.d.ts +98 -6
  26. package/css.js +143 -41
  27. package/css.js.map +1 -1
  28. package/data.cjs +90 -55
  29. package/data.cjs.map +1 -1
  30. package/data.d.ts +32 -0
  31. package/data.js +91 -61
  32. package/data.js.map +1 -1
  33. package/date-time.cjs +578 -412
  34. package/date-time.cjs.map +1 -1
  35. package/date-time.d.ts +88 -0
  36. package/date-time.js +575 -421
  37. package/date-time.js.map +1 -1
  38. package/device.cjs +48 -23
  39. package/device.cjs.map +1 -1
  40. package/device.d.ts +32 -0
  41. package/device.js +49 -31
  42. package/device.js.map +1 -1
  43. package/encodings.cjs +275 -266
  44. package/encodings.cjs.map +1 -1
  45. package/encodings.d.ts +8 -0
  46. package/encodings.js +276 -268
  47. package/encodings.js.map +1 -1
  48. package/errors.cjs +20 -18
  49. package/errors.cjs.map +1 -1
  50. package/errors.js +19 -19
  51. package/errors.js.map +1 -1
  52. package/file.cjs +42 -24
  53. package/file.cjs.map +1 -1
  54. package/file.d.ts +16 -0
  55. package/file.js +43 -27
  56. package/file.js.map +1 -1
  57. package/format.cjs +125 -83
  58. package/format.cjs.map +1 -1
  59. package/format.d.ts +89 -4
  60. package/format.js +118 -82
  61. package/format.js.map +1 -1
  62. package/html.cjs +226 -137
  63. package/html.cjs.map +1 -1
  64. package/html.d.ts +67 -3
  65. package/html.js +223 -150
  66. package/html.js.map +1 -1
  67. package/id.cjs +74 -17
  68. package/id.cjs.map +1 -1
  69. package/id.d.ts +10 -10
  70. package/id.js +73 -24
  71. package/id.js.map +1 -1
  72. package/imports.cjs +41 -29
  73. package/imports.cjs.map +1 -1
  74. package/imports.d.ts +13 -4
  75. package/imports.js +40 -31
  76. package/imports.js.map +1 -1
  77. package/math.cjs +32 -6
  78. package/math.cjs.map +1 -1
  79. package/math.d.ts +17 -1
  80. package/math.js +33 -10
  81. package/math.js.map +1 -1
  82. package/media.cjs +275 -84
  83. package/media.cjs.map +1 -1
  84. package/media.d.ts +188 -2
  85. package/media.js +274 -93
  86. package/media.js.map +1 -1
  87. package/mobx.cjs +353 -193
  88. package/mobx.cjs.map +1 -1
  89. package/mobx.d.ts +172 -6
  90. package/mobx.js +351 -200
  91. package/mobx.js.map +1 -1
  92. package/ms.cjs +21 -10
  93. package/ms.cjs.map +1 -1
  94. package/ms.d.ts +1 -1
  95. package/ms.js +22 -13
  96. package/ms.js.map +1 -1
  97. package/number.cjs +13 -7
  98. package/number.cjs.map +1 -1
  99. package/number.js +14 -9
  100. package/number.js.map +1 -1
  101. package/package.json +13 -5
  102. package/parser.cjs +117 -64
  103. package/parser.cjs.map +1 -1
  104. package/parser.d.ts +63 -0
  105. package/parser.js +111 -64
  106. package/parser.js.map +1 -1
  107. package/price.cjs +24 -18
  108. package/price.cjs.map +1 -1
  109. package/price.d.ts +8 -0
  110. package/price.js +25 -20
  111. package/price.js.map +1 -1
  112. package/random.cjs +79 -13
  113. package/random.cjs.map +1 -1
  114. package/random.d.ts +64 -0
  115. package/random.js +80 -22
  116. package/random.js.map +1 -1
  117. package/react.cjs +673 -214
  118. package/react.cjs.map +1 -1
  119. package/react.d.ts +428 -9
  120. package/react.js +674 -239
  121. package/react.js.map +1 -1
  122. package/sound.cjs +14 -9
  123. package/sound.cjs.map +1 -1
  124. package/sound.d.ts +1 -1
  125. package/sound.js +15 -11
  126. package/sound.js.map +1 -1
  127. package/storage.cjs +49 -50
  128. package/storage.cjs.map +1 -1
  129. package/storage.d.ts +15 -6
  130. package/storage.js +50 -53
  131. package/storage.js.map +1 -1
  132. package/text.cjs +51 -34
  133. package/text.cjs.map +1 -1
  134. package/text.d.ts +5 -5
  135. package/text.js +52 -37
  136. package/text.js.map +1 -1
  137. package/type-guard.cjs +292 -72
  138. package/type-guard.cjs.map +1 -1
  139. package/type-guard.d.ts +199 -42
  140. package/type-guard.js +288 -73
  141. package/type-guard.js.map +1 -1
  142. package/types.cjs +0 -2
  143. package/types.global.cjs +0 -2
  144. package/types.global.js +0 -2
  145. package/types.js +0 -2
  146. package/vibrate.cjs +31 -6
  147. package/vibrate.cjs.map +1 -1
  148. package/vibrate.d.ts +23 -1
  149. package/vibrate.js +32 -8
  150. package/vibrate.js.map +1 -1
  151. package/types.cjs.map +0 -1
  152. package/types.global.cjs.map +0 -1
  153. package/types.global.js.map +0 -1
  154. package/types.js.map +0 -1
package/data.cjs CHANGED
@@ -1,65 +1,100 @@
1
- "use strict";
2
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const isShallowEqual = (a, b) => {
4
- if (a === b) return true;
5
- if (typeof a !== "object" || typeof b !== "object" || a === null || b === null) {
6
- return false;
7
- }
8
- if (a.constructor !== b.constructor) return false;
9
- const isArrayA = Array.isArray(a);
10
- if (isArrayA !== Array.isArray(b)) return false;
11
- if (isArrayA) {
12
- const arrA = a;
13
- const arrB = b;
14
- if (arrA.length !== arrB.length) return false;
15
- for (const [i, element] of arrA.entries()) {
16
- if (element !== arrB[i]) return false;
17
- }
18
- return true;
19
- }
20
- if (a instanceof Date) return a.getTime() === b.getTime();
21
- if (a instanceof RegExp) return a.toString() === b.toString();
22
- const aKeys = Object.keys(a);
23
- const bKeys = Object.keys(b);
24
- if (aKeys.length !== bKeys.length) return false;
25
- const bObj = b;
26
- for (const key of aKeys) {
27
- if (!Object.hasOwn(bObj, key) || a[key] !== bObj[key]) {
28
- return false;
29
- }
30
- }
31
- return true;
2
+ //#region src/data.ts
3
+ /**
4
+ * Performs a shallow comparison for arrays, plain objects, dates and regular expressions.
5
+ *
6
+ * @example
7
+ * ```ts
8
+ * isShallowEqual({ id: 1 }, { id: 1 }); // true
9
+ * ```
10
+ */
11
+ var isShallowEqual = (a, b) => {
12
+ if (a === b) return true;
13
+ if (typeof a !== "object" || typeof b !== "object" || a === null || b === null) return false;
14
+ if (a.constructor !== b.constructor) return false;
15
+ const isArrayA = Array.isArray(a);
16
+ if (isArrayA !== Array.isArray(b)) return false;
17
+ if (isArrayA) {
18
+ const arrA = a;
19
+ const arrB = b;
20
+ if (arrA.length !== arrB.length) return false;
21
+ for (const [i, element] of arrA.entries()) if (element !== arrB[i]) return false;
22
+ return true;
23
+ }
24
+ if (a instanceof Date) return a.getTime() === b.getTime();
25
+ if (a instanceof RegExp) return a.toString() === b.toString();
26
+ const aKeys = Object.keys(a);
27
+ const bKeys = Object.keys(b);
28
+ if (aKeys.length !== bKeys.length) return false;
29
+ const bObj = b;
30
+ for (const key of aKeys) if (!Object.hasOwn(bObj, key) || a[key] !== bObj[key]) return false;
31
+ return true;
32
32
  };
33
- const toArray = (value) => {
34
- return Array.isArray(value) ? value : [value];
33
+ /**
34
+ * Wraps a value in an array when it is not already an array.
35
+ *
36
+ * @example
37
+ * ```ts
38
+ * toArray('item'); // ['item']
39
+ * ```
40
+ */
41
+ var toArray = (value) => {
42
+ return Array.isArray(value) ? value : [value];
35
43
  };
36
- const flatMapDeep = (arr, fn) => {
37
- const source = [];
38
- const collect = (value) => {
39
- if (!Array.isArray(value)) {
40
- source.push(value);
41
- return;
42
- }
43
- for (const item of value) {
44
- collect(item);
45
- }
46
- };
47
- collect(arr);
48
- return source.map((value, i) => fn(value, i, source));
44
+ /**
45
+ * Recursively flattens a nested array and maps the collected values.
46
+ *
47
+ * @example
48
+ * ```ts
49
+ * flatMapDeep([1, [2, [3]]], (value) => value * 2); // [2, 4, 6]
50
+ * ```
51
+ */
52
+ var flatMapDeep = (arr, fn) => {
53
+ const source = [];
54
+ const collect = (value) => {
55
+ if (!Array.isArray(value)) {
56
+ source.push(value);
57
+ return;
58
+ }
59
+ for (const item of value) collect(item);
60
+ };
61
+ collect(arr);
62
+ return source.map((value, i) => fn(value, i, source));
49
63
  };
50
- const safeJsonParse = (json, fallback = null) => {
51
- if (json == null) return fallback;
52
- try {
53
- return JSON.parse(json);
54
- } catch {
55
- return fallback;
56
- }
64
+ /**
65
+ * Parses JSON safely and returns a fallback value when parsing fails.
66
+ *
67
+ * @example
68
+ * ```ts
69
+ * safeJsonParse('{"enabled":true}', {}); // { enabled: true }
70
+ * ```
71
+ */
72
+ var safeJsonParse = (json, fallback = null) => {
73
+ if (json == null) return fallback;
74
+ try {
75
+ return JSON.parse(json);
76
+ } catch {
77
+ return fallback;
78
+ }
57
79
  };
58
- const UNSAFE_PROPERTY_KEYS = /* @__PURE__ */ new Set(["__proto__", "prototype", "constructor"]);
59
- const isUnsafeProperty = (key) => UNSAFE_PROPERTY_KEYS.has(key);
80
+ var UNSAFE_PROPERTY_KEYS = new Set([
81
+ "__proto__",
82
+ "prototype",
83
+ "constructor"
84
+ ]);
85
+ /**
86
+ * Checks whether a property key is unsafe and can lead to prototype pollution.
87
+ *
88
+ * @example
89
+ * isUnsafeProperty('__proto__'); // true
90
+ * isUnsafeProperty('name'); // false
91
+ */
92
+ var isUnsafeProperty = (key) => UNSAFE_PROPERTY_KEYS.has(key);
93
+ //#endregion
60
94
  exports.flatMapDeep = flatMapDeep;
61
95
  exports.isShallowEqual = isShallowEqual;
62
96
  exports.isUnsafeProperty = isUnsafeProperty;
63
97
  exports.safeJsonParse = safeJsonParse;
64
98
  exports.toArray = toArray;
65
- //# sourceMappingURL=data.cjs.map
99
+
100
+ //# sourceMappingURL=data.cjs.map
package/data.cjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"data.cjs","sources":["../src/data.ts"],"sourcesContent":["import type { AnyObject, Maybe } from 'yummies/types';\n\nexport const isShallowEqual = (a: unknown, b: unknown): boolean => {\n if (a === b) return true;\n\n if (\n typeof a !== 'object' ||\n typeof b !== 'object' ||\n a === null ||\n b === null\n ) {\n return false;\n }\n\n if (a.constructor !== b.constructor) return false;\n\n const isArrayA = Array.isArray(a);\n\n if (isArrayA !== Array.isArray(b)) return false;\n\n if (isArrayA) {\n const arrA = a as unknown[];\n const arrB = b as unknown[];\n if (arrA.length !== arrB.length) return false;\n\n for (const [i, element] of arrA.entries()) {\n if (element !== arrB[i]) return false;\n }\n return true;\n }\n\n if (a instanceof Date) return a.getTime() === (b as Date).getTime();\n\n if (a instanceof RegExp) return a.toString() === (b as RegExp).toString();\n\n const aKeys = Object.keys(a);\n const bKeys = Object.keys(b);\n\n if (aKeys.length !== bKeys.length) return false;\n\n const bObj = b as AnyObject;\n for (const key of aKeys) {\n if (!Object.hasOwn(bObj, key) || (a as AnyObject)[key] !== bObj[key]) {\n return false;\n }\n }\n\n return true;\n};\n\nexport const toArray = <TValue>(value: TValue | TValue[]): TValue[] => {\n return Array.isArray(value) ? value : [value];\n};\n\ntype DeepArray<TValue> = TValue | Array<DeepArray<TValue>>;\n\nexport const flatMapDeep = <TSource, TNewValue>(\n arr: DeepArray<TSource>,\n fn: (value: TSource, i: number, arr: TSource[]) => TNewValue,\n): TNewValue[] => {\n const source: TSource[] = [];\n\n const collect = (value: DeepArray<TSource>): void => {\n if (!Array.isArray(value)) {\n source.push(value);\n return;\n }\n\n for (const item of value) {\n collect(item);\n }\n };\n\n collect(arr);\n\n return source.map((value, i) => fn(value, i, source));\n};\n\nexport const safeJsonParse = <TValue = any, TFallback = null>(\n json: Maybe<string>,\n fallback: TFallback = null as TFallback,\n): TValue | TFallback => {\n if (json == null) return fallback;\n\n try {\n return JSON.parse(json);\n } catch {\n return fallback;\n }\n};\n\nconst UNSAFE_PROPERTY_KEYS = new Set(['__proto__', 'prototype', 'constructor']);\n\n/**\n * Checks whether a property key is unsafe and can lead to prototype pollution.\n *\n * @example\n * isUnsafeProperty('__proto__'); // true\n * isUnsafeProperty('name'); // false\n */\nexport const isUnsafeProperty = (key: any) => UNSAFE_PROPERTY_KEYS.has(key);\n"],"names":[],"mappings":";;AAEO,MAAM,iBAAiB,CAAC,GAAY,MAAwB;AACjE,MAAI,MAAM,EAAG,QAAO;AAEpB,MACE,OAAO,MAAM,YACb,OAAO,MAAM,YACb,MAAM,QACN,MAAM,MACN;AACA,WAAO;AAAA,EACT;AAEA,MAAI,EAAE,gBAAgB,EAAE,YAAa,QAAO;AAE5C,QAAM,WAAW,MAAM,QAAQ,CAAC;AAEhC,MAAI,aAAa,MAAM,QAAQ,CAAC,EAAG,QAAO;AAE1C,MAAI,UAAU;AACZ,UAAM,OAAO;AACb,UAAM,OAAO;AACb,QAAI,KAAK,WAAW,KAAK,OAAQ,QAAO;AAExC,eAAW,CAAC,GAAG,OAAO,KAAK,KAAK,WAAW;AACzC,UAAI,YAAY,KAAK,CAAC,EAAG,QAAO;AAAA,IAClC;AACA,WAAO;AAAA,EACT;AAEA,MAAI,aAAa,KAAM,QAAO,EAAE,QAAA,MAAe,EAAW,QAAA;AAE1D,MAAI,aAAa,OAAQ,QAAO,EAAE,SAAA,MAAgB,EAAa,SAAA;AAE/D,QAAM,QAAQ,OAAO,KAAK,CAAC;AAC3B,QAAM,QAAQ,OAAO,KAAK,CAAC;AAE3B,MAAI,MAAM,WAAW,MAAM,OAAQ,QAAO;AAE1C,QAAM,OAAO;AACb,aAAW,OAAO,OAAO;AACvB,QAAI,CAAC,OAAO,OAAO,MAAM,GAAG,KAAM,EAAgB,GAAG,MAAM,KAAK,GAAG,GAAG;AACpE,aAAO;AAAA,IACT;AAAA,EACF;AAEA,SAAO;AACT;AAEO,MAAM,UAAU,CAAS,UAAuC;AACrE,SAAO,MAAM,QAAQ,KAAK,IAAI,QAAQ,CAAC,KAAK;AAC9C;AAIO,MAAM,cAAc,CACzB,KACA,OACgB;AAChB,QAAM,SAAoB,CAAA;AAE1B,QAAM,UAAU,CAAC,UAAoC;AACnD,QAAI,CAAC,MAAM,QAAQ,KAAK,GAAG;AACzB,aAAO,KAAK,KAAK;AACjB;AAAA,IACF;AAEA,eAAW,QAAQ,OAAO;AACxB,cAAQ,IAAI;AAAA,IACd;AAAA,EACF;AAEA,UAAQ,GAAG;AAEX,SAAO,OAAO,IAAI,CAAC,OAAO,MAAM,GAAG,OAAO,GAAG,MAAM,CAAC;AACtD;AAEO,MAAM,gBAAgB,CAC3B,MACA,WAAsB,SACC;AACvB,MAAI,QAAQ,KAAM,QAAO;AAEzB,MAAI;AACF,WAAO,KAAK,MAAM,IAAI;AAAA,EACxB,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAEA,MAAM,uBAAuB,oBAAI,IAAI,CAAC,aAAa,aAAa,aAAa,CAAC;AASvE,MAAM,mBAAmB,CAAC,QAAa,qBAAqB,IAAI,GAAG;;;;;;"}
1
+ {"version":3,"file":"data.cjs","names":[],"sources":["../src/data.ts"],"sourcesContent":["import type { AnyObject, Maybe } from 'yummies/types';\n\n/**\n * Performs a shallow comparison for arrays, plain objects, dates and regular expressions.\n *\n * @example\n * ```ts\n * isShallowEqual({ id: 1 }, { id: 1 }); // true\n * ```\n */\nexport const isShallowEqual = (a: unknown, b: unknown): boolean => {\n if (a === b) return true;\n\n if (\n typeof a !== 'object' ||\n typeof b !== 'object' ||\n a === null ||\n b === null\n ) {\n return false;\n }\n\n if (a.constructor !== b.constructor) return false;\n\n const isArrayA = Array.isArray(a);\n\n if (isArrayA !== Array.isArray(b)) return false;\n\n if (isArrayA) {\n const arrA = a as unknown[];\n const arrB = b as unknown[];\n if (arrA.length !== arrB.length) return false;\n\n for (const [i, element] of arrA.entries()) {\n if (element !== arrB[i]) return false;\n }\n return true;\n }\n\n if (a instanceof Date) return a.getTime() === (b as Date).getTime();\n\n if (a instanceof RegExp) return a.toString() === (b as RegExp).toString();\n\n const aKeys = Object.keys(a);\n const bKeys = Object.keys(b);\n\n if (aKeys.length !== bKeys.length) return false;\n\n const bObj = b as AnyObject;\n for (const key of aKeys) {\n if (!Object.hasOwn(bObj, key) || (a as AnyObject)[key] !== bObj[key]) {\n return false;\n }\n }\n\n return true;\n};\n\n/**\n * Wraps a value in an array when it is not already an array.\n *\n * @example\n * ```ts\n * toArray('item'); // ['item']\n * ```\n */\nexport const toArray = <TValue>(value: TValue | TValue[]): TValue[] => {\n return Array.isArray(value) ? value : [value];\n};\n\ntype DeepArray<TValue> = TValue | Array<DeepArray<TValue>>;\n\n/**\n * Recursively flattens a nested array and maps the collected values.\n *\n * @example\n * ```ts\n * flatMapDeep([1, [2, [3]]], (value) => value * 2); // [2, 4, 6]\n * ```\n */\nexport const flatMapDeep = <TSource, TNewValue>(\n arr: DeepArray<TSource>,\n fn: (value: TSource, i: number, arr: TSource[]) => TNewValue,\n): TNewValue[] => {\n const source: TSource[] = [];\n\n const collect = (value: DeepArray<TSource>): void => {\n if (!Array.isArray(value)) {\n source.push(value);\n return;\n }\n\n for (const item of value) {\n collect(item);\n }\n };\n\n collect(arr);\n\n return source.map((value, i) => fn(value, i, source));\n};\n\n/**\n * Parses JSON safely and returns a fallback value when parsing fails.\n *\n * @example\n * ```ts\n * safeJsonParse('{\"enabled\":true}', {}); // { enabled: true }\n * ```\n */\nexport const safeJsonParse = <TValue = any, TFallback = null>(\n json: Maybe<string>,\n fallback: TFallback = null as TFallback,\n): TValue | TFallback => {\n if (json == null) return fallback;\n\n try {\n return JSON.parse(json);\n } catch {\n return fallback;\n }\n};\n\nconst UNSAFE_PROPERTY_KEYS = new Set(['__proto__', 'prototype', 'constructor']);\n\n/**\n * Checks whether a property key is unsafe and can lead to prototype pollution.\n *\n * @example\n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F,OAAK,MAAM,QAAQ,MACjB,SAAQ,KAAK;;AAIjB,SAAQ,IAAI;AAEZ,QAAO,OAAO,KAAK,OAAO,MAAM,GAAG,OAAO,GAAG,OAAO,CAAC;;;;;;;;;;AAWvD,IAAa,iBACX,MACA,WAAsB,SACC;AACvB,KAAI,QAAQ,KAAM,QAAO;AAEzB,KAAI;AACF,SAAO,KAAK,MAAM,KAAK;SACjB;AACN,SAAO;;;AAIX,IAAM,uBAAuB,IAAI,IAAI;CAAC;CAAa;CAAa;CAAc,CAAC;;;;;;;;AAS/E,IAAa,oBAAoB,QAAa,qBAAqB,IAAI,IAAI"}
package/data.d.ts CHANGED
@@ -1,9 +1,41 @@
1
1
  import { Maybe } from 'yummies/types';
2
2
 
3
+ /**
4
+ * Performs a shallow comparison for arrays, plain objects, dates and regular expressions.
5
+ *
6
+ * @example
7
+ * ```ts
8
+ * isShallowEqual({ id: 1 }, { id: 1 }); // true
9
+ * ```
10
+ */
3
11
  declare const isShallowEqual: (a: unknown, b: unknown) => boolean;
12
+ /**
13
+ * Wraps a value in an array when it is not already an array.
14
+ *
15
+ * @example
16
+ * ```ts
17
+ * toArray('item'); // ['item']
18
+ * ```
19
+ */
4
20
  declare const toArray: <TValue>(value: TValue | TValue[]) => TValue[];
5
21
  type DeepArray<TValue> = TValue | Array<DeepArray<TValue>>;
22
+ /**
23
+ * Recursively flattens a nested array and maps the collected values.
24
+ *
25
+ * @example
26
+ * ```ts
27
+ * flatMapDeep([1, [2, [3]]], (value) => value * 2); // [2, 4, 6]
28
+ * ```
29
+ */
6
30
  declare const flatMapDeep: <TSource, TNewValue>(arr: DeepArray<TSource>, fn: (value: TSource, i: number, arr: TSource[]) => TNewValue) => TNewValue[];
31
+ /**
32
+ * Parses JSON safely and returns a fallback value when parsing fails.
33
+ *
34
+ * @example
35
+ * ```ts
36
+ * safeJsonParse('{"enabled":true}', {}); // { enabled: true }
37
+ * ```
38
+ */
7
39
  declare const safeJsonParse: <TValue = any, TFallback = null>(json: Maybe<string>, fallback?: TFallback) => TValue | TFallback;
8
40
  /**
9
41
  * Checks whether a property key is unsafe and can lead to prototype pollution.
package/data.js CHANGED
@@ -1,65 +1,95 @@
1
- const isShallowEqual = (a, b) => {
2
- if (a === b) return true;
3
- if (typeof a !== "object" || typeof b !== "object" || a === null || b === null) {
4
- return false;
5
- }
6
- if (a.constructor !== b.constructor) return false;
7
- const isArrayA = Array.isArray(a);
8
- if (isArrayA !== Array.isArray(b)) return false;
9
- if (isArrayA) {
10
- const arrA = a;
11
- const arrB = b;
12
- if (arrA.length !== arrB.length) return false;
13
- for (const [i, element] of arrA.entries()) {
14
- if (element !== arrB[i]) return false;
15
- }
16
- return true;
17
- }
18
- if (a instanceof Date) return a.getTime() === b.getTime();
19
- if (a instanceof RegExp) return a.toString() === b.toString();
20
- const aKeys = Object.keys(a);
21
- const bKeys = Object.keys(b);
22
- if (aKeys.length !== bKeys.length) return false;
23
- const bObj = b;
24
- for (const key of aKeys) {
25
- if (!Object.hasOwn(bObj, key) || a[key] !== bObj[key]) {
26
- return false;
27
- }
28
- }
29
- return true;
1
+ //#region src/data.ts
2
+ /**
3
+ * Performs a shallow comparison for arrays, plain objects, dates and regular expressions.
4
+ *
5
+ * @example
6
+ * ```ts
7
+ * isShallowEqual({ id: 1 }, { id: 1 }); // true
8
+ * ```
9
+ */
10
+ var isShallowEqual = (a, b) => {
11
+ if (a === b) return true;
12
+ if (typeof a !== "object" || typeof b !== "object" || a === null || b === null) return false;
13
+ if (a.constructor !== b.constructor) return false;
14
+ const isArrayA = Array.isArray(a);
15
+ if (isArrayA !== Array.isArray(b)) return false;
16
+ if (isArrayA) {
17
+ const arrA = a;
18
+ const arrB = b;
19
+ if (arrA.length !== arrB.length) return false;
20
+ for (const [i, element] of arrA.entries()) if (element !== arrB[i]) return false;
21
+ return true;
22
+ }
23
+ if (a instanceof Date) return a.getTime() === b.getTime();
24
+ if (a instanceof RegExp) return a.toString() === b.toString();
25
+ const aKeys = Object.keys(a);
26
+ const bKeys = Object.keys(b);
27
+ if (aKeys.length !== bKeys.length) return false;
28
+ const bObj = b;
29
+ for (const key of aKeys) if (!Object.hasOwn(bObj, key) || a[key] !== bObj[key]) return false;
30
+ return true;
30
31
  };
31
- const toArray = (value) => {
32
- return Array.isArray(value) ? value : [value];
32
+ /**
33
+ * Wraps a value in an array when it is not already an array.
34
+ *
35
+ * @example
36
+ * ```ts
37
+ * toArray('item'); // ['item']
38
+ * ```
39
+ */
40
+ var toArray = (value) => {
41
+ return Array.isArray(value) ? value : [value];
33
42
  };
34
- const flatMapDeep = (arr, fn) => {
35
- const source = [];
36
- const collect = (value) => {
37
- if (!Array.isArray(value)) {
38
- source.push(value);
39
- return;
40
- }
41
- for (const item of value) {
42
- collect(item);
43
- }
44
- };
45
- collect(arr);
46
- return source.map((value, i) => fn(value, i, source));
43
+ /**
44
+ * Recursively flattens a nested array and maps the collected values.
45
+ *
46
+ * @example
47
+ * ```ts
48
+ * flatMapDeep([1, [2, [3]]], (value) => value * 2); // [2, 4, 6]
49
+ * ```
50
+ */
51
+ var flatMapDeep = (arr, fn) => {
52
+ const source = [];
53
+ const collect = (value) => {
54
+ if (!Array.isArray(value)) {
55
+ source.push(value);
56
+ return;
57
+ }
58
+ for (const item of value) collect(item);
59
+ };
60
+ collect(arr);
61
+ return source.map((value, i) => fn(value, i, source));
47
62
  };
48
- const safeJsonParse = (json, fallback = null) => {
49
- if (json == null) return fallback;
50
- try {
51
- return JSON.parse(json);
52
- } catch {
53
- return fallback;
54
- }
63
+ /**
64
+ * Parses JSON safely and returns a fallback value when parsing fails.
65
+ *
66
+ * @example
67
+ * ```ts
68
+ * safeJsonParse('{"enabled":true}', {}); // { enabled: true }
69
+ * ```
70
+ */
71
+ var safeJsonParse = (json, fallback = null) => {
72
+ if (json == null) return fallback;
73
+ try {
74
+ return JSON.parse(json);
75
+ } catch {
76
+ return fallback;
77
+ }
55
78
  };
56
- const UNSAFE_PROPERTY_KEYS = /* @__PURE__ */ new Set(["__proto__", "prototype", "constructor"]);
57
- const isUnsafeProperty = (key) => UNSAFE_PROPERTY_KEYS.has(key);
58
- export {
59
- flatMapDeep,
60
- isShallowEqual,
61
- isUnsafeProperty,
62
- safeJsonParse,
63
- toArray
64
- };
65
- //# sourceMappingURL=data.js.map
79
+ var UNSAFE_PROPERTY_KEYS = new Set([
80
+ "__proto__",
81
+ "prototype",
82
+ "constructor"
83
+ ]);
84
+ /**
85
+ * Checks whether a property key is unsafe and can lead to prototype pollution.
86
+ *
87
+ * @example
88
+ * isUnsafeProperty('__proto__'); // true
89
+ * isUnsafeProperty('name'); // false
90
+ */
91
+ var isUnsafeProperty = (key) => UNSAFE_PROPERTY_KEYS.has(key);
92
+ //#endregion
93
+ export { flatMapDeep, isShallowEqual, isUnsafeProperty, safeJsonParse, toArray };
94
+
95
+ //# sourceMappingURL=data.js.map
package/data.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"data.js","sources":["../src/data.ts"],"sourcesContent":["import type { AnyObject, Maybe } from 'yummies/types';\n\nexport const isShallowEqual = (a: unknown, b: unknown): boolean => {\n if (a === b) return true;\n\n if (\n typeof a !== 'object' ||\n typeof b !== 'object' ||\n a === null ||\n b === null\n ) {\n return false;\n }\n\n if (a.constructor !== b.constructor) return false;\n\n const isArrayA = Array.isArray(a);\n\n if (isArrayA !== Array.isArray(b)) return false;\n\n if (isArrayA) {\n const arrA = a as unknown[];\n const arrB = b as unknown[];\n if (arrA.length !== arrB.length) return false;\n\n for (const [i, element] of arrA.entries()) {\n if (element !== arrB[i]) return false;\n }\n return true;\n }\n\n if (a instanceof Date) return a.getTime() === (b as Date).getTime();\n\n if (a instanceof RegExp) return a.toString() === (b as RegExp).toString();\n\n const aKeys = Object.keys(a);\n const bKeys = Object.keys(b);\n\n if (aKeys.length !== bKeys.length) return false;\n\n const bObj = b as AnyObject;\n for (const key of aKeys) {\n if (!Object.hasOwn(bObj, key) || (a as AnyObject)[key] !== bObj[key]) {\n return false;\n }\n }\n\n return true;\n};\n\nexport const toArray = <TValue>(value: TValue | TValue[]): TValue[] => {\n return Array.isArray(value) ? value : [value];\n};\n\ntype DeepArray<TValue> = TValue | Array<DeepArray<TValue>>;\n\nexport const flatMapDeep = <TSource, TNewValue>(\n arr: DeepArray<TSource>,\n fn: (value: TSource, i: number, arr: TSource[]) => TNewValue,\n): TNewValue[] => {\n const source: TSource[] = [];\n\n const collect = (value: DeepArray<TSource>): void => {\n if (!Array.isArray(value)) {\n source.push(value);\n return;\n }\n\n for (const item of value) {\n collect(item);\n }\n };\n\n collect(arr);\n\n return source.map((value, i) => fn(value, i, source));\n};\n\nexport const safeJsonParse = <TValue = any, TFallback = null>(\n json: Maybe<string>,\n fallback: TFallback = null as TFallback,\n): TValue | TFallback => {\n if (json == null) return fallback;\n\n try {\n return JSON.parse(json);\n } catch {\n return fallback;\n }\n};\n\nconst UNSAFE_PROPERTY_KEYS = new Set(['__proto__', 'prototype', 'constructor']);\n\n/**\n * Checks whether a property key is unsafe and can lead to prototype pollution.\n *\n * @example\n * isUnsafeProperty('__proto__'); // true\n * isUnsafeProperty('name'); // false\n */\nexport const isUnsafeProperty = (key: any) => UNSAFE_PROPERTY_KEYS.has(key);\n"],"names":[],"mappings":"AAEO,MAAM,iBAAiB,CAAC,GAAY,MAAwB;AACjE,MAAI,MAAM,EAAG,QAAO;AAEpB,MACE,OAAO,MAAM,YACb,OAAO,MAAM,YACb,MAAM,QACN,MAAM,MACN;AACA,WAAO;AAAA,EACT;AAEA,MAAI,EAAE,gBAAgB,EAAE,YAAa,QAAO;AAE5C,QAAM,WAAW,MAAM,QAAQ,CAAC;AAEhC,MAAI,aAAa,MAAM,QAAQ,CAAC,EAAG,QAAO;AAE1C,MAAI,UAAU;AACZ,UAAM,OAAO;AACb,UAAM,OAAO;AACb,QAAI,KAAK,WAAW,KAAK,OAAQ,QAAO;AAExC,eAAW,CAAC,GAAG,OAAO,KAAK,KAAK,WAAW;AACzC,UAAI,YAAY,KAAK,CAAC,EAAG,QAA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["import type { AnyObject, Maybe } from 'yummies/types';\n\n/**\n * Performs a shallow comparison for arrays, plain objects, dates and regular expressions.\n *\n * @example\n * ```ts\n * isShallowEqual({ id: 1 }, { id: 1 }); // true\n * ```\n */\nexport const isShallowEqual = (a: unknown, b: unknown): boolean => {\n if (a === b) return true;\n\n if (\n typeof a !== 'object' ||\n typeof b !== 'object' ||\n a === null ||\n b === null\n ) {\n return false;\n }\n\n if (a.constructor !== b.constructor) return false;\n\n const isArrayA = Array.isArray(a);\n\n if (isArrayA !== Array.isArray(b)) return false;\n\n if (isArrayA) {\n const arrA = a as unknown[];\n const arrB = b as unknown[];\n if (arrA.length !== arrB.length) return false;\n\n for (const [i, element] of arrA.entries()) {\n if (element !== arrB[i]) return false;\n }\n return true;\n }\n\n if (a instanceof Date) return a.getTime() === (b as Date).getTime();\n\n if (a instanceof RegExp) return a.toString() === (b as RegExp).toString();\n\n const aKeys = Object.keys(a);\n const bKeys = Object.keys(b);\n\n if (aKeys.length !== bKeys.length) return false;\n\n const bObj = b as AnyObject;\n for (const key of aKeys) {\n if (!Object.hasOwn(bObj, key) || (a as AnyObject)[key] !== bObj[key]) {\n return false;\n }\n }\n\n return true;\n};\n\n/**\n * Wraps a value in an array when it is not already an array.\n *\n * @example\n * ```ts\n * toArray('item'); // ['item']\n * ```\n */\nexport const toArray = <TValue>(value: TValue | TValue[]): TValue[] => {\n return Array.isArray(value) ? value : [value];\n};\n\ntype DeepArray<TValue> = TValue | Array<DeepArray<TValue>>;\n\n/**\n * Recursively flattens a nested array and maps the collected values.\n *\n * @example\n * ```ts\n * flatMapDeep([1, [2, [3]]], (value) => value * 2); // [2, 4, 6]\n * ```\n */\nexport const flatMapDeep = <TSource, TNewValue>(\n arr: DeepArray<TSource>,\n fn: (value: TSource, i: number, arr: TSource[]) => TNewValue,\n): TNewValue[] => {\n const source: TSource[] = [];\n\n const collect = (value: DeepArray<TSource>): void => {\n if (!Array.isArray(value)) {\n source.push(value);\n return;\n }\n\n for (const item of value) {\n collect(item);\n }\n };\n\n collect(arr);\n\n return source.map((value, i) => fn(value, i, source));\n};\n\n/**\n * Parses JSON safely and returns a fallback value when parsing fails.\n *\n * @example\n * ```ts\n * safeJsonParse('{\"enabled\":true}', {}); // { enabled: true }\n * ```\n */\nexport const safeJsonParse = <TValue = any, TFallback = null>(\n json: Maybe<string>,\n fallback: TFallback = null as TFallback,\n): TValue | TFallback => {\n if (json == null) return fallback;\n\n try {\n return JSON.parse(json);\n } catch {\n return fallback;\n }\n};\n\nconst UNSAFE_PROPERTY_KEYS = new Set(['__proto__', 'prototype', 'constructor']);\n\n/**\n * Checks whether a property key is unsafe and can lead to prototype pollution.\n *\n * @example\n * isUnsafeProperty('__proto__'); // true\n * isUnsafeProperty('name'); // false\n */\nexport const isUnsafeProperty = (key: any) => UNSAFE_PROPERTY_KEYS.has(key);\n"],"mappings":";;;;;;;;;AAUA,IAAa,kBAAkB,GAAY,MAAwB;AACjE,KAAI,MAAM,EAAG,QAAO;AAEpB,KACE,OAAO,MAAM,YACb,OAAO,MAAM,YACb,MAAM,QACN,MAAM,KAEN,QAAO;AAGT,KAAI,EAAE,gBAAgB,EAAE,YAAa,QAAO;CAE5C,MAAM,WAAW,MAAM,QAAQ,EAAE;AAEjC,KAAI,aAAa,MAAM,QAAQ,EAAE,CAAE,QAAO;AAE1C,KAAI,UAAU;EACZ,MAAM,OAAO;EACb,MAAM,OAAO;AACb,MAAI,KAAK,WAAW,KAAK,OAAQ,QAAO;AAExC,OAAK,MAAM,CAAC,GAAG,YAAY,KAAK,SAAS,CACvC,KAAI,YAAY,KAAK,GAAI,QAAO;AAElC,SAAO;;AAGT,KAAI,aAAa,KAAM,QAAO,EAAE,SAAS,KAAM,EAAW,SAAS;AAEnE,KAAI,aAAa,OAAQ,QAAO,EAAE,UAAU,KAAM,EAAa,UAAU;CAEzE,MAAM,QAAQ,OAAO,KAAK,EAAE;CAC5B,MAAM,QAAQ,OAAO,KAAK,EAAE;AAE5B,KAAI,MAAM,WA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