cafe-utility 4.6.0 → 4.7.2
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 +11 -7
- package/index.js +14 -1
- 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,6 +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
62
|
declare function randomLetterString(length: number): string;
|
|
62
63
|
declare function randomAlphanumericString(length: number): string;
|
|
63
64
|
declare function randomRichAsciiString(length: number): string;
|
|
@@ -67,15 +68,16 @@ declare function asString(string: any): string;
|
|
|
67
68
|
declare function asNumber(number: any): number;
|
|
68
69
|
declare function asDate(date: any): Date;
|
|
69
70
|
declare function asNullableString(string: any): string | null;
|
|
71
|
+
declare function asId(value: any): number;
|
|
70
72
|
declare function createLogger(module: string): {
|
|
71
|
-
trace: (...pieces:
|
|
72
|
-
info: (...pieces:
|
|
73
|
-
warn: (...pieces:
|
|
74
|
-
error: (...pieces:
|
|
75
|
-
errorObject: (error:
|
|
73
|
+
trace: (...pieces: any[]) => void;
|
|
74
|
+
info: (...pieces: any[]) => void;
|
|
75
|
+
warn: (...pieces: any[]) => void;
|
|
76
|
+
error: (...pieces: any[]) => void;
|
|
77
|
+
errorObject: (error: any, stackTrace?: boolean) => void;
|
|
76
78
|
};
|
|
77
79
|
declare function enableFileLogging(path: string): void;
|
|
78
|
-
declare function expandError(error:
|
|
80
|
+
declare function expandError(error: any, stackTrace?: boolean): string;
|
|
79
81
|
declare function mergeDeep(target: CafeObject, source: CafeObject): CafeObject;
|
|
80
82
|
declare function zip<T>(objects: CafeObject<T>[], reducer: (a: T, b: T) => T): CafeObject<T>;
|
|
81
83
|
declare function zipSum(objects: CafeObject<number>[]): CafeObject<number>;
|
|
@@ -429,10 +431,12 @@ export declare const Types: {
|
|
|
429
431
|
isNumber: typeof isNumber;
|
|
430
432
|
isDate: typeof isDate;
|
|
431
433
|
isBlank: typeof isBlank;
|
|
434
|
+
isId: typeof isId;
|
|
432
435
|
asString: typeof asString;
|
|
433
436
|
asNumber: typeof asNumber;
|
|
434
437
|
asDate: typeof asDate;
|
|
435
438
|
asNullableString: typeof asNullableString;
|
|
439
|
+
asId: typeof asId;
|
|
436
440
|
};
|
|
437
441
|
export declare const Strings: {
|
|
438
442
|
tokenizeByCount: typeof tokenizeByCount;
|
package/index.js
CHANGED
|
@@ -381,6 +381,10 @@ function isBlank(value) {
|
|
|
381
381
|
return !isString(value) || value.trim().length === 0
|
|
382
382
|
}
|
|
383
383
|
|
|
384
|
+
function isId(value) {
|
|
385
|
+
return Number.isInteger(value) && value >= 1
|
|
386
|
+
}
|
|
387
|
+
|
|
384
388
|
const alphabet = 'abcdefghijklmnopqrstuvwxyz'
|
|
385
389
|
const alphanumericAlphabet = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890'
|
|
386
390
|
const richAsciiAlphabet = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$%^&*()_+-=[]{}|;:<>?,./'
|
|
@@ -454,6 +458,13 @@ function asNullableString(string) {
|
|
|
454
458
|
return string
|
|
455
459
|
}
|
|
456
460
|
|
|
461
|
+
function asId(value) {
|
|
462
|
+
if (!isId(value)) {
|
|
463
|
+
throw new TypeError('Expected id, got: ' + value)
|
|
464
|
+
}
|
|
465
|
+
return value
|
|
466
|
+
}
|
|
467
|
+
|
|
457
468
|
function represent(value) {
|
|
458
469
|
if (isObject(value)) {
|
|
459
470
|
return JSON.stringify(value, null, 4)
|
|
@@ -1837,10 +1848,12 @@ exports.Types = {
|
|
|
1837
1848
|
isNumber,
|
|
1838
1849
|
isDate,
|
|
1839
1850
|
isBlank,
|
|
1851
|
+
isId,
|
|
1840
1852
|
asString,
|
|
1841
1853
|
asNumber,
|
|
1842
1854
|
asDate,
|
|
1843
|
-
asNullableString
|
|
1855
|
+
asNullableString,
|
|
1856
|
+
asId
|
|
1844
1857
|
}
|
|
1845
1858
|
|
|
1846
1859
|
exports.Strings = {
|