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.
- package/index.d.ts +43 -14
- package/index.js +176 -161
- 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,
|
|
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
|
|
83
|
-
|
|
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,
|
|
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
|
|
92
|
-
|
|
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
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
declare function
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
declare function
|
|
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
|
|
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(
|
|
141
|
-
|
|
142
|
-
for (t !== null &&
|
|
143
|
-
const
|
|
144
|
-
o(u[
|
|
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(
|
|
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
|
-
|
|
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]) || (
|
|
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
|
-
|
|
257
|
-
|
|
258
|
-
f = Math.sin(
|
|
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(
|
|
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
|
|
391
|
-
(
|
|
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(
|
|
405
|
+
.every(e => e === '_' || isLetterOrDigit(e))
|
|
401
406
|
)
|
|
402
|
-
throw new TypeError(
|
|
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
|
|
410
|
-
(
|
|
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+)?$/))
|
|
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(
|
|
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(
|
|
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(
|
|
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
|
|
443
|
-
if (!isId(
|
|
444
|
-
return
|
|
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(
|
|
448
|
-
const
|
|
449
|
-
if (
|
|
450
|
-
const
|
|
451
|
-
|
|
452
|
-
if (!isNumber(
|
|
453
|
-
throw new TypeError(
|
|
454
|
-
return `${String(
|
|
455
|
-
}
|
|
456
|
-
function asArray(n) {
|
|
457
|
-
if (!Array.isArray(n)) throw new TypeError(
|
|
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(
|
|
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
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
if (!
|
|
472
|
-
|
|
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(
|
|
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
|
|
776
|
-
const
|
|
777
|
-
u = u.concat(
|
|
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) | (
|
|
1015
|
-
a = ((
|
|
1016
|
-
h = ((
|
|
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
|
-
|
|
1029
|
-
|
|
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[
|
|
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(
|
|
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
|
|
1084
|
-
|
|
1085
|
-
if (
|
|
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
|
|
1090
|
-
if (
|
|
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
|
|
1126
|
-
|
|
1127
|
-
if (((o +=
|
|
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
|
|
1183
|
-
n = n.replace(`${r}${t}${o}${
|
|
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
|
-
|
|
1212
|
-
n = n.slice(0, r) +
|
|
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,
|
|
1251
|
-
n.forEach((u,
|
|
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
|
|
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
|
|
1385
|
-
|
|
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((
|
|
1389
|
-
return { cycles:
|
|
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
|
-
|
|
1407
|
-
|
|
1408
|
-
return { deltaMs: i, progress: o, baseTimeMs: u, totalTimeMs:
|
|
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
|
|
1574
|
-
|
|
1575
|
-
i[
|
|
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
|
-
|
|
1651
|
+
s = (r = t?.precision) !== null && r !== void 0 ? r : 1
|
|
1645
1652
|
if (n < thresholds[0]) return `${n}${i}`
|
|
1646
|
-
for (let
|
|
1647
|
-
if (n < thresholds[
|
|
1648
|
-
return `${(n / thresholds[thresholds.length - 1]).toFixed(
|
|
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(
|
|
1728
|
-
r = e.reduce((
|
|
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
|
|
1738
|
+
for (let s = 0; s < e.length - 1; s++) (o *= e[s]), i.push(o)
|
|
1732
1739
|
const u = []
|
|
1733
|
-
for (let
|
|
1734
|
-
const
|
|
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(
|
|
1738
|
-
|
|
1744
|
+
a = Math.floor(s / i[f]) % l.length
|
|
1745
|
+
c[t[f]] = l[a]
|
|
1739
1746
|
}
|
|
1740
|
-
u.push(
|
|
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
|
|
1760
|
+
const s = getFlatNotation(e, i, r)
|
|
1754
1761
|
Array.isArray(u)
|
|
1755
1762
|
? o
|
|
1756
|
-
? flattenInner(n, u,
|
|
1757
|
-
: (n[
|
|
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,
|
|
1760
|
-
: (n[
|
|
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
|
|
1827
|
-
const
|
|
1828
|
-
return e ? Object.keys(
|
|
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(
|
|
1970
|
-
const f = new Node(
|
|
1971
|
-
i.set(
|
|
1976
|
+
n.forEach(c => {
|
|
1977
|
+
const f = new Node(c)
|
|
1978
|
+
i.set(c[t], f)
|
|
1972
1979
|
}),
|
|
1973
|
-
n.forEach(
|
|
1974
|
-
const f = i.get(
|
|
1980
|
+
n.forEach(c => {
|
|
1981
|
+
const f = i.get(c[t])
|
|
1975
1982
|
if (!f) return
|
|
1976
|
-
const l =
|
|
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
|
|
1983
|
-
|
|
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
|
-
|
|
1995
|
+
c.children.forEach(s)
|
|
1989
1996
|
}
|
|
1990
|
-
return u.forEach(
|
|
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(
|
|
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(
|
|
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
|
-
|
|
2146
|
+
s = ['false', '0', 'no', 'n', 'off']
|
|
2140
2147
|
if (u.includes(i.toLowerCase())) return !0
|
|
2141
|
-
if (
|
|
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,
|
|
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
|
-
: (!(!((
|
|
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
|
-
!(!((
|
|
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
|
|
2262
|
-
for (const
|
|
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, (
|
|
2268
|
-
Object.assign(Object.assign({},
|
|
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, (
|
|
2271
|
-
Object.assign(Object.assign({},
|
|
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
|
-
(
|
|
2282
|
+
(c, f) => {
|
|
2276
2283
|
var l
|
|
2277
|
-
return n[
|
|
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(
|
|
2287
|
+
).map(c => Object.assign(Object.assign({}, c), { dx: 0, dy: 1 })),
|
|
2281
2288
|
i = filterCoordinates(
|
|
2282
2289
|
n,
|
|
2283
|
-
(
|
|
2290
|
+
(c, f) => {
|
|
2284
2291
|
var l
|
|
2285
|
-
return n[
|
|
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(
|
|
2289
|
-
e.forEach(
|
|
2290
|
-
const u = group([...o, ...i], (
|
|
2291
|
-
|
|
2292
|
-
return [...u, ...
|
|
2293
|
-
.map(
|
|
2294
|
-
.map(
|
|
2295
|
-
start: multiplyPoint(
|
|
2296
|
-
end: multiplyPoint(addPoint(
|
|
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
|
|
2311
|
-
|
|
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 =
|
|
2314
|
-
(u =
|
|
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
|
|
2328
|
-
|
|
2329
|
-
return
|
|
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
|
|
2338
|
-
|
|
2339
|
-
|
|
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 = {
|
|
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,
|