cafe-utility 4.7.3 → 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 +2 -0
- package/index.js +9 -1
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -69,6 +69,7 @@ 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;
|
|
@@ -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
|
@@ -466,6 +466,13 @@ 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
|
+
|
|
469
476
|
function represent(value) {
|
|
470
477
|
if (isObject(value)) {
|
|
471
478
|
return JSON.stringify(value, null, 4)
|
|
@@ -1854,7 +1861,8 @@ exports.Types = {
|
|
|
1854
1861
|
asNumber,
|
|
1855
1862
|
asDate,
|
|
1856
1863
|
asNullableString,
|
|
1857
|
-
asId
|
|
1864
|
+
asId,
|
|
1865
|
+
asArray
|
|
1858
1866
|
}
|
|
1859
1867
|
|
|
1860
1868
|
exports.Strings = {
|