yummies 7.11.0 → 7.13.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 (159) hide show
  1. package/README.md +5 -87
  2. package/async.cjs +179 -48
  3. package/async.cjs.map +1 -1
  4. package/async.d.ts +125 -7
  5. package/async.js +180 -54
  6. package/async.js.map +1 -1
  7. package/chunk-CVq3Gv4J.cjs +50 -0
  8. package/chunk-YKewjYmz.js +37 -0
  9. package/common.cjs +48 -8
  10. package/common.cjs.map +1 -1
  11. package/common.d.ts +53 -2
  12. package/common.js +49 -11
  13. package/common.js.map +1 -1
  14. package/complex.cjs +275 -128
  15. package/complex.cjs.map +1 -1
  16. package/complex.d.ts +66 -0
  17. package/complex.js +275 -133
  18. package/complex.js.map +1 -1
  19. package/cookie.cjs +17 -7
  20. package/cookie.cjs.map +1 -1
  21. package/cookie.d.ts +26 -0
  22. package/cookie.js +18 -9
  23. package/cookie.js.map +1 -1
  24. package/css.cjs +163 -39
  25. package/css.cjs.map +1 -1
  26. package/css.d.ts +115 -6
  27. package/css.js +159 -41
  28. package/css.js.map +1 -1
  29. package/data.cjs +90 -55
  30. package/data.cjs.map +1 -1
  31. package/data.d.ts +50 -0
  32. package/data.js +91 -61
  33. package/data.js.map +1 -1
  34. package/date-time.cjs +594 -412
  35. package/date-time.cjs.map +1 -1
  36. package/date-time.d.ts +105 -0
  37. package/date-time.js +591 -421
  38. package/date-time.js.map +1 -1
  39. package/device.cjs +65 -23
  40. package/device.cjs.map +1 -1
  41. package/device.d.ts +49 -0
  42. package/device.js +66 -31
  43. package/device.js.map +1 -1
  44. package/encodings.cjs +275 -266
  45. package/encodings.cjs.map +1 -1
  46. package/encodings.d.ts +25 -0
  47. package/encodings.js +276 -268
  48. package/encodings.js.map +1 -1
  49. package/errors.cjs +36 -18
  50. package/errors.cjs.map +1 -1
  51. package/errors.d.ts +17 -0
  52. package/errors.js +35 -19
  53. package/errors.js.map +1 -1
  54. package/file.cjs +58 -24
  55. package/file.cjs.map +1 -1
  56. package/file.d.ts +32 -0
  57. package/file.js +59 -27
  58. package/file.js.map +1 -1
  59. package/format.cjs +125 -83
  60. package/format.cjs.map +1 -1
  61. package/format.d.ts +18 -0
  62. package/format.js +118 -82
  63. package/format.js.map +1 -1
  64. package/html.cjs +242 -137
  65. package/html.cjs.map +1 -1
  66. package/html.d.ts +81 -0
  67. package/html.js +239 -150
  68. package/html.js.map +1 -1
  69. package/id.cjs +90 -17
  70. package/id.cjs.map +1 -1
  71. package/id.d.ts +16 -0
  72. package/id.js +89 -24
  73. package/id.js.map +1 -1
  74. package/imports.cjs +57 -29
  75. package/imports.cjs.map +1 -1
  76. package/imports.d.ts +24 -0
  77. package/imports.js +56 -31
  78. package/imports.js.map +1 -1
  79. package/math.cjs +32 -6
  80. package/math.cjs.map +1 -1
  81. package/math.d.ts +33 -0
  82. package/math.js +33 -10
  83. package/math.js.map +1 -1
  84. package/media.cjs +291 -84
  85. package/media.cjs.map +1 -1
  86. package/media.d.ts +204 -2
  87. package/media.js +290 -93
  88. package/media.js.map +1 -1
  89. package/mobx.cjs +449 -193
  90. package/mobx.cjs.map +1 -1
  91. package/mobx.d.ts +108 -0
  92. package/mobx.js +447 -200
  93. package/mobx.js.map +1 -1
  94. package/ms.cjs +37 -10
  95. package/ms.cjs.map +1 -1
  96. package/ms.d.ts +16 -0
  97. package/ms.js +38 -13
  98. package/ms.js.map +1 -1
  99. package/number.cjs +29 -7
  100. package/number.cjs.map +1 -1
  101. package/number.d.ts +16 -0
  102. package/number.js +30 -9
  103. package/number.js.map +1 -1
  104. package/package.json +11 -3
  105. package/parser.cjs +117 -64
  106. package/parser.cjs.map +1 -1
  107. package/parser.d.ts +17 -0
  108. package/parser.js +111 -64
  109. package/parser.js.map +1 -1
  110. package/price.cjs +24 -18
  111. package/price.cjs.map +1 -1
  112. package/price.d.ts +24 -0
  113. package/price.js +25 -20
  114. package/price.js.map +1 -1
  115. package/random.cjs +95 -13
  116. package/random.cjs.map +1 -1
  117. package/random.d.ts +80 -0
  118. package/random.js +96 -22
  119. package/random.js.map +1 -1
  120. package/react.cjs +673 -214
  121. package/react.cjs.map +1 -1
  122. package/react.d.ts +21 -0
  123. package/react.js +674 -239
  124. package/react.js.map +1 -1
  125. package/sound.cjs +30 -9
  126. package/sound.cjs.map +1 -1
  127. package/sound.d.ts +16 -0
  128. package/sound.js +31 -11
  129. package/sound.js.map +1 -1
  130. package/storage.cjs +49 -50
  131. package/storage.cjs.map +1 -1
  132. package/storage.d.ts +24 -0
  133. package/storage.js +50 -53
  134. package/storage.js.map +1 -1
  135. package/text.cjs +67 -34
  136. package/text.cjs.map +1 -1
  137. package/text.d.ts +16 -0
  138. package/text.js +68 -37
  139. package/text.js.map +1 -1
  140. package/type-guard.cjs +292 -72
  141. package/type-guard.cjs.map +1 -1
  142. package/type-guard.d.ts +18 -0
  143. package/type-guard.js +288 -73
  144. package/type-guard.js.map +1 -1
  145. package/types.cjs +0 -2
  146. package/types.d.ts +41 -0
  147. package/types.global.cjs +0 -2
  148. package/types.global.d.ts +41 -0
  149. package/types.global.js +0 -2
  150. package/types.js +0 -2
  151. package/vibrate.cjs +47 -6
  152. package/vibrate.cjs.map +1 -1
  153. package/vibrate.d.ts +39 -1
  154. package/vibrate.js +48 -8
  155. package/vibrate.js.map +1 -1
  156. package/types.cjs.map +0 -1
  157. package/types.global.cjs.map +0 -1
  158. package/types.global.js.map +0 -1
  159. 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":["/**\n * ---header-docs-section---\n * # yummies/data\n *\n * ## Description\n *\n * General-purpose data helpers: shallow equality, normalizing values to arrays, and recursive\n * `flatMap`-style transforms. They complement `Array`/`Object` builtins when you need stable\n * comparisons for memoization or small structural utilities without pulling a large lodash-style\n * dependency into the bundle.\n *\n * ## Usage\n *\n * ```ts\n * import { isShallowEqual, toArray } from \"yummies/data\";\n * ```\n */\n\nimport 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":";;;;;;;;;;AA4BA,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,WAAW,MAAM,OAAQ,QAAO;CAE1C,MAAM,OAAO;AACb,MAAK,MAAM,OAAO,MAChB,KAAI,CAAC,OAAO,OAAO,MAAM,IAAI,IAAK,EAAgB,SAAS,KAAK,KAC9D,QAAO;AAIX,QAAO;;;;;;;;;;AAWT,IAAa,WAAmB,UAAuC;AACrE,QAAO,MAAM,QAAQ,MAAM,GAAG,QAAQ,CAAC,MAAM;;;;;;;;;;AAa/C,IAAa,eACX,KACA,OACgB;CAChB,MAAM,SAAoB,EAAE;CAE5B,MAAM,WAAW,UAAoC;AACnD,MAAI,CAAC,MAAM,QAAQ,MAAM,EAAE;AACzB,UAAO,KAAK,MAAM;AAClB;;AAGF,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,59 @@
