cafe-utility 18.3.0 → 18.4.1
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 +9 -0
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -84,6 +84,8 @@ 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
86
|
declare function asNumericDictionary(value: any): Record<string, number>;
|
|
87
|
+
declare function isUrl(value: any): boolean;
|
|
88
|
+
declare function asUrl(value: any): string;
|
|
87
89
|
declare function isNullable(typeFn: (value: any) => boolean, value: any): boolean;
|
|
88
90
|
declare function asNullable<T>(typeFn: (value: any) => T, value: any): T | null;
|
|
89
91
|
declare function enforceObjectShape(value: Record<string, any>, shape: Record<string, (value: any) => boolean>): boolean;
|
|
@@ -609,6 +611,7 @@ export declare const Types: {
|
|
|
609
611
|
isDate: typeof isDate;
|
|
610
612
|
isBlank: typeof isBlank;
|
|
611
613
|
isId: typeof isId;
|
|
614
|
+
isUrl: typeof isUrl;
|
|
612
615
|
isNullable: typeof isNullable;
|
|
613
616
|
asString: typeof asString;
|
|
614
617
|
asSafeString: typeof asSafeString;
|
|
@@ -623,6 +626,7 @@ export declare const Types: {
|
|
|
623
626
|
asArray: typeof asArray;
|
|
624
627
|
asObject: typeof asObject;
|
|
625
628
|
asNumericDictionary: typeof asNumericDictionary;
|
|
629
|
+
asUrl: typeof asUrl;
|
|
626
630
|
asNullable: typeof asNullable;
|
|
627
631
|
enforceObjectShape: typeof enforceObjectShape;
|
|
628
632
|
enforceArrayShape: typeof enforceArrayShape;
|
package/index.js
CHANGED
|
@@ -430,6 +430,13 @@ function asNumericDictionary(n) {
|
|
|
430
430
|
if (!e.every(isString) || !r.every(isNumber)) throw new TypeError('Expected numeric dictionary, got: ' + n)
|
|
431
431
|
return t
|
|
432
432
|
}
|
|
433
|
+
function isUrl(n) {
|
|
434
|
+
return isString(n) && n.match(/^https?:\/\/.+/) !== null
|
|
435
|
+
}
|
|
436
|
+
function asUrl(n) {
|
|
437
|
+
if (!isUrl(n)) throw new TypeError('Expected url, got: ' + n)
|
|
438
|
+
return n
|
|
439
|
+
}
|
|
433
440
|
function isNullable(n, t) {
|
|
434
441
|
return isUndefined(t) || t === null ? !0 : n(t)
|
|
435
442
|
}
|
|
@@ -2238,6 +2245,7 @@ function raycastCircle(n, t, e) {
|
|
|
2238
2245
|
isDate,
|
|
2239
2246
|
isBlank,
|
|
2240
2247
|
isId,
|
|
2248
|
+
isUrl,
|
|
2241
2249
|
isNullable,
|
|
2242
2250
|
asString,
|
|
2243
2251
|
asSafeString,
|
|
@@ -2252,6 +2260,7 @@ function raycastCircle(n, t, e) {
|
|
|
2252
2260
|
asArray,
|
|
2253
2261
|
asObject,
|
|
2254
2262
|
asNumericDictionary,
|
|
2263
|
+
asUrl,
|
|
2255
2264
|
asNullable,
|
|
2256
2265
|
enforceObjectShape,
|
|
2257
2266
|
enforceArrayShape
|