cafe-utility 27.4.1 → 27.5.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 +6 -0
  2. package/index.js +20 -8
  3. package/package.json +1 -1
package/index.d.ts CHANGED
@@ -79,6 +79,11 @@ declare function randomUnicodeString(length: number, generator?: () => number):
79
79
  declare function searchHex(string: string, length: number): string | null;
80
80
  declare function searchSubstring(string: string, predicate: (string: string) => boolean, separators?: string[]): string | null;
81
81
  declare function randomHexString(length: number, generator?: () => number): string;
82
+ declare function asIntegerString(value: any, options?: {
83
+ name?: string;
84
+ min?: bigint;
85
+ max?: bigint;
86
+ }): string;
82
87
  declare function asString(string: any, options?: {
83
88
  name?: string;
84
89
  min?: number;
@@ -886,6 +891,7 @@ export declare const Types: {
886
891
  asString: typeof asString;
887
892
  asHexString: typeof asHexString;
888
893
  asSafeString: typeof asSafeString;
894
+ asIntegerString: typeof asIntegerString;
889
895
  asNumber: typeof asNumber;
890
896
  asInteger: typeof asInteger;
891
897
  asBoolean: typeof asBoolean;
package/index.js CHANGED
@@ -415,6 +415,17 @@ function randomHexString(n, e = Math.random) {
415
415
  for (let r = 0; r < n; r++) t += hexAlphabet[Math.floor(e() * hexAlphabet.length)]
416
416
  return t
417
417
  }
418
+ function asIntegerString(n, e) {
419
+ if (!isIntegerString(n)) throw new TypeError(`Expected integer string${e?.name ? ` for ${e.name}` : ''}, got: ` + n)
420
+ const t = BigInt(n)
421
+ if (e && ((e.min && t < e.min) || (e.max && t > e.max)))
422
+ throw RangeError(
423
+ `Expected integer string${e?.name ? ` for ${e.name}` : ''} in range: ${e.min ?? '-inf'}..${
424
+ e.max ?? 'inf'
425
+ }; got: ` + t
426
+ )
427
+ return n
428
+ }
418
429
  function asString(n, e) {
419
430
  if (isBlank(n)) throw new TypeError(`Expected string${e?.name ? ` for ${e.name}` : ''}, got: ` + n)
420
431
  if (e && ((e.min !== void 0 && n.length < e.min) || (e.max !== void 0 && n.length > e.max)))
@@ -2273,8 +2284,8 @@ function keccakPermutate(n) {
2273
2284
  B = (n[11] << 4) | (n[10] >>> 28),
2274
2285
  P = (n[10] << 4) | (n[11] >>> 28),
2275
2286
  U = (n[13] << 12) | (n[12] >>> 20),
2276
- v = (n[12] << 12) | (n[13] >>> 20),
2277
- L = (n[14] << 6) | (n[15] >>> 26),
2287
+ L = (n[12] << 12) | (n[13] >>> 20),
2288
+ v = (n[14] << 6) | (n[15] >>> 26),
2278
2289
  N = (n[15] << 6) | (n[14] >>> 26),
2279
2290
  j = (n[17] << 23) | (n[16] >>> 9),
2280
2291
  z = (n[16] << 23) | (n[17] >>> 9),
@@ -2311,15 +2322,15 @@ function keccakPermutate(n) {
2311
2322
  yn = (n[48] << 14) | (n[49] >>> 18),
2312
2323
  xn = (n[49] << 14) | (n[48] >>> 18)
2313
2324
  ;(n[0] = E ^ (~U & K)),
2314
- (n[1] = M ^ (~v & Z)),
2325
+ (n[1] = M ^ (~L & Z)),
2315
2326
  (n[2] = U ^ (~K & un)),
2316
- (n[3] = v ^ (~Z & cn)),
2327
+ (n[3] = L ^ (~Z & cn)),
2317
2328
  (n[4] = K ^ (~un & yn)),
2318
2329
  (n[5] = Z ^ (~cn & xn)),
2319
2330
  (n[6] = un ^ (~yn & E)),
2320
2331
  (n[7] = cn ^ (~xn & M)),
2321
2332
  (n[8] = yn ^ (~E & U)),
2322
- (n[9] = xn ^ (~M & v)),
2333
+ (n[9] = xn ^ (~M & L)),
2323
2334
  (n[10] = R ^ (~F & H)),
2324
2335
  (n[11] = C ^ (~q & W)),
2325
2336
  (n[12] = F ^ (~H & en)),
@@ -2330,15 +2341,15 @@ function keccakPermutate(n) {
2330
2341
  (n[17] = tn ^ (~mn & C)),
2331
2342
  (n[18] = dn ^ (~R & F)),
2332
2343
  (n[19] = mn ^ (~C & q)),
2333
- (n[20] = O ^ (~L & _)),
2344
+ (n[20] = O ^ (~v & _)),
2334
2345
  (n[21] = k ^ (~N & Q)),
2335
- (n[22] = L ^ (~_ & sn)),
2346
+ (n[22] = v ^ (~_ & sn)),
2336
2347
  (n[23] = N ^ (~Q & fn)),
2337
2348
  (n[24] = _ ^ (~sn & ln)),
2338
2349
  (n[25] = Q ^ (~fn & an)),
2339
2350
  (n[26] = sn ^ (~ln & O)),
2340
2351
  (n[27] = fn ^ (~an & k)),
2341
- (n[28] = ln ^ (~O & L)),
2352
+ (n[28] = ln ^ (~O & v)),
2342
2353
  (n[29] = an ^ (~k & N)),
2343
2354
  (n[30] = D ^ (~B & V)),
2344
2355
  (n[31] = I ^ (~P & J)),
@@ -3247,6 +3258,7 @@ class AsyncQueue {
3247
3258
  asString,
3248
3259
  asHexString,
3249
3260
  asSafeString,
3261
+ asIntegerString,
3250
3262
  asNumber,
3251
3263
  asInteger,
3252
3264
  asBoolean,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cafe-utility",
3
- "version": "27.4.1",
3
+ "version": "27.5.0",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "exports": {