cafe-utility 22.2.1 → 22.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 +43 -14
  2. package/index.js +176 -161
  3. package/package.json +1 -1
package/index.d.ts CHANGED
@@ -26,6 +26,7 @@ interface Rectangle {
26
26
  height: number;
27
27
  }
28
28
  declare function randomPoint(width: number, height: number, exclude?: Rectangle, generator?: () => number): [number, number];
29
+ declare function procs(probabilty: number, generator?: () => number): number;
29
30
  declare function chance(threshold: number, generator?: () => number): boolean;
30
31
  declare function pick<T>(array: T[], generator?: () => number): T;
31
32
  declare function pickMany<T>(array: T[], count: number, generator?: () => number): T[];
@@ -75,31 +76,58 @@ declare function randomUnicodeString(length: number, generator?: () => number):
75
76
  declare function searchHex(string: string, length: number): string | null;
76
77
  declare function searchSubstring(string: string, predicate: (string: string) => boolean, separators?: string[]): string | null;
77
78
  declare function randomHexString(length: number, generator?: () => number): string;
78
- declare function asString(string: any, limits?: {
79
+ declare function asString(string: any, options?: {
80
+ name?: string;
79
81
  min?: number;
80
82
  max?: number;
81
83
  }): string;
82
- declare function asSafeString(string: any): string;
83
- declare function asNumber(number: any, limits?: {
84
+ declare function asSafeString(string: any, options?: {
85
+ name?: string;
86
+ min?: number;
87
+ max?: number;
88
+ }): string;
89
+ declare function asNumber(number: any, options?: {
90
+ name?: string;
84
91
  min?: number;
85
92
  max?: number;
86
93
  }): number;
87
- declare function asInteger(number: any, limits?: {
94
+ declare function asInteger(number: any, options?: {
95
+ name?: string;
88
96
  min?: number;
89
97
  max?: number;
90
98
  }): number;
91
- declare function asBoolean(bool: any): boolean;
92
- declare function asDate(date: any): Date;
99
+ declare function asBoolean(bool: any, options?: {
100
+ name: string;
101
+ }): boolean;
102
+ declare function asDate(date: any, options?: {
103
+ name: string;
104
+ }): Date;
93
105
  declare function asNullableString(string: any): string | null;
94
- declare function asEmptiableString(string: any): string;
95
- declare function asId(value: any): number;
96
- declare function asTime(value: any): string;
97
- declare function asArray(value: any): unknown[];
98
- declare function asObject(value: any): Record<string, unknown>;
99
- declare function asNullableObject(value: any): Record<string, unknown> | null;
100
- declare function asNumericDictionary(value: any): Record<string, number>;
106
+ declare function asEmptiableString(string: any, options?: {
107
+ name: string;
108
+ }): string;
109
+ declare function asId(value: any, options?: {
110
+ name: string;
111
+ }): number;
112
+ declare function asTime(value: any, options?: {
113
+ name: string;
114
+ }): string;
115
+ declare function asArray(value: any, options?: {
116
+ name: string;
117
+ }): unknown[];
118
+ declare function asObject(value: any, options?: {
119
+ name: string;
120
+ }): Record<string, unknown>;
121
+ declare function asNullableObject(value: any, options?: {
122
+ name: string;
123
+ }): Record<string, unknown> | null;
124
+ declare function asNumericDictionary(value: any, options?: {
125
+ name: string;
126
+ }): Record<string, number>;
101
127
  declare function isUrl(value: any): boolean;
102
- declare function asUrl(value: any): string;
128
+ declare function asUrl(value: any, options?: {
129
+ name: string;
130
+ }): string;
103
131
  declare function isNullable(typeFn: (value: any) => boolean, value: any): boolean;
104
132
  declare function asNullable<T>(typeFn: (value: any) => T, value: any): T | null;
105
133
  declare function enforceObjectShape(value: Record<string, any>, shape: Record<string, (value: any) => boolean>): boolean;
@@ -533,6 +561,7 @@ export declare const Random: {
533
561
  signed: typeof signedRandom;
534
562
  makeSeededRng: typeof makeSeededRng;
535
563
  point: typeof randomPoint;
564
+ procs: typeof procs;
536
565
  };
537
566
  export declare const Arrays: {
538
567
  countUnique: typeof countUnique;
package/index.js CHANGED
@@ -117,6 +117,11 @@ function randomPoint(n, t, e, r = Math.random) {
117
117
  while (e && containsPoint(e, o, i))
118
118
  return [o, i]
119
119
  }
120
+ function procs(n, t = Math.random) {
121
+ const e = Math.floor(n),
122
+ r = n - e
123
+ return chance(r, t) ? e + 1 : e
124
+ }
120
125
  function chance(n, t = Math.random) {
121
126
  return t() < n
122
127
  }
@@ -137,13 +142,13 @@ function pickManyUnique(n, t, e, r = Math.random) {
137
142
  return o
138
143
  }
139
144
  function pickGuaranteed(n, t, e, r, o, i = Math.random) {
140
- const u = n.filter(s => s !== t && s !== e),
141
- c = []
142
- for (t !== null && c.push(t); u.length && c.length < r; ) {
143
- const s = exports.Random.intBetween(0, u.length - 1, i)
144
- o(u[s], c) && c.push(u[s]), u.splice(s, 1)
145
+ const u = n.filter(c => c !== t && c !== e),
146
+ s = []
147
+ for (t !== null && s.push(t); u.length && s.length < r; ) {
148
+ const c = exports.Random.intBetween(0, u.length - 1, i)
149
+ o(u[c], s) && s.push(u[c]), u.splice(c, 1)
145
150
  }
146
- return shuffle(c, i), { values: c, indexOfGuaranteed: t !== null ? c.indexOf(t) : -1 }
151
+ return shuffle(s, i), { values: s, indexOfGuaranteed: t !== null ? s.indexOf(t) : -1 }
147
152
  }
148
153
  function last(n) {
149
154
  if (!n.length) throw Error('Received empty array')
@@ -183,10 +188,10 @@ function setDeep(n, t, e) {
183
188
  let o = n
184
189
  for (let i = 0; i < r.length; i++) {
185
190
  const u = r[i],
186
- c = i < r.length - 1 && r[i + 1].includes(']'),
191
+ s = i < r.length - 1 && r[i + 1].includes(']'),
187
192
  f = u.includes(']') ? u.replace(/\[|\]/g, '') : u
188
193
  if (i === r.length - 1) return (o[f] = e), e
189
- isObject(o[f]) || (c ? (o[f] = []) : (o[f] = {})), (o = o[f])
194
+ isObject(o[f]) || (s ? (o[f] = []) : (o[f] = {})), (o = o[f])
190
195
  }
191
196
  return e
192
197
  }
@@ -253,9 +258,9 @@ function rgbToHex(n) {
253
258
  function haversineDistanceToMeters(n, t, e, r) {
254
259
  const i = (n * Math.PI) / 180,
255
260
  u = (e * Math.PI) / 180,
256
- c = ((e - n) * Math.PI) / 180,
257
- s = ((r - t) * Math.PI) / 180,
258
- f = Math.sin(c / 2) * Math.sin(c / 2) + Math.cos(i) * Math.cos(u) * Math.sin(s / 2) * Math.sin(s / 2)
261
+ s = ((e - n) * Math.PI) / 180,
262
+ c = ((r - t) * Math.PI) / 180,
263
+ f = Math.sin(s / 2) * Math.sin(s / 2) + Math.cos(i) * Math.cos(u) * Math.sin(c / 2) * Math.sin(c / 2)
259
264
  return 6371e3 * (2 * Math.atan2(Math.sqrt(f), Math.sqrt(1 - f)))
260
265
  }
261
266
  function roundToNearest(n, t) {
@@ -384,98 +389,100 @@ function randomHexString(n, t = Math.random) {
384
389
  }
385
390
  function asString(n, t) {
386
391
  var e, r
387
- if (isBlank(n)) throw new TypeError('Expected string, got: ' + n)
392
+ if (isBlank(n)) throw new TypeError(`Expected string${t?.name ? ` for ${t.name}` : ''}, got: ` + n)
388
393
  if (t && ((t.min !== void 0 && n.length < t.min) || (t.max !== void 0 && n.length > t.max)))
389
394
  throw RangeError(
390
- `Expected string length in range: ${(e = t.min) !== null && e !== void 0 ? e : '-inf'}..${
391
- (r = t.max) !== null && r !== void 0 ? r : 'inf'
392
- }; got: ${n.length}`
395
+ `Expected string${t?.name ? ` for ${t.name}` : ''} length in range: ${
396
+ (e = t.min) !== null && e !== void 0 ? e : '-inf'
397
+ }..${(r = t.max) !== null && r !== void 0 ? r : 'inf'}; got: ${n.length}`
393
398
  )
394
399
  return n
395
400
  }
396
- function asSafeString(n) {
401
+ function asSafeString(n, t) {
397
402
  if (
398
- !asString(n)
403
+ !asString(n, t)
399
404
  .split('')
400
- .every(t => t === '_' || isLetterOrDigit(t))
405
+ .every(e => e === '_' || isLetterOrDigit(e))
401
406
  )
402
- throw new TypeError('Expected safe string, got: ' + n)
407
+ throw new TypeError(`Expected safe string${t?.name ? ` for ${t.name}` : ''}, got: ` + n)
403
408
  return n
404
409
  }
405
410
  function checkLimits(n, t) {
406
411
  var e, r
407
412
  if ((t.min !== void 0 && n < t.min) || (t.max !== void 0 && n > t.max))
408
413
  throw RangeError(
409
- `Expected value in range: ${(e = t.min) !== null && e !== void 0 ? e : '-inf'}..${
410
- (r = t.max) !== null && r !== void 0 ? r : 'inf'
411
- }; got: ${n}`
414
+ `Expected value${t?.name ? ` for ${t.name}` : ''} in range: ${
415
+ (e = t.min) !== null && e !== void 0 ? e : '-inf'
416
+ }..${(r = t.max) !== null && r !== void 0 ? r : 'inf'}; got: ${n}`
412
417
  )
413
418
  }
414
419
  function asNumber(n, t) {
415
420
  if (isNumber(n)) return t && checkLimits(n, t), n
416
- if (!isString(n) || !n.match(/^-?\d+(\.\d+)?$/)) throw new TypeError('Expected number, got: ' + n)
421
+ if (!isString(n) || !n.match(/^-?\d+(\.\d+)?$/))
422
+ throw new TypeError(`Expected number${t?.name ? ` for ${t.name}` : ''}, got: ` + n)
417
423
  const e = parseFloat(n)
418
424
  return t && checkLimits(e, t), e
419
425
  }
420
426
  function asInteger(n, t) {
421
427
  return asNumber(n, t) | 0
422
428
  }
423
- function asBoolean(n) {
429
+ function asBoolean(n, t) {
424
430
  if (n === 'true') return !0
425
431
  if (n === 'false') return !1
426
- if (!isBoolean(n)) throw new TypeError('Expected boolean, got: ' + n)
432
+ if (!isBoolean(n)) throw new TypeError(`Expected boolean${t?.name ? ` for ${t.name}` : ''}, got: ` + n)
427
433
  return n
428
434
  }
429
- function asDate(n) {
430
- if (!isDate(n)) throw new TypeError('Expected date, got: ' + n)
435
+ function asDate(n, t) {
436
+ if (!isDate(n)) throw new TypeError(`Expected date${t?.name ? ` for ${t.name}` : ''}, got: ` + n)
431
437
  return n
432
438
  }
433
439
  function asNullableString(n) {
434
440
  return isBlank(n) ? null : n
435
441
  }
436
- function asEmptiableString(n) {
437
- if (!isString(n)) throw new TypeError('Expected string, got: ' + n)
442
+ function asEmptiableString(n, t) {
443
+ if (!isString(n)) throw new TypeError(`Expected string${t?.name ? ` for ${t.name}` : ''}, got: ` + n)
438
444
  return n
439
445
  }
440
- function asId(n) {
446
+ function asId(n, t) {
441
447
  if (isId(n)) return n
442
- const t = parseInt(n, 10)
443
- if (!isId(t)) throw new TypeError('Expected id, got: ' + n)
444
- return t
448
+ const e = parseInt(n, 10)
449
+ if (!isId(e)) throw new TypeError(`Expected id${t?.name ? ` for ${t.name}` : ''}, got: ` + n)
450
+ return e
445
451
  }
446
- function asTime(n) {
447
- if (!isString(n)) throw new TypeError('Expected time, got: ' + n)
448
- const t = n.split(':')
449
- if (t.length !== 2) throw new TypeError('Expected time, got: ' + n)
450
- const e = parseInt(t[0], 10),
451
- r = parseInt(t[1], 10)
452
- if (!isNumber(e) || !isNumber(r) || e < 0 || e > 23 || r < 0 || r > 59)
453
- throw new TypeError('Expected time, got: ' + n)
454
- return `${String(e).padStart(2, '0')}:${String(r).padStart(2, '0')}`
455
- }
456
- function asArray(n) {
457
- if (!Array.isArray(n)) throw new TypeError('Expected array, got: ' + n)
452
+ function asTime(n, t) {
453
+ if (!isString(n)) throw new TypeError(`Expected time${t?.name ? ` for ${t.name}` : ''}, got: ` + n)
454
+ const e = n.split(':')
455
+ if (e.length !== 2) throw new TypeError(`Expected time${t?.name ? ` for ${t.name}` : ''}, got: ` + n)
456
+ const r = parseInt(e[0], 10),
457
+ o = parseInt(e[1], 10)
458
+ if (!isNumber(r) || !isNumber(o) || r < 0 || r > 23 || o < 0 || o > 59)
459
+ throw new TypeError(`Expected time, got${t?.name ? ` for ${t.name}` : ''}: ` + n)
460
+ return `${String(r).padStart(2, '0')}:${String(o).padStart(2, '0')}`
461
+ }
462
+ function asArray(n, t) {
463
+ if (!Array.isArray(n)) throw new TypeError(`Expected array${t?.name ? ` for ${t.name}` : ''}, got: ` + n)
458
464
  return n
459
465
  }
460
- function asObject(n) {
461
- if (!isStrictlyObject(n)) throw new TypeError('Expected object, got: ' + n)
466
+ function asObject(n, t) {
467
+ if (!isStrictlyObject(n)) throw new TypeError(`Expected object${t?.name ? ` for ${t.name}` : ''}, got: ` + n)
462
468
  return n
463
469
  }
464
- function asNullableObject(n) {
465
- return n === null ? null : asObject(n)
470
+ function asNullableObject(n, t) {
471
+ return n === null ? null : asObject(n, t)
466
472
  }
467
- function asNumericDictionary(n) {
468
- const t = asObject(n),
469
- e = Object.keys(t),
470
- r = Object.values(t)
471
- if (!e.every(isString) || !r.every(isNumber)) throw new TypeError('Expected numeric dictionary, got: ' + n)
472
- return t
473
+ function asNumericDictionary(n, t) {
474
+ const e = asObject(n),
475
+ r = Object.keys(e),
476
+ o = Object.values(e)
477
+ if (!r.every(isString) || !o.every(isNumber))
478
+ throw new TypeError(`Expected numeric dictionary${t?.name ? ` for ${t.name}` : ''}, got: ` + n)
479
+ return e
473
480
  }
474
481
  function isUrl(n) {
475
482
  return isString(n) && n.match(/^https?:\/\/.+/) !== null
476
483
  }
477
- function asUrl(n) {
478
- if (!isUrl(n)) throw new TypeError('Expected url, got: ' + n)
484
+ function asUrl(n, t) {
485
+ if (!isUrl(n)) throw new TypeError(`Expected url${t?.name ? ` for ${t.name}` : ''}, got: ` + n)
479
486
  return n
480
487
  }
481
488
  function isNullable(n, t) {
@@ -772,9 +779,9 @@ function expand(n) {
772
779
  o = n.slice(0, e.index),
773
780
  i = n.slice(e.index + e[0].length)
774
781
  let u = []
775
- for (const c of r) {
776
- const s = expand(o + c + i)
777
- u = u.concat(s)
782
+ for (const s of r) {
783
+ const c = expand(o + s + i)
784
+ u = u.concat(c)
778
785
  }
779
786
  return u
780
787
  }
@@ -1008,12 +1015,12 @@ function base64ToUint8Array(n) {
1008
1015
  i = 0
1009
1016
  for (; o < n.length; ) {
1010
1017
  const u = BASE64_CHARS.indexOf(n.charAt(o++)),
1011
- c = BASE64_CHARS.indexOf(n.charAt(o++)),
1012
1018
  s = BASE64_CHARS.indexOf(n.charAt(o++)),
1019
+ c = BASE64_CHARS.indexOf(n.charAt(o++)),
1013
1020
  f = BASE64_CHARS.indexOf(n.charAt(o++)),
1014
- l = (u << 2) | (c >> 4),
1015
- a = ((c & 15) << 4) | (s >> 2),
1016
- h = ((s & 3) << 6) | f
1021
+ l = (u << 2) | (s >> 4),
1022
+ a = ((s & 15) << 4) | (c >> 2),
1023
+ h = ((c & 3) << 6) | f
1017
1024
  ;(r[i++] = l), i < e && (r[i++] = a), i < e && (r[i++] = h)
1018
1025
  }
1019
1026
  return r
@@ -1025,11 +1032,11 @@ function uint8ArrayToBase64(n) {
1025
1032
  const o = n[r],
1026
1033
  i = n[r + 1],
1027
1034
  u = n[r + 2],
1028
- c = o >> 2,
1029
- s = ((o & 3) << 4) | (i >> 4),
1035
+ s = o >> 2,
1036
+ c = ((o & 3) << 4) | (i >> 4),
1030
1037
  f = ((i & 15) << 2) | (u >> 6),
1031
1038
  l = u & 63
1032
- ;(t += BASE64_CHARS[c] + BASE64_CHARS[s]),
1039
+ ;(t += BASE64_CHARS[s] + BASE64_CHARS[c]),
1033
1040
  r + 1 < n.length ? (t += BASE64_CHARS[f]) : e++,
1034
1041
  r + 2 < n.length ? (t += BASE64_CHARS[l]) : e++
1035
1042
  }
@@ -1071,7 +1078,7 @@ function generateVariants(n, t, e, r = Math.random) {
1071
1078
  const o = exports.Arrays.shuffle(
1072
1079
  t.map(u => ({
1073
1080
  variants: exports.Arrays.shuffle(
1074
- u.variants.map(c => c),
1081
+ u.variants.map(s => s),
1075
1082
  r
1076
1083
  ),
1077
1084
  avoid: u.avoid
@@ -1080,14 +1087,14 @@ function generateVariants(n, t, e, r = Math.random) {
1080
1087
  ),
1081
1088
  i = []
1082
1089
  for (const u of o) {
1083
- const c = u.variants.filter(f => f !== u.avoid),
1084
- s = c.find(f => n.includes(f))
1085
- if (s && (pushAll(i, explodeReplace(n, s, c)), i.length >= e)) break
1090
+ const s = u.variants.filter(f => f !== u.avoid),
1091
+ c = s.find(f => n.includes(f))
1092
+ if (c && (pushAll(i, explodeReplace(n, c, s)), i.length >= e)) break
1086
1093
  }
1087
1094
  if (i.length < e)
1088
1095
  for (const u of o) {
1089
- const c = u.variants.find(s => n.includes(s))
1090
- if (c && (pushAll(i, explodeReplace(n, c, u.variants)), i.length >= e)) break
1096
+ const s = u.variants.find(c => n.includes(c))
1097
+ if (s && (pushAll(i, explodeReplace(n, s, u.variants)), i.length >= e)) break
1091
1098
  }
1092
1099
  return i.slice(0, e)
1093
1100
  }
@@ -1122,9 +1129,9 @@ function toLines(n, t, e = {}) {
1122
1129
  let o = '',
1123
1130
  i = 0
1124
1131
  for (let u = 0; u < n.length; u++) {
1125
- const c = n[u],
1126
- s = e[c] || 1
1127
- if (((o += c), (i += s), i > t)) {
1132
+ const s = n[u],
1133
+ c = e[s] || 1
1134
+ if (((o += s), (i += c), i > t)) {
1128
1135
  const { line: f, rest: l } = breakLine(o)
1129
1136
  r.push(f),
1130
1137
  (o = l),
@@ -1179,8 +1186,8 @@ function resolveVariableWithDefaultSyntax(n, t, e, r = '$', o = ':') {
1179
1186
  if (n[i + t.length + 1] === o)
1180
1187
  if (n[i + t.length + 2] === o) n = n.replace(`${r}${t}${o}${o}`, e)
1181
1188
  else {
1182
- const c = readNextWord(n, i + t.length + 2, ['_'])
1183
- n = n.replace(`${r}${t}${o}${c}`, e)
1189
+ const s = readNextWord(n, i + t.length + 2, ['_'])
1190
+ n = n.replace(`${r}${t}${o}${s}`, e)
1184
1191
  }
1185
1192
  else n = n.replace(`${r}${t}`, e)
1186
1193
  i = n.indexOf(`${r}${t}`, i + e.length)
@@ -1208,8 +1215,8 @@ function resolveMarkdownLinks(n, t) {
1208
1215
  o = n.indexOf(')', e)
1209
1216
  if (r !== -1 && o !== -1) {
1210
1217
  const [i, u] = n.slice(r + 1, o).split(']('),
1211
- c = t(i, u)
1212
- n = n.slice(0, r) + c + n.slice(o + 1)
1218
+ s = t(i, u)
1219
+ n = n.slice(0, r) + s + n.slice(o + 1)
1213
1220
  }
1214
1221
  e = n.indexOf('](', e + 1)
1215
1222
  }
@@ -1247,8 +1254,8 @@ function reposition(n, t, e, r) {
1247
1254
  const o = n.find(u => u[t] === e),
1248
1255
  i = n.find(u => u[t] === e + r)
1249
1256
  o && i ? ((o[t] = e + r), (i[t] = e)) : o && (o[t] = e + r),
1250
- n.sort((u, c) => asNumber(u[t]) - asNumber(c[t])),
1251
- n.forEach((u, c) => (u[t] = c + 1))
1257
+ n.sort((u, s) => asNumber(u[t]) - asNumber(s[t])),
1258
+ n.forEach((u, s) => (u[t] = s + 1))
1252
1259
  }
1253
1260
  function unwrapSingleKey(n) {
1254
1261
  const t = Object.keys(n)
@@ -1263,7 +1270,7 @@ function parseCsv(n, t = ',', e = '"') {
1263
1270
  let o = '',
1264
1271
  i = !1
1265
1272
  const u = n.split('')
1266
- for (const c of u) c === t && !i ? (r.push(o), (o = '')) : c === e && ((!o && !i) || i) ? (i = !i) : (o += c)
1273
+ for (const s of u) s === t && !i ? (r.push(o), (o = '')) : s === e && ((!o && !i) || i) ? (i = !i) : (o += s)
1267
1274
  return r.push(o), r
1268
1275
  }
1269
1276
  function humanizeProgress(n) {
@@ -1381,12 +1388,12 @@ function secondsToHumanTime(n, t = DefaultTimeDeltaLabels) {
1381
1388
  }
1382
1389
  function countCycles(n, t, e) {
1383
1390
  var r, o, i
1384
- const c = ((r = e?.now) !== null && r !== void 0 ? r : Date.now()) - n,
1385
- s = Math.floor(c / t),
1391
+ const s = ((r = e?.now) !== null && r !== void 0 ? r : Date.now()) - n,
1392
+ c = Math.floor(s / t),
1386
1393
  f =
1387
1394
  t / ((o = e?.precision) !== null && o !== void 0 ? o : 1) -
1388
- Math.ceil((c % t) / ((i = e?.precision) !== null && i !== void 0 ? i : 1))
1389
- return { cycles: s, remaining: f }
1395
+ Math.ceil((s % t) / ((i = e?.precision) !== null && i !== void 0 ? i : 1))
1396
+ return { cycles: c, remaining: f }
1390
1397
  }
1391
1398
  const throttleTimers = {}
1392
1399
  function throttle(n, t) {
@@ -1403,9 +1410,9 @@ function getProgress(n, t, e, r) {
1403
1410
  const o = t / e,
1404
1411
  i = r - n,
1405
1412
  u = i / t,
1406
- c = u * e,
1407
- s = c - i
1408
- return { deltaMs: i, progress: o, baseTimeMs: u, totalTimeMs: c, remainingTimeMs: s }
1413
+ s = u * e,
1414
+ c = s - i
1415
+ return { deltaMs: i, progress: o, baseTimeMs: u, totalTimeMs: s, remainingTimeMs: c }
1409
1416
  }
1410
1417
  const dayNumberIndex = {
1411
1418
  0: 'sunday',
@@ -1570,9 +1577,9 @@ function organiseWithLimits(n, t, e, r, o) {
1570
1577
  for (const u of Object.keys(t)) i[u] = []
1571
1578
  ;(i[r] = []), o && (n = n.sort(o))
1572
1579
  for (const u of n) {
1573
- const c = u[e],
1574
- s = t[c] ? c : r
1575
- i[s].length >= t[s] ? i[r].push(u) : i[s].push(u)
1580
+ const s = u[e],
1581
+ c = t[s] ? s : r
1582
+ i[c].length >= t[c] ? i[r].push(u) : i[c].push(u)
1576
1583
  }
1577
1584
  return i
1578
1585
  }
@@ -1641,11 +1648,11 @@ function formatNumber(n, t) {
1641
1648
  const o = (e = t?.longForm) !== null && e !== void 0 ? e : !1,
1642
1649
  i = t?.unit ? ` ${t.unit}` : '',
1643
1650
  u = o ? longNumberUnits : shortNumberUnits,
1644
- c = (r = t?.precision) !== null && r !== void 0 ? r : 1
1651
+ s = (r = t?.precision) !== null && r !== void 0 ? r : 1
1645
1652
  if (n < thresholds[0]) return `${n}${i}`
1646
- for (let s = 0; s < thresholds.length - 1; s++)
1647
- if (n < thresholds[s + 1]) return `${(n / thresholds[s]).toFixed(c)}${o ? ' ' : ''}${u[s]}${i}`
1648
- return `${(n / thresholds[thresholds.length - 1]).toFixed(c)}${o ? ' ' : ''}${u[thresholds.length - 1]}${i}`
1653
+ for (let c = 0; c < thresholds.length - 1; c++)
1654
+ if (n < thresholds[c + 1]) return `${(n / thresholds[c]).toFixed(s)}${o ? ' ' : ''}${u[c]}${i}`
1655
+ return `${(n / thresholds[thresholds.length - 1]).toFixed(s)}${o ? ' ' : ''}${u[thresholds.length - 1]}${i}`
1649
1656
  }
1650
1657
  function makeNumber(n) {
1651
1658
  const t = parseFloat(n)
@@ -1724,20 +1731,20 @@ function flip(n) {
1724
1731
  }
1725
1732
  function getAllPermutations(n) {
1726
1733
  const t = Object.keys(n),
1727
- e = t.map(c => n[c].length),
1728
- r = e.reduce((c, s) => (c *= s))
1734
+ e = t.map(s => n[s].length),
1735
+ r = e.reduce((s, c) => (s *= c))
1729
1736
  let o = 1
1730
1737
  const i = [1]
1731
- for (let c = 0; c < e.length - 1; c++) (o *= e[c]), i.push(o)
1738
+ for (let s = 0; s < e.length - 1; s++) (o *= e[s]), i.push(o)
1732
1739
  const u = []
1733
- for (let c = 0; c < r; c++) {
1734
- const s = {}
1740
+ for (let s = 0; s < r; s++) {
1741
+ const c = {}
1735
1742
  for (let f = 0; f < t.length; f++) {
1736
1743
  const l = n[t[f]],
1737
- a = Math.floor(c / i[f]) % l.length
1738
- s[t[f]] = l[a]
1744
+ a = Math.floor(s / i[f]) % l.length
1745
+ c[t[f]] = l[a]
1739
1746
  }
1740
- u.push(s)
1747
+ u.push(c)
1741
1748
  }
1742
1749
  return u
1743
1750
  }
@@ -1750,14 +1757,14 @@ function getFlatNotation(n, t, e) {
1750
1757
  function flattenInner(n, t, e, r, o) {
1751
1758
  if (!isObject(t)) return t
1752
1759
  for (const [i, u] of Object.entries(t)) {
1753
- const c = getFlatNotation(e, i, r)
1760
+ const s = getFlatNotation(e, i, r)
1754
1761
  Array.isArray(u)
1755
1762
  ? o
1756
- ? flattenInner(n, u, c, !0, o)
1757
- : (n[c] = u.map(s => flattenInner(Array.isArray(s) ? [] : {}, s, '', !1, o)))
1763
+ ? flattenInner(n, u, s, !0, o)
1764
+ : (n[s] = u.map(c => flattenInner(Array.isArray(c) ? [] : {}, c, '', !1, o)))
1758
1765
  : isObject(u)
1759
- ? flattenInner(n, u, c, !1, o)
1760
- : (n[c] = u)
1766
+ ? flattenInner(n, u, s, !1, o)
1767
+ : (n[s] = u)
1761
1768
  }
1762
1769
  return n
1763
1770
  }
@@ -1823,9 +1830,9 @@ function makeUnique(n, t) {
1823
1830
  function countUnique(n, t, e, r, o) {
1824
1831
  const i = t ? n.map(t) : n,
1825
1832
  u = {}
1826
- for (const s of i) u[s] = (u[s] || 0) + 1
1827
- const c = r ? sortObjectValues(u, o ? (s, f) => s[1] - f[1] : (s, f) => f[1] - s[1]) : u
1828
- return e ? Object.keys(c) : c
1833
+ for (const c of i) u[c] = (u[c] || 0) + 1
1834
+ const s = r ? sortObjectValues(u, o ? (c, f) => c[1] - f[1] : (c, f) => f[1] - c[1]) : u
1835
+ return e ? Object.keys(s) : s
1829
1836
  }
1830
1837
  function sortObjectValues(n, t) {
1831
1838
  return Object.fromEntries(Object.entries(n).sort(t))
@@ -1966,28 +1973,28 @@ class Node {
1966
1973
  function createHierarchy(n, t, e, r, o = !1) {
1967
1974
  const i = new Map(),
1968
1975
  u = []
1969
- n.forEach(s => {
1970
- const f = new Node(s)
1971
- i.set(s[t], f)
1976
+ n.forEach(c => {
1977
+ const f = new Node(c)
1978
+ i.set(c[t], f)
1972
1979
  }),
1973
- n.forEach(s => {
1974
- const f = i.get(s[t])
1980
+ n.forEach(c => {
1981
+ const f = i.get(c[t])
1975
1982
  if (!f) return
1976
- const l = s[e]
1983
+ const l = c[e]
1977
1984
  if (l) {
1978
1985
  const a = i.get(l)
1979
1986
  a && a.children.push(f)
1980
1987
  } else u.push(f)
1981
1988
  })
1982
- const c = s => {
1983
- s.children.sort((f, l) => {
1989
+ const s = c => {
1990
+ c.children.sort((f, l) => {
1984
1991
  const a = f.value[r],
1985
1992
  h = l.value[r]
1986
1993
  return o ? h - a : a - h
1987
1994
  }),
1988
- s.children.forEach(c)
1995
+ c.children.forEach(s)
1989
1996
  }
1990
- return u.forEach(c), u
1997
+ return u.forEach(s), u
1991
1998
  }
1992
1999
  function log2Reduce(n, t) {
1993
2000
  if (Math.log2(n.length) % 1 !== 0) throw new Error('Array length must be a power of 2')
@@ -2114,7 +2121,7 @@ function tickPlaybook(n) {
2114
2121
  )
2115
2122
  }
2116
2123
  function getArgument(n, t, e, r) {
2117
- const o = n.findIndex(c => c === `--${t}` || c.startsWith(`--${t}=`)),
2124
+ const o = n.findIndex(s => s === `--${t}` || s.startsWith(`--${t}=`)),
2118
2125
  i = n[o]
2119
2126
  if (!i) return (e || {})[r || t || ''] || null
2120
2127
  if (i.includes('=')) return i.split('=')[1]
@@ -2131,14 +2138,14 @@ function getNumberArgument(n, t, e, r) {
2131
2138
  }
2132
2139
  }
2133
2140
  function getBooleanArgument(n, t, e, r) {
2134
- const o = n.some(s => s.endsWith('-' + t)),
2141
+ const o = n.some(c => c.endsWith('-' + t)),
2135
2142
  i = getArgument(n, t, e, r)
2136
2143
  if (!i && o) return !0
2137
2144
  if (!i && !o) return null
2138
2145
  const u = ['true', '1', 'yes', 'y', 'on'],
2139
- c = ['false', '0', 'no', 'n', 'off']
2146
+ s = ['false', '0', 'no', 'n', 'off']
2140
2147
  if (u.includes(i.toLowerCase())) return !0
2141
- if (c.includes(i.toLowerCase())) return !1
2148
+ if (s.includes(i.toLowerCase())) return !1
2142
2149
  throw Error(`Invalid boolean argument ${t}: ${i}`)
2143
2150
  }
2144
2151
  function requireStringArgument(n, t, e, r) {
@@ -2221,16 +2228,16 @@ function isBottommost(n, t, e) {
2221
2228
  return !n[t][e + 1]
2222
2229
  }
2223
2230
  function getCorners(n, t, e) {
2224
- var r, o, i, u, c, s, f, l
2231
+ var r, o, i, u, s, c, f, l
2225
2232
  const a = []
2226
2233
  return n[t][e]
2227
2234
  ? isHorizontalLine(n, t, e) || isVerticalLine(n, t, e)
2228
2235
  ? []
2229
- : (!(!((c = n[t - 1]) === null || c === void 0) && c[e - 1]) &&
2236
+ : (!(!((s = n[t - 1]) === null || s === void 0) && s[e - 1]) &&
2230
2237
  isLeftmost(n, t, e) &&
2231
2238
  isTopmost(n, t, e) &&
2232
2239
  a.push({ x: t, y: e }),
2233
- !(!((s = n[t + 1]) === null || s === void 0) && s[e - 1]) &&
2240
+ !(!((c = n[t + 1]) === null || c === void 0) && c[e - 1]) &&
2234
2241
  isRightmost(n, t, e) &&
2235
2242
  isTopmost(n, t, e) &&
2236
2243
  a.push({ x: t + 1, y: e }),
@@ -2258,42 +2265,42 @@ function findCorners(n, t, e, r) {
2258
2265
  ]
2259
2266
  for (let i = 0; i < n.length; i++)
2260
2267
  for (let u = 0; u < n[0].length; u++) {
2261
- const c = getCorners(n, i, u)
2262
- for (const s of c) o.some(f => f.x === s.x && f.y === s.y) || o.push(s)
2268
+ const s = getCorners(n, i, u)
2269
+ for (const c of s) o.some(f => f.x === c.x && f.y === c.y) || o.push(c)
2263
2270
  }
2264
2271
  return o.map(i => ({ x: i.x * t, y: i.y * t }))
2265
2272
  }
2266
2273
  function findLines(n, t) {
2267
- const e = filterCoordinates(n, (s, f) => n[s][f] === 0 && n[s][f + 1] !== 0, 'row-first').map(s =>
2268
- Object.assign(Object.assign({}, s), { dx: 1, dy: 0 })
2274
+ const e = filterCoordinates(n, (c, f) => n[c][f] === 0 && n[c][f + 1] !== 0, 'row-first').map(c =>
2275
+ Object.assign(Object.assign({}, c), { dx: 1, dy: 0 })
2269
2276
  ),
2270
- r = filterCoordinates(n, (s, f) => n[s][f] === 0 && n[s][f - 1] !== 0, 'row-first').map(s =>
2271
- Object.assign(Object.assign({}, s), { dx: 1, dy: 0 })
2277
+ r = filterCoordinates(n, (c, f) => n[c][f] === 0 && n[c][f - 1] !== 0, 'row-first').map(c =>
2278
+ Object.assign(Object.assign({}, c), { dx: 1, dy: 0 })
2272
2279
  ),
2273
2280
  o = filterCoordinates(
2274
2281
  n,
2275
- (s, f) => {
2282
+ (c, f) => {
2276
2283
  var l
2277
- return n[s][f] === 0 && ((l = n[s - 1]) === null || l === void 0 ? void 0 : l[f]) !== 0
2284
+ return n[c][f] === 0 && ((l = n[c - 1]) === null || l === void 0 ? void 0 : l[f]) !== 0
2278
2285
  },
2279
2286
  'column-first'
2280
- ).map(s => Object.assign(Object.assign({}, s), { dx: 0, dy: 1 })),
2287
+ ).map(c => Object.assign(Object.assign({}, c), { dx: 0, dy: 1 })),
2281
2288
  i = filterCoordinates(
2282
2289
  n,
2283
- (s, f) => {
2290
+ (c, f) => {
2284
2291
  var l
2285
- return n[s][f] === 0 && ((l = n[s + 1]) === null || l === void 0 ? void 0 : l[f]) !== 0
2292
+ return n[c][f] === 0 && ((l = n[c + 1]) === null || l === void 0 ? void 0 : l[f]) !== 0
2286
2293
  },
2287
2294
  'column-first'
2288
- ).map(s => Object.assign(Object.assign({}, s), { dx: 0, dy: 1 }))
2289
- e.forEach(s => s.y++), i.forEach(s => s.x++)
2290
- const u = group([...o, ...i], (s, f) => s.x === f.x && s.y - 1 === f.y),
2291
- c = group([...r, ...e], (s, f) => s.y === f.y && s.x - 1 === f.x)
2292
- return [...u, ...c]
2293
- .map(s => ({ start: s[0], end: last(s) }))
2294
- .map(s => ({
2295
- start: multiplyPoint(s.start, t),
2296
- end: multiplyPoint(addPoint(s.end, { x: s.start.dx, y: s.start.dy }), t)
2295
+ ).map(c => Object.assign(Object.assign({}, c), { dx: 0, dy: 1 }))
2296
+ e.forEach(c => c.y++), i.forEach(c => c.x++)
2297
+ const u = group([...o, ...i], (c, f) => c.x === f.x && c.y - 1 === f.y),
2298
+ s = group([...r, ...e], (c, f) => c.y === f.y && c.x - 1 === f.x)
2299
+ return [...u, ...s]
2300
+ .map(c => ({ start: c[0], end: last(c) }))
2301
+ .map(c => ({
2302
+ start: multiplyPoint(c.start, t),
2303
+ end: multiplyPoint(addPoint(c.end, { x: c.start.dx, y: c.start.dy }), t)
2297
2304
  }))
2298
2305
  }
2299
2306
  function getAngleInRadians(n, t) {
@@ -2307,11 +2314,11 @@ function getLineIntersectionPoint(n, t, e, r) {
2307
2314
  if (o === 0) return null
2308
2315
  let i = n.y - e.y,
2309
2316
  u = n.x - e.x
2310
- const c = (r.x - e.x) * i - (r.y - e.y) * u,
2311
- s = (t.x - n.x) * i - (t.y - n.y) * u
2317
+ const s = (r.x - e.x) * i - (r.y - e.y) * u,
2318
+ c = (t.x - n.x) * i - (t.y - n.y) * u
2312
2319
  return (
2313
- (i = c / o),
2314
- (u = s / o),
2320
+ (i = s / o),
2321
+ (u = c / o),
2315
2322
  i > 0 && i < 1 && u > 0 && u < 1 ? { x: n.x + i * (t.x - n.x), y: n.y + i * (t.y - n.y) } : null
2316
2323
  )
2317
2324
  }
@@ -2324,9 +2331,9 @@ function raycast(n, t, e) {
2324
2331
  }
2325
2332
  return r.length
2326
2333
  ? r.reduce((i, u) => {
2327
- const c = getDistanceBetweenPoints(n, u),
2328
- s = getDistanceBetweenPoints(n, i)
2329
- return c < s ? u : i
2334
+ const s = getDistanceBetweenPoints(n, u),
2335
+ c = getDistanceBetweenPoints(n, i)
2336
+ return s < c ? u : i
2330
2337
  })
2331
2338
  : null
2332
2339
  }
@@ -2334,9 +2341,9 @@ function raycastCircle(n, t, e) {
2334
2341
  const o = getSortedRayAngles(n, e),
2335
2342
  i = []
2336
2343
  for (const u of o) {
2337
- const c = raycast(n, t, u - 0.001),
2338
- s = raycast(n, t, u + 0.001)
2339
- c && i.push(c), s && i.push(s)
2344
+ const s = raycast(n, t, u - 0.001),
2345
+ c = raycast(n, t, u + 0.001)
2346
+ s && i.push(s), c && i.push(c)
2340
2347
  }
2341
2348
  return i
2342
2349
  }
@@ -2356,7 +2363,15 @@ function raycastCircle(n, t, e) {
2356
2363
  numberToUint64BE,
2357
2364
  uint64BEToNumber
2358
2365
  }),
2359
- (exports.Random = { intBetween, floatBetween, chance, signed: signedRandom, makeSeededRng, point: randomPoint }),
2366
+ (exports.Random = {
2367
+ intBetween,
2368
+ floatBetween,
2369
+ chance,
2370
+ signed: signedRandom,
2371
+ makeSeededRng,
2372
+ point: randomPoint,
2373
+ procs
2374
+ }),
2360
2375
  (exports.Arrays = {
2361
2376
  countUnique,
2362
2377
  makeUnique,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cafe-utility",
3
- "version": "22.2.1",
3
+ "version": "22.4.0",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "exports": {