cafe-utility 27.5.1 → 27.7.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 +8 -0
  2. package/index.js +20 -8
  3. package/package.json +1 -1
package/index.d.ts CHANGED
@@ -98,6 +98,9 @@ declare function asSafeString(string: any, options?: {
98
98
  min?: number;
99
99
  max?: number;
100
100
  }): string;
101
+ declare function asFunction(value: any, options?: {
102
+ name: string;
103
+ }): Function;
101
104
  declare function asNumber(number: any, options?: {
102
105
  name?: string;
103
106
  min?: number;
@@ -133,6 +136,9 @@ declare function asObject(value: any, options?: {
133
136
  declare function asNullableObject(value: any, options?: {
134
137
  name: string;
135
138
  }): Record<string, unknown> | null;
139
+ declare function asStringMap(value: any, options?: {
140
+ name: string;
141
+ }): Record<string, string>;
136
142
  declare function asNumericDictionary(value: any, options?: {
137
143
  name: string;
138
144
  }): Record<string, number>;
@@ -893,6 +899,7 @@ export declare const Types: {
893
899
  asSafeString: typeof asSafeString;
894
900
  asIntegerString: typeof asIntegerString;
895
901
  asNumber: typeof asNumber;
902
+ asFunction: typeof asFunction;
896
903
  asInteger: typeof asInteger;
897
904
  asBoolean: typeof asBoolean;
898
905
  asDate: typeof asDate;
@@ -903,6 +910,7 @@ export declare const Types: {
903
910
  asArray: typeof asArray;
904
911
  asObject: typeof asObject;
905
912
  asNullableObject: typeof asNullableObject;
913
+ asStringMap: typeof asStringMap;
906
914
  asNumericDictionary: typeof asNumericDictionary;
907
915
  asUrl: typeof asUrl;
908
916
  asNullable: typeof asNullable;
package/index.js CHANGED
@@ -462,6 +462,10 @@ function checkLimits(n, e) {
462
462
  }; got: ${n}`
463
463
  )
464
464
  }
465
+ function asFunction(n, e) {
466
+ if (!isFunction(n)) throw new TypeError(`Expected function${e?.name ? ` for ${e.name}` : ''}, got: ` + n)
467
+ return n
468
+ }
465
469
  function asNumber(n, e) {
466
470
  if (isNumber(n)) return e && checkLimits(n, e), n
467
471
  if (!isString(n) || !n.match(/^-?\d+(\.\d+)?$/))
@@ -516,6 +520,12 @@ function asObject(n, e) {
516
520
  function asNullableObject(n, e) {
517
521
  return n === null ? null : asObject(n, e)
518
522
  }
523
+ function asStringMap(n, e) {
524
+ const t = asObject(n, e)
525
+ for (const r of Object.keys(t))
526
+ if (!isString(t[r])) throw new TypeError(`Expected string map${e?.name ? ` for ${e.name}` : ''}, got: ` + n)
527
+ return t
528
+ }
519
529
  function asNumericDictionary(n, e) {
520
530
  const t = asObject(n),
521
531
  r = Object.keys(t),
@@ -2285,8 +2295,8 @@ function keccakPermutate(n) {
2285
2295
  P = (n[10] << 4) | (n[11] >>> 28),
2286
2296
  U = (n[13] << 12) | (n[12] >>> 20),
2287
2297
  L = (n[12] << 12) | (n[13] >>> 20),
2288
- v = (n[14] << 6) | (n[15] >>> 26),
2289
- N = (n[15] << 6) | (n[14] >>> 26),
2298
+ N = (n[14] << 6) | (n[15] >>> 26),
2299
+ v = (n[15] << 6) | (n[14] >>> 26),
2290
2300
  j = (n[17] << 23) | (n[16] >>> 9),
2291
2301
  z = (n[16] << 23) | (n[17] >>> 9),
2292
2302
  F = (n[18] << 20) | (n[19] >>> 12),
@@ -2341,16 +2351,16 @@ function keccakPermutate(n) {
2341
2351
  (n[17] = tn ^ (~mn & C)),
2342
2352
  (n[18] = dn ^ (~R & F)),
2343
2353
  (n[19] = mn ^ (~C & q)),
2344
- (n[20] = O ^ (~v & _)),
2345
- (n[21] = k ^ (~N & Q)),
2346
- (n[22] = v ^ (~_ & sn)),
2347
- (n[23] = N ^ (~Q & fn)),
2354
+ (n[20] = O ^ (~N & _)),
2355
+ (n[21] = k ^ (~v & Q)),
2356
+ (n[22] = N ^ (~_ & sn)),
2357
+ (n[23] = v ^ (~Q & fn)),
2348
2358
  (n[24] = _ ^ (~sn & ln)),
2349
2359
  (n[25] = Q ^ (~fn & an)),
2350
2360
  (n[26] = sn ^ (~ln & O)),
2351
2361
  (n[27] = fn ^ (~an & k)),
2352
- (n[28] = ln ^ (~O & v)),
2353
- (n[29] = an ^ (~k & N)),
2362
+ (n[28] = ln ^ (~O & N)),
2363
+ (n[29] = an ^ (~k & v)),
2354
2364
  (n[30] = D ^ (~B & V)),
2355
2365
  (n[31] = I ^ (~P & J)),
2356
2366
  (n[32] = B ^ (~V & rn)),
@@ -3261,6 +3271,7 @@ class AsyncQueue {
3261
3271
  asSafeString,
3262
3272
  asIntegerString,
3263
3273
  asNumber,
3274
+ asFunction,
3264
3275
  asInteger,
3265
3276
  asBoolean,
3266
3277
  asDate,
@@ -3271,6 +3282,7 @@ class AsyncQueue {
3271
3282
  asArray,
3272
3283
  asObject,
3273
3284
  asNullableObject,
3285
+ asStringMap,
3274
3286
  asNumericDictionary,
3275
3287
  asUrl,
3276
3288
  asNullable,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cafe-utility",
3
- "version": "27.5.1",
3
+ "version": "27.7.0",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "exports": {