cafe-utility 18.0.0 → 18.2.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 +12 -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;
|
|
@@ -381,6 +382,7 @@ interface Newable<T> extends Function {
|
|
|
381
382
|
new (...args: any[]): T;
|
|
382
383
|
}
|
|
383
384
|
declare function findInstance<T, K extends T>(array: T[], type: Newable<K>): Optional<K>;
|
|
385
|
+
declare function filterInstances<T, K extends T>(array: T[], type: Newable<K>): K[];
|
|
384
386
|
declare function interleave<T, K>(arrayA: T[], arrayB: K[]): (T | K)[];
|
|
385
387
|
type Playbook<T> = {
|
|
386
388
|
ttl: number;
|
|
@@ -471,6 +473,7 @@ export declare const Arrays: {
|
|
|
471
473
|
bringToFront: typeof bringToFront;
|
|
472
474
|
bringToFrontInPlace: typeof bringToFrontInPlace;
|
|
473
475
|
findInstance: typeof findInstance;
|
|
476
|
+
filterInstances: typeof filterInstances;
|
|
474
477
|
interleave: typeof interleave;
|
|
475
478
|
};
|
|
476
479
|
export declare const System: {
|
|
@@ -614,6 +617,7 @@ export declare const Types: {
|
|
|
614
617
|
asTime: typeof asTime;
|
|
615
618
|
asArray: typeof asArray;
|
|
616
619
|
asObject: typeof asObject;
|
|
620
|
+
asNumericDictionary: typeof asNumericDictionary;
|
|
617
621
|
asNullable: typeof asNullable;
|
|
618
622
|
enforceObjectShape: typeof enforceObjectShape;
|
|
619
623
|
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
|
}
|
|
@@ -1798,6 +1802,9 @@ function findInstance(n, t) {
|
|
|
1798
1802
|
const e = n.find(r => r instanceof t)
|
|
1799
1803
|
return Optional.of(e)
|
|
1800
1804
|
}
|
|
1805
|
+
function filterInstances(n, t) {
|
|
1806
|
+
return n.filter(e => e instanceof t)
|
|
1807
|
+
}
|
|
1801
1808
|
function interleave(n, t) {
|
|
1802
1809
|
const e = [],
|
|
1803
1810
|
r = Math.max(n.length, t.length)
|
|
@@ -2085,6 +2092,7 @@ function raycastCircle(n, t, e) {
|
|
|
2085
2092
|
bringToFront,
|
|
2086
2093
|
bringToFrontInPlace,
|
|
2087
2094
|
findInstance,
|
|
2095
|
+
filterInstances,
|
|
2088
2096
|
interleave
|
|
2089
2097
|
}),
|
|
2090
2098
|
(exports.System = { sleepMillis, forever, scheduleMany, waitFor, expandError }),
|
|
@@ -2217,6 +2225,7 @@ function raycastCircle(n, t, e) {
|
|
|
2217
2225
|
asTime,
|
|
2218
2226
|
asArray,
|
|
2219
2227
|
asObject,
|
|
2228
|
+
asNumericDictionary,
|
|
2220
2229
|
asNullable,
|
|
2221
2230
|
enforceObjectShape,
|
|
2222
2231
|
enforceArrayShape
|