cafe-utility 13.2.0 → 13.3.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/index.d.ts +4 -0
- package/index.js +8 -0
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -72,6 +72,8 @@ declare function asId(value: any): number;
|
|
|
72
72
|
declare function asTime(value: any): string;
|
|
73
73
|
declare function asArray(value: any): unknown[];
|
|
74
74
|
declare function asObject(value: any): Record<string, unknown>;
|
|
75
|
+
declare function isNullable(typeFn: (value: any) => boolean, value: any): boolean;
|
|
76
|
+
declare function asNullable<T>(typeFn: (value: any) => T, value: any): T | null;
|
|
75
77
|
declare function enforceObjectShape(value: Record<string, any>, shape: Record<string, (value: any) => boolean>): boolean;
|
|
76
78
|
declare function enforceArrayShape(value: any[], shape: Record<string, (value: any) => boolean>): boolean;
|
|
77
79
|
declare function represent(value: any, strategy?: 'json' | 'key-value', depth?: number): string;
|
|
@@ -563,6 +565,7 @@ export declare const Types: {
|
|
|
563
565
|
isDate: typeof isDate;
|
|
564
566
|
isBlank: typeof isBlank;
|
|
565
567
|
isId: typeof isId;
|
|
568
|
+
isNullable: typeof isNullable;
|
|
566
569
|
asString: typeof asString;
|
|
567
570
|
asNumber: typeof asNumber;
|
|
568
571
|
asInteger: typeof asInteger;
|
|
@@ -574,6 +577,7 @@ export declare const Types: {
|
|
|
574
577
|
asTime: typeof asTime;
|
|
575
578
|
asArray: typeof asArray;
|
|
576
579
|
asObject: typeof asObject;
|
|
580
|
+
asNullable: typeof asNullable;
|
|
577
581
|
enforceObjectShape: typeof enforceObjectShape;
|
|
578
582
|
enforceArrayShape: typeof enforceArrayShape;
|
|
579
583
|
};
|
package/index.js
CHANGED
|
@@ -385,6 +385,12 @@ function asObject(n) {
|
|
|
385
385
|
if (!isStrictlyObject(n)) throw new TypeError('Expected object, got: ' + n)
|
|
386
386
|
return n
|
|
387
387
|
}
|
|
388
|
+
function isNullable(n, e) {
|
|
389
|
+
return isUndefined(e) || e === null ? !0 : n(e)
|
|
390
|
+
}
|
|
391
|
+
function asNullable(n, e) {
|
|
392
|
+
return e === null || isUndefined(e) ? null : n(e)
|
|
393
|
+
}
|
|
388
394
|
function enforceObjectShape(n, e) {
|
|
389
395
|
for (const [t, r] of Object.entries(e)) if (!r(n[t])) throw TypeError(`${t} in value does not exist or match shape`)
|
|
390
396
|
for (const t of Object.keys(n)) if (!e[t]) throw TypeError(`${t} exists in value but not in shape`)
|
|
@@ -2062,6 +2068,7 @@ function raycastCircle(n, e, t) {
|
|
|
2062
2068
|
isDate,
|
|
2063
2069
|
isBlank,
|
|
2064
2070
|
isId,
|
|
2071
|
+
isNullable,
|
|
2065
2072
|
asString,
|
|
2066
2073
|
asNumber,
|
|
2067
2074
|
asInteger,
|
|
@@ -2073,6 +2080,7 @@ function raycastCircle(n, e, t) {
|
|
|
2073
2080
|
asTime,
|
|
2074
2081
|
asArray,
|
|
2075
2082
|
asObject,
|
|
2083
|
+
asNullable,
|
|
2076
2084
|
enforceObjectShape,
|
|
2077
2085
|
enforceArrayShape
|
|
2078
2086
|
}),
|