1
1
  import { Maybe } from 'yummies/types';
2
2
 
3
+ /**
4
+ * ---header-docs-section---
5
+ * # yummies/data
6
+ *
7
+ * ## Description
8
+ *
9
+ * General-purpose data helpers: shallow equality, normalizing values to arrays, and recursive
10
+ * `flatMap`-style transforms. They complement `Array`/`Object` builtins when you need stable
11
+ * comparisons for memoization or small structural utilities without pulling a large lodash-style
12
+ * dependency into the bundle.
13
+ *
14
+ * ## Usage
15
+ *
16
+ * ```ts
17
+ * import { isShallowEqual, toArray } from "yummies/data";
18
+ * ```
19
+ */
20
+
21
+ /**
22
+ * Performs a shallow comparison for arrays, plain objects, dates and regular expressions.
23
+ *
24
+ * @example
25
+ * ```ts
26
+ * isShallowEqual({ id: 1 }, { id: 1 }); // true
27
+ * ```
28
+ */
3
29
  declare const isShallowEqual: (a: unknown, b: unknown) => boolean;
30
+ /**
31
+ * Wraps a value in an array when it is not already an array.
32
+ *
33
+ * @example
34
+ * ```ts
35
+ * toArray('item'); // ['item']
36
+ * ```
37
+ */
4
38
  declare const toArray: <TValue>(value: TValue | TValue[]) => TValue[];
