cafe-utility 18.0.0 → 18.1.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 +2 -0
- package/index.js +8 -3
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -83,6 +83,7 @@ declare function asId(value: any): number;
|
|
|
83
83
|
declare function asTime(value: any): string;
|
|
84
84
|
declare function asArray(value: any): unknown[];
|
|
85
85
|
declare function asObject(value: any): Record<string, unknown>;
|
|
86
|
+
declare function asNumericDictionary(value: any): Record<string, number>;
|
|
86
87
|
declare function isNullable(typeFn: (value: any) => boolean, value: any): boolean;
|
|
87
88
|
declare function asNullable<T>(typeFn: (value: any) => T, value: any): T | null;
|
|
88
89
|
declare function enforceObjectShape(value: Record<string, any>, shape: Record<string, (value: any) => boolean>): boolean;
|
|
@@ -614,6 +615,7 @@ export declare const Types: {
|
|
|
614
615
|
asTime: typeof asTime;
|
|
615
616
|
asArray: typeof asArray;
|
|
616
617
|
asObject: typeof asObject;
|
|
618
|
+
asNumericDictionary: typeof asNumericDictionary;
|
|
617
619
|
asNullable: typeof asNullable;
|
|
618
620
|
enforceObjectShape: typeof enforceObjectShape;
|
|
619
621
|
enforceArrayShape: typeof enforceArrayShape;
|
package/index.js
CHANGED
|
@@ -289,9 +289,6 @@ function isFunction(n) {
|
|
|
289
289
|
function isString(n) {
|
|
290
290
|
return Object.prototype.toString.call(n) === '[object String]'
|
|
291
291
|
}
|
|
292
|
-
function isPromise(n) {
|
|
293
|
-
return n && typeof n.then == 'function'
|
|
294
|
-
}
|
|
295
292
|
function isNumber(n) {
|
|
296
293
|
return typeof n == 'number' && isFinite(n)
|
|
297
294
|
}
|
|
@@ -426,6 +423,13 @@ function asObject(n) {
|
|
|
426
423
|
if (!isStrictlyObject(n)) throw new TypeError('Expected object, got: ' + n)
|
|
427
424
|
return n
|
|
428
425
|
}
|
|
426
|
+
function asNumericDictionary(n) {
|
|
427
|
+
const t = asObject(n),
|
|
428
|
+
e = Object.keys(t),
|
|
429
|
+
r = Object.values(t)
|
|
430
|
+
if (!e.every(isString) || !r.every(isNumber)) throw new TypeError('Expected numeric dictionary, got: ' + n)
|
|
431
|
+
return t
|
|
432
|
+
}
|
|
429
433
|
function isNullable(n, t) {
|
|
430
434
|
return isUndefined(t) || t === null ? !0 : n(t)
|
|
431
435
|
}
|
|
@@ -2217,6 +2221,7 @@ function raycastCircle(n, t, e) {
|
|
|
2217
2221
|
asTime,
|
|
2218
2222
|
asArray,
|
|
2219
2223
|
asObject,
|
|
2224
|
+
asNumericDictionary,
|
|
2220
2225
|
asNullable,
|
|
2221
2226
|
enforceObjectShape,
|
|
2222
2227
|
enforceArrayShape
|