yummies 7.7.1 → 7.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/data.cjs +21 -1
- package/data.cjs.map +1 -1
- package/data.d.ts +12 -2
- package/data.js +22 -2
- package/data.js.map +1 -1
- package/package.json +1 -1
package/data.cjs
CHANGED
|
@@ -30,7 +30,23 @@ const isShallowEqual = (a, b) => {
|
|
|
30
30
|
}
|
|
31
31
|
return true;
|
|
32
32
|
};
|
|
33
|
-
const
|
|
33
|
+
const toArray = (value) => {
|
|
34
|
+
return Array.isArray(value) ? value : [value];
|
|
35
|
+
};
|
|
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));
|
|
49
|
+
};
|
|
34
50
|
const safeJsonParse = (json, fallback = null) => {
|
|
35
51
|
if (json == null) return fallback;
|
|
36
52
|
try {
|
|
@@ -39,7 +55,11 @@ const safeJsonParse = (json, fallback = null) => {
|
|
|
39
55
|
return fallback;
|
|
40
56
|
}
|
|
41
57
|
};
|
|
58
|
+
const UNSAFE_PROPERTY_KEYS = /* @__PURE__ */ new Set(["__proto__", "prototype", "constructor"]);
|
|
59
|
+
const isUnsafeProperty = (key) => UNSAFE_PROPERTY_KEYS.has(key);
|
|
42
60
|
exports.flatMapDeep = flatMapDeep;
|
|
43
61
|
exports.isShallowEqual = isShallowEqual;
|
|
62
|
+
exports.isUnsafeProperty = isUnsafeProperty;
|
|
44
63
|
exports.safeJsonParse = safeJsonParse;
|
|
64
|
+
exports.toArray = toArray;
|
|
45
65
|
//# 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 flatMapDeep = <TSource, TNewValue>(\n arr: TSource
|
|
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,aAA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AAA,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;;;;;;"}
|
package/data.d.ts
CHANGED
|
@@ -1,7 +1,17 @@
|
|
|
1
1
|
import { Maybe } from 'yummies/types';
|
|
2
2
|
|
|
3
3
|
declare const isShallowEqual: (a: unknown, b: unknown) => boolean;
|
|
4
|
-
declare const
|
|
4
|
+
declare const toArray: <TValue>(value: TValue | TValue[]) => TValue[];
|
|
5
|
+
type DeepArray<TValue> = TValue | Array<DeepArray<TValue>>;
|
|
6
|
+
declare const flatMapDeep: <TSource, TNewValue>(arr: DeepArray<TSource>, fn: (value: TSource, i: number, arr: TSource[]) => TNewValue) => TNewValue[];
|
|
5
7
|
declare const safeJsonParse: <TValue = any, TFallback = null>(json: Maybe<string>, fallback?: TFallback) => TValue | TFallback;
|
|
8
|
+
/**
|
|
9
|
+
* Checks whether a property key is unsafe and can lead to prototype pollution.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* isUnsafeProperty('__proto__'); // true
|
|
13
|
+
* isUnsafeProperty('name'); // false
|
|
14
|
+
*/
|
|
15
|
+
declare const isUnsafeProperty: (key: any) => boolean;
|
|
6
16
|
|
|
7
|
-
export { flatMapDeep, isShallowEqual, safeJsonParse };
|
|
17
|
+
export { flatMapDeep, isShallowEqual, isUnsafeProperty, safeJsonParse, toArray };
|
package/data.js
CHANGED
|
@@ -28,7 +28,23 @@ const isShallowEqual = (a, b) => {
|
|
|
28
28
|
}
|
|
29
29
|
return true;
|
|
30
30
|
};
|
|
31
|
-
const
|
|
31
|
+
const toArray = (value) => {
|
|
32
|
+
return Array.isArray(value) ? value : [value];
|
|
33
|
+
};
|
|
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));
|
|
47
|
+
};
|
|
32
48
|
const safeJsonParse = (json, fallback = null) => {
|
|
33
49
|
if (json == null) return fallback;
|
|
34
50
|
try {
|
|
@@ -37,9 +53,13 @@ const safeJsonParse = (json, fallback = null) => {
|
|
|
37
53
|
return fallback;
|
|
38
54
|
}
|
|
39
55
|
};
|
|
56
|
+
const UNSAFE_PROPERTY_KEYS = /* @__PURE__ */ new Set(["__proto__", "prototype", "constructor"]);
|
|
57
|
+
const isUnsafeProperty = (key) => UNSAFE_PROPERTY_KEYS.has(key);
|
|
40
58
|
export {
|
|
41
59
|
flatMapDeep,
|
|
42
60
|
isShallowEqual,
|
|
43
|
-
|
|
61
|
+
isUnsafeProperty,
|
|
62
|
+
safeJsonParse,
|
|
63
|
+
toArray
|
|
44
64
|
};
|
|
45
65
|
//# 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 flatMapDeep = <TSource, TNewValue>(\n arr: TSource
|
|
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,aA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