cafe-utility 4.7.1 → 4.8.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 +6 -4
- package/index.js +11 -2
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -30,7 +30,7 @@ declare function incrementDeep(object: CafeObject, path: string, amount?: number
|
|
|
30
30
|
declare function ensureDeep(object: CafeObject, path: string, value: unknown): unknown;
|
|
31
31
|
declare function deleteDeep(object: CafeObject, path: string): void;
|
|
32
32
|
declare function replaceDeep(object: CafeObject, path: string, value: unknown): unknown;
|
|
33
|
-
declare function getFirstDeep(object: CafeObject, paths: string[], fallbackToAnyKey
|
|
33
|
+
declare function getFirstDeep(object: CafeObject, paths: string[], fallbackToAnyKey?: boolean): unknown;
|
|
34
34
|
declare function forever(callable: (() => Promise<void>) | (() => void), millis: number): Promise<never>;
|
|
35
35
|
declare function readUtf8FileAsync(path: string): Promise<string>;
|
|
36
36
|
declare function readJsonAsync(path: string): Promise<CafeObject>;
|
|
@@ -58,7 +58,7 @@ declare function isString(value: any): value is string;
|
|
|
58
58
|
declare function isNumber(value: any): value is number;
|
|
59
59
|
declare function isDate(value: any): value is Date;
|
|
60
60
|
declare function isBlank(value: any): boolean;
|
|
61
|
-
declare function isId(value: any): value is number;
|
|
61
|
+
declare function isId(value: any): value is number | string;
|
|
62
62
|
declare function randomLetterString(length: number): string;
|
|
63
63
|
declare function randomAlphanumericString(length: number): string;
|
|
64
64
|
declare function randomRichAsciiString(length: number): string;
|
|
@@ -69,15 +69,16 @@ declare function asNumber(number: any): number;
|
|
|
69
69
|
declare function asDate(date: any): Date;
|
|
70
70
|
declare function asNullableString(string: any): string | null;
|
|
71
71
|
declare function asId(value: any): number;
|
|
72
|
+
declare function asArray(value: any): unknown[];
|
|
72
73
|
declare function createLogger(module: string): {
|
|
73
74
|
trace: (...pieces: any[]) => void;
|
|
74
75
|
info: (...pieces: any[]) => void;
|
|
75
76
|
warn: (...pieces: any[]) => void;
|
|
76
77
|
error: (...pieces: any[]) => void;
|
|
77
|
-
errorObject: (error:
|
|
78
|
+
errorObject: (error: any, stackTrace?: boolean) => void;
|
|
78
79
|
};
|
|
79
80
|
declare function enableFileLogging(path: string): void;
|
|
80
|
-
declare function expandError(error:
|
|
81
|
+
declare function expandError(error: any, stackTrace?: boolean): string;
|
|
81
82
|
declare function mergeDeep(target: CafeObject, source: CafeObject): CafeObject;
|
|
82
83
|
declare function zip<T>(objects: CafeObject<T>[], reducer: (a: T, b: T) => T): CafeObject<T>;
|
|
83
84
|
declare function zipSum(objects: CafeObject<number>[]): CafeObject<number>;
|
|
@@ -437,6 +438,7 @@ export declare const Types: {
|
|
|
437
438
|
asDate: typeof asDate;
|
|
438
439
|
asNullableString: typeof asNullableString;
|
|
439
440
|
asId: typeof asId;
|
|
441
|
+
asArray: typeof asArray;
|
|
440
442
|
};
|
|
441
443
|
export declare const Strings: {
|
|
442
444
|
tokenizeByCount: typeof tokenizeByCount;
|
package/index.js
CHANGED
|
@@ -382,7 +382,8 @@ function isBlank(value) {
|
|
|
382
382
|
}
|
|
383
383
|
|
|
384
384
|
function isId(value) {
|
|
385
|
-
|
|
385
|
+
const numeric = typeof value === 'string' ? parseInt(value, 10) : value
|
|
386
|
+
return Number.isInteger(numeric) && numeric >= 1
|
|
386
387
|
}
|
|
387
388
|
|
|
388
389
|
const alphabet = 'abcdefghijklmnopqrstuvwxyz'
|
|
@@ -462,6 +463,13 @@ function asId(value) {
|
|
|
462
463
|
if (!isId(value)) {
|
|
463
464
|
throw new TypeError('Expected id, got: ' + value)
|
|
464
465
|
}
|
|
466
|
+
return typeof value === 'string' ? parseInt(value, 10) : value
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
function asArray(value) {
|
|
470
|
+
if (!Array.isArray(value)) {
|
|
471
|
+
throw new TypeError('Expected array, got: ' + value)
|
|
472
|
+
}
|
|
465
473
|
return value
|
|
466
474
|
}
|
|
467
475
|
|
|
@@ -1853,7 +1861,8 @@ exports.Types = {
|
|
|
1853
1861
|
asNumber,
|
|
1854
1862
|
asDate,
|
|
1855
1863
|
asNullableString,
|
|
1856
|
-
asId
|
|
1864
|
+
asId,
|
|
1865
|
+
asArray
|
|
1857
1866
|
}
|
|
1858
1867
|
|
|
1859
1868
|
exports.Strings = {
|