5
39
  type DeepArray<TValue> = TValue | Array<DeepArray<TValue>>;
40
+ /**
41
+ * Recursively flattens a nested array and maps the collected values.
42
+ *
43
+ * @example
44
+ * ```ts
45
+ * flatMapDeep([1, [2, [3]]], (value) => value * 2); // [2, 4, 6]
46
+ * ```
47
+ */
6
48
  declare const flatMapDeep: <TSource, TNewValue>(arr: DeepArray<TSource>, fn: (value: TSource, i: number, arr: TSource[]) => TNewValue) => TNewValue[];
49
+ /**
50
+ * Parses JSON safely and returns a fallback value when parsing fails.
51
+ *
52
+ * @example
53
+ * ```ts
54
+ * safeJsonParse('{"enabled":true}', {}); // { enabled: true }
55
+ * ```
56
+ */
7
57
  declare const safeJsonParse: <TValue = any, TFallback = null>(json: Maybe<string>, fallback?: TFallback) => TValue | TFallback;
8
58
  /**
9
59
  * 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,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.js","names":[],"sources":["../src/data.ts"],"sourcesContent":["/**\n * ---header-docs-section---\n * # yummies/data\n *\n * ## Description\n *\n * General-purpose data helpers: shallow equality, normalizing values to arrays, and recursive\n * `flatMap`-style transforms. They complement `Array`/`Object` builtins when you need stable\n * comparisons for memoization or small structural utilities without pulling a large lodash-style\n * dependency into the bundle.\n *\n * ## Usage\n *\n * ```ts\n * import { isShallowEqual, toArray } from \"yummies/data\";\n * ```\n */\n\nimport 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":";;;;;;;;;AA4BA,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,WAAW,MAAM,OAAQ,QAAO;CAE1C,MAAM,OAAO;AACb,MAAK,MAAM,OAAO,MAChB,KAAI,CAAC,OAAO,OAAO,MAAM,IAAI,IAAK,EAAgB,SAAS,KAAK,KAC9D,QAAO;AAIX,QAAO;;;;;;;;;;AAWT,IAAa,WAAmB,UAAuC;AACrE,QAAO,MAAM,QAAQ,MAAM,GAAG,QAAQ,CAAC,MAAM;;;;;;;;;;AAa/C,IAAa,eACX,KACA,OACgB;CAChB,MAAM,SAAoB,EAAE;CAE5B,MAAM,WAAW,UAAoC;AACnD,MAAI,CAAC,MAAM,QAAQ,MAAM,EAAE;AACzB,UAAO,KAAK,MAAM;AAClB;;AAGF,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"}