cafe-utility 27.10.0 → 27.11.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 -1
  2. package/index.js +74 -57
  3. package/package.json +1 -1
package/index.d.ts CHANGED
@@ -470,8 +470,13 @@ export declare class Optional<T> {
470
470
  static of<U>(value: U | null | undefined): Optional<U>;
471
471
  static empty<U>(): Optional<U>;
472
472
  map<K>(fn: (value: T) => K): Optional<K>;
473
+ mapAsync<K>(fn: (value: T) => Promise<K>): Promise<Optional<K>>;
473
474
  ifPresent(fn: (value: T) => void): this;
474
- orElse(fn: () => void): void;
475
+ ifPresentAsync(fn: (value: T) => Promise<void>): Promise<this>;
476
+ ifAbsent(fn: () => void): this;
477
+ ifAbsentAsync(fn: () => Promise<void>): Promise<this>;
478
+ getOrFallback(fn: () => T): T;
479
+ getOrFallbackAsync(fn: () => Promise<T>): Promise<T>;
475
480
  getOrThrow(): T;
476
481
  }
477
482
  export declare class Lazy<T> {
package/index.js CHANGED
@@ -172,7 +172,7 @@ function makePipe(n, e) {
172
172
  return t => pipe(t, n, e)
173
173
  }
174
174
  function pickWeighted(n, e, t) {
175
- if ((isUndefined(t) && (t = Math.random()), n.length !== e.length)) throw new Error('Array length mismatch')
175
+ if ((t === void 0 && (t = Math.random()), n.length !== e.length)) throw new Error('Array length mismatch')
176
176
  let r = e.reduce((i, u) => i + u, 0)
177
177
  const o = t * r
178
178
  for (let i = 0; i < n.length - 1; i++) if (((r -= e[i]), o >= r)) return n[i]
@@ -325,7 +325,7 @@ function isEmptyObject(n) {
325
325
  return isStrictlyObject(n) && Object.keys(n).length === 0
326
326
  }
327
327
  function isUndefined(n) {
328
- return typeof n > 'u'
328
+ return n === void 0
329
329
  }
330
330
  function isFunction(n) {
331
331
  return (
@@ -545,13 +545,13 @@ function asUrl(n, e) {
545
545
  return n
546
546
  }
547
547
  function isNullable(n, e) {
548
- return isUndefined(e) || e === null ? !0 : n(e)
548
+ return e == null ? !0 : n(e)
549
549
  }
550
550
  function asNullable(n, e) {
551
- return e === null || isUndefined(e) ? null : n(e)
551
+ return e == null ? null : n(e)
552
552
  }
553
553
  function asOptional(n, e) {
554
- if (e != null) return n(e)
554
+ return e == null ? void 0 : n(e)
555
555
  }
556
556
  function enforceObjectShape(n, e) {
557
557
  for (const [t, r] of Object.entries(e)) if (!r(n[t])) throw TypeError(`${t} in value does not exist or match shape`)
@@ -1803,7 +1803,7 @@ function removeEmptyArrays(n) {
1803
1803
  }
1804
1804
  function removeEmptyValues(n) {
1805
1805
  for (const e of Object.entries(n))
1806
- (isUndefined(e[1]) || e[1] === null || (isString(e[1]) && isBlank(e[1]))) && delete n[e[0]]
1806
+ (e[1] === null || e[1] === void 0 || (isString(e[1]) && isBlank(e[1]))) && delete n[e[0]]
1807
1807
  return n
1808
1808
  }
1809
1809
  function filterObjectKeys(n, e) {
@@ -1835,11 +1835,11 @@ async function rethrow(n, e) {
1835
1835
  }
1836
1836
  }
1837
1837
  function setSomeOnObject(n, e, t) {
1838
- typeof t < 'u' && t !== null && (n[e] = t)
1838
+ t != null && (n[e] = t)
1839
1839
  }
1840
1840
  function setSomeDeep(n, e, t, r) {
1841
1841
  const o = getDeep(t, r)
1842
- typeof o > 'u' || o === null || setDeep(n, e, o)
1842
+ o != null && setDeep(n, e, o)
1843
1843
  }
1844
1844
  function flip(n) {
1845
1845
  const e = {}
@@ -2027,11 +2027,28 @@ class Optional {
2027
2027
  map(e) {
2028
2028
  return new Optional(this.value !== null && this.value !== void 0 ? e(this.value) : null)
2029
2029
  }
2030
+ mapAsync(e) {
2031
+ return this.value !== null && this.value !== void 0
2032
+ ? e(this.value).then(t => Optional.of(t))
2033
+ : Promise.resolve(Optional.empty())
2034
+ }
2030
2035
  ifPresent(e) {
2031
2036
  return this.value !== null && this.value !== void 0 && e(this.value), this
2032
2037
  }
2033
- orElse(e) {
2034
- this.value ?? e()
2038
+ ifPresentAsync(e) {
2039
+ return this.value !== null && this.value !== void 0 ? e(this.value).then(() => this) : Promise.resolve(this)
2040
+ }
2041
+ ifAbsent(e) {
2042
+ return (this.value === null || this.value === void 0) && e(), this
2043
+ }
2044
+ ifAbsentAsync(e) {
2045
+ return this.value === null || this.value === void 0 ? e().then(() => this) : Promise.resolve(this)
2046
+ }
2047
+ getOrFallback(e) {
2048
+ return this.value ?? e()
2049
+ }
2050
+ getOrFallbackAsync(e) {
2051
+ return this.value !== null && this.value !== void 0 ? Promise.resolve(this.value) : e()
2035
2052
  }
2036
2053
  getOrThrow() {
2037
2054
  if (this.value === null || this.value === void 0) throw Error('Optional.value is empty')
@@ -2223,8 +2240,8 @@ function keccakPermutate(n) {
2223
2240
  a = n[9] ^ n[19] ^ n[29] ^ n[39] ^ n[49],
2224
2241
  h = (o << 1) | (i >>> 31),
2225
2242
  bn = (i << 1) | (o >>> 31),
2226
- p = l ^ h,
2227
- d = a ^ bn,
2243
+ d = l ^ h,
2244
+ p = a ^ bn,
2228
2245
  $n = (u << 1) | (s >>> 31),
2229
2246
  An = (s << 1) | (u >>> 31),
2230
2247
  m = t ^ $n,
@@ -2234,15 +2251,15 @@ function keccakPermutate(n) {
2234
2251
  w = o ^ En,
2235
2252
  y = i ^ Mn,
2236
2253
  On = (l << 1) | (a >>> 31),
2237
- Tn = (a << 1) | (l >>> 31),
2254
+ kn = (a << 1) | (l >>> 31),
2238
2255
  x = u ^ On,
2239
- b = s ^ Tn,
2240
- kn = (t << 1) | (r >>> 31),
2256
+ b = s ^ kn,
2257
+ Tn = (t << 1) | (r >>> 31),
2241
2258
  Sn = (r << 1) | (t >>> 31),
2242
- $ = c ^ kn,
2259
+ $ = c ^ Tn,
2243
2260
  A = f ^ Sn
2244
- ;(n[0] ^= p),
2245
- (n[1] ^= d),
2261
+ ;(n[0] ^= d),
2262
+ (n[1] ^= p),
2246
2263
  (n[2] ^= m),
2247
2264
  (n[3] ^= g),
2248
2265
  (n[4] ^= w),
@@ -2251,8 +2268,8 @@ function keccakPermutate(n) {
2251
2268
  (n[7] ^= b),
2252
2269
  (n[8] ^= $),
2253
2270
  (n[9] ^= A),
2254
- (n[10] ^= p),
2255
- (n[11] ^= d),
2271
+ (n[10] ^= d),
2272
+ (n[11] ^= p),
2256
2273
  (n[12] ^= m),
2257
2274
  (n[13] ^= g),
2258
2275
  (n[14] ^= w),
@@ -2261,8 +2278,8 @@ function keccakPermutate(n) {
2261
2278
  (n[17] ^= b),
2262
2279
  (n[18] ^= $),
2263
2280
  (n[19] ^= A),
2264
- (n[20] ^= p),
2265
- (n[21] ^= d),
2281
+ (n[20] ^= d),
2282
+ (n[21] ^= p),
2266
2283
  (n[22] ^= m),
2267
2284
  (n[23] ^= g),
2268
2285
  (n[24] ^= w),
@@ -2271,8 +2288,8 @@ function keccakPermutate(n) {
2271
2288
  (n[27] ^= b),
2272
2289
  (n[28] ^= $),
2273
2290
  (n[29] ^= A),
2274
- (n[30] ^= p),
2275
- (n[31] ^= d),
2291
+ (n[30] ^= d),
2292
+ (n[31] ^= p),
2276
2293
  (n[32] ^= m),
2277
2294
  (n[33] ^= g),
2278
2295
  (n[34] ^= w),
@@ -2281,8 +2298,8 @@ function keccakPermutate(n) {
2281
2298
  (n[37] ^= b),
2282
2299
  (n[38] ^= $),
2283
2300
  (n[39] ^= A),
2284
- (n[40] ^= p),
2285
- (n[41] ^= d),
2301
+ (n[40] ^= d),
2302
+ (n[41] ^= p),
2286
2303
  (n[42] ^= m),
2287
2304
  (n[43] ^= g),
2288
2305
  (n[44] ^= w),
@@ -2294,16 +2311,16 @@ function keccakPermutate(n) {
2294
2311
  const E = n[0],
2295
2312
  M = n[1],
2296
2313
  O = (n[2] << 1) | (n[3] >>> 31),
2297
- T = (n[3] << 1) | (n[2] >>> 31),
2298
- k = (n[5] << 30) | (n[4] >>> 2),
2314
+ k = (n[3] << 1) | (n[2] >>> 31),
2315
+ T = (n[5] << 30) | (n[4] >>> 2),
2299
2316
  S = (n[4] << 30) | (n[5] >>> 2),
2300
2317
  R = (n[6] << 28) | (n[7] >>> 4),
2301
2318
  C = (n[7] << 28) | (n[6] >>> 4),
2302
2319
  D = (n[8] << 27) | (n[9] >>> 5),
2303
2320
  I = (n[9] << 27) | (n[8] >>> 5),
2304
2321
  B = (n[11] << 4) | (n[10] >>> 28),
2305
- P = (n[10] << 4) | (n[11] >>> 28),
2306
- v = (n[13] << 12) | (n[12] >>> 20),
2322
+ v = (n[10] << 4) | (n[11] >>> 28),
2323
+ P = (n[13] << 12) | (n[12] >>> 20),
2307
2324
  U = (n[12] << 12) | (n[13] >>> 20),
2308
2325
  L = (n[14] << 6) | (n[15] >>> 26),
2309
2326
  N = (n[15] << 6) | (n[14] >>> 26),
@@ -2317,8 +2334,8 @@ function keccakPermutate(n) {
2317
2334
  J = (n[23] << 10) | (n[22] >>> 22),
2318
2335
  K = (n[25] << 11) | (n[24] >>> 21),
2319
2336
  Z = (n[24] << 11) | (n[25] >>> 21),
2320
- _ = (n[26] << 25) | (n[27] >>> 7),
2321
- Q = (n[27] << 25) | (n[26] >>> 7),
2337
+ Q = (n[26] << 25) | (n[27] >>> 7),
2338
+ _ = (n[27] << 25) | (n[26] >>> 7),
2322
2339
  G = (n[29] << 7) | (n[28] >>> 25),
2323
2340
  Y = (n[28] << 7) | (n[29] >>> 25),
2324
2341
  X = (n[31] << 9) | (n[30] >>> 23),
@@ -2334,63 +2351,63 @@ function keccakPermutate(n) {
2334
2351
  ln = (n[40] << 18) | (n[41] >>> 14),
2335
2352
  an = (n[41] << 18) | (n[40] >>> 14),
2336
2353
  hn = (n[42] << 2) | (n[43] >>> 30),
2337
- pn = (n[43] << 2) | (n[42] >>> 30),
2338
- dn = (n[45] << 29) | (n[44] >>> 3),
2354
+ dn = (n[43] << 2) | (n[42] >>> 30),
2355
+ pn = (n[45] << 29) | (n[44] >>> 3),
2339
2356
  mn = (n[44] << 29) | (n[45] >>> 3),
2340
2357
  gn = (n[47] << 24) | (n[46] >>> 8),
2341
2358
  wn = (n[46] << 24) | (n[47] >>> 8),
2342
2359
  yn = (n[48] << 14) | (n[49] >>> 18),
2343
2360
  xn = (n[49] << 14) | (n[48] >>> 18)
2344
- ;(n[0] = E ^ (~v & K)),
2361
+ ;(n[0] = E ^ (~P & K)),
2345
2362
  (n[1] = M ^ (~U & Z)),
2346
- (n[2] = v ^ (~K & un)),
2363
+ (n[2] = P ^ (~K & un)),
2347
2364
  (n[3] = U ^ (~Z & cn)),
2348
2365
  (n[4] = K ^ (~un & yn)),
2349
2366
  (n[5] = Z ^ (~cn & xn)),
2350
2367
  (n[6] = un ^ (~yn & E)),
2351
2368
  (n[7] = cn ^ (~xn & M)),
2352
- (n[8] = yn ^ (~E & v)),
2369
+ (n[8] = yn ^ (~E & P)),
2353
2370
  (n[9] = xn ^ (~M & U)),
2354
2371
  (n[10] = R ^ (~F & H)),
2355
2372
  (n[11] = C ^ (~q & W)),
2356
2373
  (n[12] = F ^ (~H & en)),
2357
2374
  (n[13] = q ^ (~W & tn)),
2358
- (n[14] = H ^ (~en & dn)),
2375
+ (n[14] = H ^ (~en & pn)),
2359
2376
  (n[15] = W ^ (~tn & mn)),
2360
- (n[16] = en ^ (~dn & R)),
2377
+ (n[16] = en ^ (~pn & R)),
2361
2378
  (n[17] = tn ^ (~mn & C)),
2362
- (n[18] = dn ^ (~R & F)),
2379
+ (n[18] = pn ^ (~R & F)),
2363
2380
  (n[19] = mn ^ (~C & q)),
2364
- (n[20] = O ^ (~L & _)),
2365
- (n[21] = T ^ (~N & Q)),
2366
- (n[22] = L ^ (~_ & sn)),
2367
- (n[23] = N ^ (~Q & fn)),
2368
- (n[24] = _ ^ (~sn & ln)),
2369
- (n[25] = Q ^ (~fn & an)),
2381
+ (n[20] = O ^ (~L & Q)),
2382
+ (n[21] = k ^ (~N & _)),
2383
+ (n[22] = L ^ (~Q & sn)),
2384
+ (n[23] = N ^ (~_ & fn)),
2385
+ (n[24] = Q ^ (~sn & ln)),
2386
+ (n[25] = _ ^ (~fn & an)),
2370
2387
  (n[26] = sn ^ (~ln & O)),
2371
- (n[27] = fn ^ (~an & T)),
2388
+ (n[27] = fn ^ (~an & k)),
2372
2389
  (n[28] = ln ^ (~O & L)),
2373
- (n[29] = an ^ (~T & N)),
2390
+ (n[29] = an ^ (~k & N)),
2374
2391
  (n[30] = D ^ (~B & V)),
2375
- (n[31] = I ^ (~P & J)),
2392
+ (n[31] = I ^ (~v & J)),
2376
2393
  (n[32] = B ^ (~V & rn)),
2377
- (n[33] = P ^ (~J & on)),
2394
+ (n[33] = v ^ (~J & on)),
2378
2395
  (n[34] = V ^ (~rn & gn)),
2379
2396
  (n[35] = J ^ (~on & wn)),
2380
2397
  (n[36] = rn ^ (~gn & D)),
2381
2398
  (n[37] = on ^ (~wn & I)),
2382
2399
  (n[38] = gn ^ (~D & B)),
2383
- (n[39] = wn ^ (~I & P)),
2384
- (n[40] = k ^ (~j & G)),
2400
+ (n[39] = wn ^ (~I & v)),
2401
+ (n[40] = T ^ (~j & G)),
2385
2402
  (n[41] = S ^ (~z & Y)),
2386
2403
  (n[42] = j ^ (~G & X)),
2387
2404
  (n[43] = z ^ (~Y & nn)),
2388
2405
  (n[44] = G ^ (~X & hn)),
2389
- (n[45] = Y ^ (~nn & pn)),
2390
- (n[46] = X ^ (~hn & k)),
2391
- (n[47] = nn ^ (~pn & S)),
2392
- (n[48] = hn ^ (~k & j)),
2393
- (n[49] = pn ^ (~S & z)),
2406
+ (n[45] = Y ^ (~nn & dn)),
2407
+ (n[46] = X ^ (~hn & T)),
2408
+ (n[47] = nn ^ (~dn & S)),
2409
+ (n[48] = hn ^ (~T & j)),
2410
+ (n[49] = dn ^ (~S & z)),
2394
2411
  (n[0] ^= IOTA_CONSTANTS[e * 2]),
2395
2412
  (n[1] ^= IOTA_CONSTANTS[e * 2 + 1])
2396
2413
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cafe-utility",
3
- "version": "27.10.0",
3
+ "version": "27.11.0",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "exports": {