yummies 7.5.0 → 7.7.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.
- package/data.cjs +2 -2
- package/data.cjs.map +1 -1
- package/data.d.ts +1 -1
- package/data.js +2 -2
- package/data.js.map +1 -1
- package/package.json +1 -1
- package/types.d.ts +11 -1
- package/types.global.d.ts +10 -0
package/data.cjs
CHANGED
|
@@ -31,11 +31,11 @@ const isShallowEqual = (a, b) => {
|
|
|
31
31
|
return true;
|
|
32
32
|
};
|
|
33
33
|
const flatMapDeep = (arr, fn) => Array.isArray(arr) ? arr.flatMap((c) => flatMapDeep(c, fn)) : [fn(arr, 0, [arr])];
|
|
34
|
-
const safeJsonParse = (json) => {
|
|
34
|
+
const safeJsonParse = (json, fallback = null) => {
|
|
35
35
|
try {
|
|
36
36
|
return JSON.parse(json);
|
|
37
37
|
} catch {
|
|
38
|
-
return
|
|
38
|
+
return fallback;
|
|
39
39
|
}
|
|
40
40
|
};
|
|
41
41
|
exports.flatMapDeep = flatMapDeep;
|
package/data.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"data.cjs","sources":["../src/data.ts"],"sourcesContent":["import type { AnyObject } 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 | TSource[],\n fn: (value: TSource, i: number, arr: TSource[]) => TNewValue,\n): TNewValue[] =>\n Array.isArray(arr)\n ? arr.flatMap((c: TSource): TNewValue[] => flatMapDeep(c, fn))\n : [fn(arr, 0, [arr])];\n\nexport const safeJsonParse = (json: string) => {\n try {\n return JSON.parse(json);\n } catch {\n return
|
|
1
|
+
{"version":3,"file":"data.cjs","sources":["../src/data.ts"],"sourcesContent":["import type { AnyObject } 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 | TSource[],\n fn: (value: TSource, i: number, arr: TSource[]) => TNewValue,\n): TNewValue[] =>\n Array.isArray(arr)\n ? arr.flatMap((c: TSource): TNewValue[] => flatMapDeep(c, fn))\n : [fn(arr, 0, [arr])];\n\nexport const safeJsonParse = <TValue = any, TFallback = null>(\n json: string,\n fallback: TFallback = null as TFallback,\n): TValue | TFallback => {\n try {\n return JSON.parse(json);\n } catch {\n return fallback;\n }\n};\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,cAAc,CACzB,KACA,OAEA,MAAM,QAAQ,GAAG,IACb,IAAI,QAAQ,CAAC,MAA4B,YAAY,GAAG,EAAE,CAAC,IAC3D,CAAC,GAAG,KAAK,GAAG,CAAC,GAAG,CAAC,CAAC;AAEjB,MAAM,gBAAgB,CAC3B,MACA,WAAsB,SACC;AACvB,MAAI;AACF,WAAO,KAAK,MAAM,IAAI;AAAA,EACxB,QAAQ;AACN,WAAO;AAAA,EACT;AACF;;;;"}
|
package/data.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
declare const isShallowEqual: (a: unknown, b: unknown) => boolean;
|
|
2
2
|
declare const flatMapDeep: <TSource, TNewValue>(arr: TSource | TSource[], fn: (value: TSource, i: number, arr: TSource[]) => TNewValue) => TNewValue[];
|
|
3
|
-
declare const safeJsonParse: (json: string) =>
|
|
3
|
+
declare const safeJsonParse: <TValue = any, TFallback = null>(json: string, fallback?: TFallback) => TValue | TFallback;
|
|
4
4
|
|
|
5
5
|
export { flatMapDeep, isShallowEqual, safeJsonParse };
|
package/data.js
CHANGED
|
@@ -29,11 +29,11 @@ const isShallowEqual = (a, b) => {
|
|
|
29
29
|
return true;
|
|
30
30
|
};
|
|
31
31
|
const flatMapDeep = (arr, fn) => Array.isArray(arr) ? arr.flatMap((c) => flatMapDeep(c, fn)) : [fn(arr, 0, [arr])];
|
|
32
|
-
const safeJsonParse = (json) => {
|
|
32
|
+
const safeJsonParse = (json, fallback = null) => {
|
|
33
33
|
try {
|
|
34
34
|
return JSON.parse(json);
|
|
35
35
|
} catch {
|
|
36
|
-
return
|
|
36
|
+
return fallback;
|
|
37
37
|
}
|
|
38
38
|
};
|
|
39
39
|
export {
|
package/data.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"data.js","sources":["../src/data.ts"],"sourcesContent":["import type { AnyObject } 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 | TSource[],\n fn: (value: TSource, i: number, arr: TSource[]) => TNewValue,\n): TNewValue[] =>\n Array.isArray(arr)\n ? arr.flatMap((c: TSource): TNewValue[] => flatMapDeep(c, fn))\n : [fn(arr, 0, [arr])];\n\nexport const safeJsonParse = (json: string) => {\n try {\n return JSON.parse(json);\n } catch {\n return
|
|
1
|
+
{"version":3,"file":"data.js","sources":["../src/data.ts"],"sourcesContent":["import type { AnyObject } 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 | TSource[],\n fn: (value: TSource, i: number, arr: TSource[]) => TNewValue,\n): TNewValue[] =>\n Array.isArray(arr)\n ? arr.flatMap((c: TSource): TNewValue[] => flatMapDeep(c, fn))\n : [fn(arr, 0, [arr])];\n\nexport const safeJsonParse = <TValue = any, TFallback = null>(\n json: string,\n fallback: TFallback = null as TFallback,\n): TValue | TFallback => {\n try {\n return JSON.parse(json);\n } catch {\n return fallback;\n }\n};\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,cAAc,CACzB,KACA,OAEA,MAAM,QAAQ,GAAG,IACb,IAAI,QAAQ,CAAC,MAA4B,YAAY,GAAG,EAAE,CAAC,IAC3D,CAAC,GAAG,KAAK,GAAG,CAAC,GAAG,CAAC,CAAC;AAEjB,MAAM,gBAAgB,CAC3B,MACA,WAAsB,SACC;AACvB,MAAI;AACF,WAAO,KAAK,MAAM,IAAI;AAAA,EACxB,QAAQ;AACN,WAAO;AAAA,EACT;AACF;"}
|
package/package.json
CHANGED
package/types.d.ts
CHANGED
|
@@ -139,6 +139,16 @@ type DeepPartial<T> = T extends BrowserNativeObject ? T : {
|
|
|
139
139
|
* @returns A type with specified keys optional and others required
|
|
140
140
|
*/
|
|
141
141
|
type PartialKeys<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
|
|
142
|
+
/**
|
|
143
|
+
* Makes specified keys of a type possibly Maybe<T> while keeping the rest required.
|
|
144
|
+
*
|
|
145
|
+
* @template T - The original type
|
|
146
|
+
* @template TMaybeKeys - The keys to make possibly Maybe<T>
|
|
147
|
+
* @returns A type with specified keys possibly Maybe<T> and others required
|
|
148
|
+
*/
|
|
149
|
+
type MaybeKeys<T, TMaybeKeys extends keyof T> = {
|
|
150
|
+
[K in keyof T]: K extends TMaybeKeys ? Maybe<T[K]> : T[K];
|
|
151
|
+
};
|
|
142
152
|
/**
|
|
143
153
|
* Makes specified keys of a type required while keeping the rest optional.
|
|
144
154
|
*
|
|
@@ -444,4 +454,4 @@ type AnyBoolean = boolean & {};
|
|
|
444
454
|
*/
|
|
445
455
|
type UpperFirst<S extends string> = S extends `${infer F}${infer R}` ? `${Uppercase<F>}${R}` : S;
|
|
446
456
|
|
|
447
|
-
export type { AllPropertiesOptional, AnyBoolean, AnyFunction, AnyNumber, AnyObject, AnyPrimitive, AnyString, BrowserNativeObject, Class, CopyObject, DeepPartial, Defined, Dict, EmptyObject, ExtractEnumKeys, ExtractEnumValues, ExtractObjects, FalsyValues, Fn, HasKey, HasSpecificKey, IfEquals, IndexKeys, IsAny, IsArray, IsEmptyArray, IsFunction, IsObject, IsObjectEmpty, IsPartial, IsUnknown, KeyOfByValue, LiteralUnion, Maybe, MaybeArray, MaybeFalsy, MaybeFn, MaybePromise, MaybeValues, NonReadonly, NonUndefined, NotMaybe, NotNullable, Nullable, OmitByValue, OverrideKey, Params, PartialIf, PartialKeys, PickByValue, Primitive, ReadonlyKeys, RecordEntries, RenameKey, RequiredKeys, UnionToIntersection, Unpromise, UpperFirst, ValueOf, WithRequired, WritableKeys };
|
|
457
|
+
export type { AllPropertiesOptional, AnyBoolean, AnyFunction, AnyNumber, AnyObject, AnyPrimitive, AnyString, BrowserNativeObject, Class, CopyObject, DeepPartial, Defined, Dict, EmptyObject, ExtractEnumKeys, ExtractEnumValues, ExtractObjects, FalsyValues, Fn, HasKey, HasSpecificKey, IfEquals, IndexKeys, IsAny, IsArray, IsEmptyArray, IsFunction, IsObject, IsObjectEmpty, IsPartial, IsUnknown, KeyOfByValue, LiteralUnion, Maybe, MaybeArray, MaybeFalsy, MaybeFn, MaybeKeys, MaybePromise, MaybeValues, NonReadonly, NonUndefined, NotMaybe, NotNullable, Nullable, OmitByValue, OverrideKey, Params, PartialIf, PartialKeys, PickByValue, Primitive, ReadonlyKeys, RecordEntries, RenameKey, RequiredKeys, UnionToIntersection, Unpromise, UpperFirst, ValueOf, WithRequired, WritableKeys };
|
package/types.global.d.ts
CHANGED
|
@@ -140,6 +140,16 @@ type DeepPartial<T> = T extends BrowserNativeObject ? T : {
|
|
|
140
140
|
* @returns A type with specified keys optional and others required
|
|
141
141
|
*/
|
|
142
142
|
type PartialKeys<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
|
|
143
|
+
/**
|
|
144
|
+
* Makes specified keys of a type possibly Maybe<T> while keeping the rest required.
|
|
145
|
+
*
|
|
146
|
+
* @template T - The original type
|
|
147
|
+
* @template TMaybeKeys - The keys to make possibly Maybe<T>
|
|
148
|
+
* @returns A type with specified keys possibly Maybe<T> and others required
|
|
149
|
+
*/
|
|
150
|
+
type MaybeKeys<T, TMaybeKeys extends keyof T> = {
|
|
151
|
+
[K in keyof T]: K extends TMaybeKeys ? Maybe<T[K]> : T[K];
|
|
152
|
+
};
|
|
143
153
|
/**
|
|
144
154
|
* Makes specified keys of a type required while keeping the rest optional.
|
|
145
155
|
*
|