cafe-utility 4.7.3 → 4.9.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 +17 -1
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -69,6 +69,8 @@ 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[];
|
|
73
|
+
declare function asObject(value: any): Record<string, unknown>;
|
|
72
74
|
declare function createLogger(module: string): {
|
|
73
75
|
trace: (...pieces: any[]) => void;
|
|
74
76
|
info: (...pieces: any[]) => void;
|
|
@@ -437,6 +439,8 @@ export declare const Types: {
|
|
|
437
439
|
asDate: typeof asDate;
|
|
438
440
|
asNullableString: typeof asNullableString;
|
|
439
441
|
asId: typeof asId;
|
|
442
|
+
asArray: typeof asArray;
|
|
443
|
+
asObject: typeof asObject;
|
|
440
444
|
};
|
|
441
445
|
export declare const Strings: {
|
|
442
446
|
tokenizeByCount: typeof tokenizeByCount;
|
package/index.js
CHANGED
|
@@ -466,6 +466,20 @@ function asId(value) {
|
|
|
466
466
|
return typeof value === 'string' ? parseInt(value, 10) : value
|
|
467
467
|
}
|
|
468
468
|
|
|
469
|
+
function asArray(value) {
|
|
470
|
+
if (!Array.isArray(value)) {
|
|
471
|
+
throw new TypeError('Expected array, got: ' + value)
|
|
472
|
+
}
|
|
473
|
+
return value
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
function asObject(value) {
|
|
477
|
+
if (!isStrictlyObject(value)) {
|
|
478
|
+
throw new TypeError('Expected object, got: ' + value)
|
|
479
|
+
}
|
|
480
|
+
return value
|
|
481
|
+
}
|
|
482
|
+
|
|
469
483
|
function represent(value) {
|
|
470
484
|
if (isObject(value)) {
|
|
471
485
|
return JSON.stringify(value, null, 4)
|
|
@@ -1854,7 +1868,9 @@ exports.Types = {
|
|
|
1854
1868
|
asNumber,
|
|
1855
1869
|
asDate,
|
|
1856
1870
|
asNullableString,
|
|
1857
|
-
asId
|
|
1871
|
+
asId,
|
|
1872
|
+
asArray,
|
|
1873
|
+
asObject
|
|
1858
1874
|
}
|
|
1859
1875
|
|
|
1860
1876
|
exports.Strings = {
|