cafe-utility 18.3.0 → 18.4.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.
Files changed (3) hide show
  1. package/index.d.ts +2 -0
  2. package/index.js +8 -0
  3. package/package.json +1 -1
package/index.d.ts CHANGED
@@ -84,6 +84,7 @@ 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 asUrl(value: any): string;
87
88
  declare function isNullable(typeFn: (value: any) => boolean, value: any): boolean;
88
89
  declare function asNullable<T>(typeFn: (value: any) => T, value: any): T | null;
89
90
  declare function enforceObjectShape(value: Record<string, any>, shape: Record<string, (value: any) => boolean>): boolean;
@@ -623,6 +624,7 @@ export declare const Types: {
623
624
  asArray: typeof asArray;
624
625
  asObject: typeof asObject;
625
626
  asNumericDictionary: typeof asNumericDictionary;
627
+ asUrl: typeof asUrl;
626
628
  asNullable: typeof asNullable;
627
629
  enforceObjectShape: typeof enforceObjectShape;
628
630
  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
  }
@@ -2252,6 +2259,7 @@ function raycastCircle(n, t, e) {
2252
2259
  asArray,
2253
2260
  asObject,
2254
2261
  asNumericDictionary,
2262
+ asUrl,
2255
2263
  asNullable,
2256
2264
  enforceObjectShape,
2257
2265
  enforceArrayShape
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cafe-utility",
3
- "version": "18.3.0",
3
+ "version": "18.4.0",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "exports": {