cafe-utility 22.0.0 → 22.2.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 +14 -3
- package/index.js +199 -174
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -75,10 +75,19 @@ declare function randomUnicodeString(length: number, generator?: () => number):
|
|
|
75
75
|
declare function searchHex(string: string, length: number): string | null;
|
|
76
76
|
declare function searchSubstring(string: string, predicate: (string: string) => boolean, separators?: string[]): string | null;
|
|
77
77
|
declare function randomHexString(length: number, generator?: () => number): string;
|
|
78
|
-
declare function asString(string: any
|
|
78
|
+
declare function asString(string: any, limits?: {
|
|
79
|
+
min?: number;
|
|
80
|
+
max?: number;
|
|
81
|
+
}): string;
|
|
79
82
|
declare function asSafeString(string: any): string;
|
|
80
|
-
declare function asNumber(number: any
|
|
81
|
-
|
|
83
|
+
declare function asNumber(number: any, limits?: {
|
|
84
|
+
min?: number;
|
|
85
|
+
max?: number;
|
|
86
|
+
}): number;
|
|
87
|
+
declare function asInteger(number: any, limits?: {
|
|
88
|
+
min?: number;
|
|
89
|
+
max?: number;
|
|
90
|
+
}): number;
|
|
82
91
|
declare function asBoolean(bool: any): boolean;
|
|
83
92
|
declare function asDate(date: any): Date;
|
|
84
93
|
declare function asNullableString(string: any): string | null;
|
|
@@ -239,6 +248,7 @@ declare function dateTimeSlug(optionalDate?: Date): string;
|
|
|
239
248
|
declare function fromUtcString(string: string): Date;
|
|
240
249
|
declare function fromMillis(millis: number): Date;
|
|
241
250
|
declare function createTimeDigits(value: number): string;
|
|
251
|
+
declare function normalizeTime(time: string): string;
|
|
242
252
|
declare function humanizeTime(millis: number): string;
|
|
243
253
|
interface TimestampLabels {
|
|
244
254
|
today: (hour: number, minute: number, pm: boolean) => string;
|
|
@@ -635,6 +645,7 @@ export declare const Dates: {
|
|
|
635
645
|
minutes: typeof minutes;
|
|
636
646
|
hours: typeof hours;
|
|
637
647
|
make: typeof makeDate;
|
|
648
|
+
normalizeTime: typeof normalizeTime;
|
|
638
649
|
};
|
|
639
650
|
export declare const Objects: {
|
|
640
651
|
safeParse: typeof safeParse;
|
package/index.js
CHANGED
|
@@ -25,7 +25,7 @@ async function runInParallelBatches(n, t = 1) {
|
|
|
25
25
|
const e = splitByCount(n, t),
|
|
26
26
|
r = [],
|
|
27
27
|
o = e.map(async i => {
|
|
28
|
-
for (const
|
|
28
|
+
for (const u of i) r.push(await u())
|
|
29
29
|
})
|
|
30
30
|
return await Promise.all(o), r
|
|
31
31
|
}
|
|
@@ -132,16 +132,16 @@ function pickManyUnique(n, t, e, r = Math.random) {
|
|
|
132
132
|
const o = []
|
|
133
133
|
for (; o.length < t; ) {
|
|
134
134
|
const i = pick(n, r)
|
|
135
|
-
o.some(
|
|
135
|
+
o.some(u => e(u, i)) || o.push(i)
|
|
136
136
|
}
|
|
137
137
|
return o
|
|
138
138
|
}
|
|
139
139
|
function pickGuaranteed(n, t, e, r, o, i = Math.random) {
|
|
140
|
-
const
|
|
140
|
+
const u = n.filter(s => s !== t && s !== e),
|
|
141
141
|
c = []
|
|
142
|
-
for (t !== null && c.push(t);
|
|
143
|
-
const
|
|
144
|
-
o(s
|
|
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
145
|
}
|
|
146
146
|
return shuffle(c, i), { values: c, indexOfGuaranteed: t !== null ? c.indexOf(t) : -1 }
|
|
147
147
|
}
|
|
@@ -157,7 +157,7 @@ function makePipe(n, t) {
|
|
|
157
157
|
}
|
|
158
158
|
function pickWeighted(n, t, e) {
|
|
159
159
|
if ((isUndefined(e) && (e = Math.random()), n.length !== t.length)) throw new Error('Array length mismatch')
|
|
160
|
-
let r = t.reduce((i,
|
|
160
|
+
let r = t.reduce((i, u) => i + u, 0)
|
|
161
161
|
const o = e * r
|
|
162
162
|
for (let i = 0; i < n.length - 1; i++) if (((r -= t[i]), o >= r)) return n[i]
|
|
163
163
|
return last(n)
|
|
@@ -166,7 +166,7 @@ function sortWeighted(n, t, e = Math.random) {
|
|
|
166
166
|
const r = t.map(i => e() * i),
|
|
167
167
|
o = []
|
|
168
168
|
for (let i = 0; i < n.length; i++) o.push([n[i], r[i]])
|
|
169
|
-
return o.sort((i,
|
|
169
|
+
return o.sort((i, u) => u[1] - i[1]).map(i => i[0])
|
|
170
170
|
}
|
|
171
171
|
function getDeep(n, t) {
|
|
172
172
|
if (n == null) return null
|
|
@@ -182,9 +182,9 @@ function setDeep(n, t, e) {
|
|
|
182
182
|
const r = t.split(/\.|\[/)
|
|
183
183
|
let o = n
|
|
184
184
|
for (let i = 0; i < r.length; i++) {
|
|
185
|
-
const
|
|
185
|
+
const u = r[i],
|
|
186
186
|
c = i < r.length - 1 && r[i + 1].includes(']'),
|
|
187
|
-
f =
|
|
187
|
+
f = u.includes(']') ? u.replace(/\[|\]/g, '') : u
|
|
188
188
|
if (i === r.length - 1) return (o[f] = e), e
|
|
189
189
|
isObject(o[f]) || (c ? (o[f] = []) : (o[f] = {})), (o = o[f])
|
|
190
190
|
}
|
|
@@ -252,10 +252,10 @@ function rgbToHex(n) {
|
|
|
252
252
|
}
|
|
253
253
|
function haversineDistanceToMeters(n, t, e, r) {
|
|
254
254
|
const i = (n * Math.PI) / 180,
|
|
255
|
-
|
|
255
|
+
u = (e * Math.PI) / 180,
|
|
256
256
|
c = ((e - n) * Math.PI) / 180,
|
|
257
|
-
|
|
258
|
-
f = Math.sin(c / 2) * Math.sin(c / 2) + Math.cos(i) * Math.cos(
|
|
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)
|
|
259
259
|
return 6371e3 * (2 * Math.atan2(Math.sqrt(f), Math.sqrt(1 - f)))
|
|
260
260
|
}
|
|
261
261
|
function roundToNearest(n, t) {
|
|
@@ -382,8 +382,15 @@ function randomHexString(n, t = Math.random) {
|
|
|
382
382
|
for (let r = 0; r < n; r++) e += hexAlphabet[Math.floor(t() * hexAlphabet.length)]
|
|
383
383
|
return e
|
|
384
384
|
}
|
|
385
|
-
function asString(n) {
|
|
385
|
+
function asString(n, t) {
|
|
386
|
+
var e, r
|
|
386
387
|
if (isBlank(n)) throw new TypeError('Expected string, got: ' + n)
|
|
388
|
+
if (t && ((t.min !== void 0 && n.length < t.min) || (t.max !== void 0 && n.length > t.max)))
|
|
389
|
+
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}`
|
|
393
|
+
)
|
|
387
394
|
return n
|
|
388
395
|
}
|
|
389
396
|
function asSafeString(n) {
|
|
@@ -395,13 +402,23 @@ function asSafeString(n) {
|
|
|
395
402
|
throw new TypeError('Expected safe string, got: ' + n)
|
|
396
403
|
return n
|
|
397
404
|
}
|
|
398
|
-
function
|
|
399
|
-
|
|
405
|
+
function checkLimits(n, t) {
|
|
406
|
+
var e, r
|
|
407
|
+
if ((t.min !== void 0 && n < t.min) || (t.max !== void 0 && n > t.max))
|
|
408
|
+
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}`
|
|
412
|
+
)
|
|
413
|
+
}
|
|
414
|
+
function asNumber(n, t) {
|
|
415
|
+
if (isNumber(n)) return t && checkLimits(n, t), n
|
|
400
416
|
if (!isString(n) || !n.match(/^-?\d+(\.\d+)?$/)) throw new TypeError('Expected number, got: ' + n)
|
|
401
|
-
|
|
417
|
+
const e = parseFloat(n)
|
|
418
|
+
return t && checkLimits(e, t), e
|
|
402
419
|
}
|
|
403
|
-
function asInteger(n) {
|
|
404
|
-
return asNumber(n) | 0
|
|
420
|
+
function asInteger(n, t) {
|
|
421
|
+
return asNumber(n, t) | 0
|
|
405
422
|
}
|
|
406
423
|
function asBoolean(n) {
|
|
407
424
|
if (n === 'true') return !0
|
|
@@ -754,12 +771,12 @@ function expand(n) {
|
|
|
754
771
|
const r = e[1].split(','),
|
|
755
772
|
o = n.slice(0, e.index),
|
|
756
773
|
i = n.slice(e.index + e[0].length)
|
|
757
|
-
let
|
|
774
|
+
let u = []
|
|
758
775
|
for (const c of r) {
|
|
759
|
-
const
|
|
760
|
-
|
|
776
|
+
const s = expand(o + c + i)
|
|
777
|
+
u = u.concat(s)
|
|
761
778
|
}
|
|
762
|
-
return
|
|
779
|
+
return u
|
|
763
780
|
}
|
|
764
781
|
function shrinkTrim(n) {
|
|
765
782
|
return n.replace(/\s+/g, ' ').replace(/\s$|^\s/g, '')
|
|
@@ -983,13 +1000,13 @@ function base64ToUint8Array(n) {
|
|
|
983
1000
|
let o = 0,
|
|
984
1001
|
i = 0
|
|
985
1002
|
for (; o < n.length; ) {
|
|
986
|
-
const
|
|
1003
|
+
const u = BASE64_CHARS.indexOf(n.charAt(o++)),
|
|
987
1004
|
c = BASE64_CHARS.indexOf(n.charAt(o++)),
|
|
988
|
-
|
|
1005
|
+
s = BASE64_CHARS.indexOf(n.charAt(o++)),
|
|
989
1006
|
f = BASE64_CHARS.indexOf(n.charAt(o++)),
|
|
990
|
-
l = (
|
|
991
|
-
a = ((c & 15) << 4) | (
|
|
992
|
-
h = ((
|
|
1007
|
+
l = (u << 2) | (c >> 4),
|
|
1008
|
+
a = ((c & 15) << 4) | (s >> 2),
|
|
1009
|
+
h = ((s & 3) << 6) | f
|
|
993
1010
|
;(r[i++] = l), i < e && (r[i++] = a), i < e && (r[i++] = h)
|
|
994
1011
|
}
|
|
995
1012
|
return r
|
|
@@ -1000,12 +1017,12 @@ function uint8ArrayToBase64(n) {
|
|
|
1000
1017
|
for (let r = 0; r < n.length; r += 3) {
|
|
1001
1018
|
const o = n[r],
|
|
1002
1019
|
i = n[r + 1],
|
|
1003
|
-
|
|
1020
|
+
u = n[r + 2],
|
|
1004
1021
|
c = o >> 2,
|
|
1005
|
-
|
|
1006
|
-
f = ((i & 15) << 2) | (
|
|
1007
|
-
l =
|
|
1008
|
-
;(t += BASE64_CHARS[c] + BASE64_CHARS[
|
|
1022
|
+
s = ((o & 3) << 4) | (i >> 4),
|
|
1023
|
+
f = ((i & 15) << 2) | (u >> 6),
|
|
1024
|
+
l = u & 63
|
|
1025
|
+
;(t += BASE64_CHARS[c] + BASE64_CHARS[s]),
|
|
1009
1026
|
r + 1 < n.length ? (t += BASE64_CHARS[f]) : e++,
|
|
1010
1027
|
r + 2 < n.length ? (t += BASE64_CHARS[l]) : e++
|
|
1011
1028
|
}
|
|
@@ -1032,9 +1049,9 @@ function route(n, t) {
|
|
|
1032
1049
|
if (e.length !== r.length) return null
|
|
1033
1050
|
const o = {}
|
|
1034
1051
|
for (let i = 0; i < e.length; i++) {
|
|
1035
|
-
const
|
|
1036
|
-
if (
|
|
1037
|
-
else if (
|
|
1052
|
+
const u = e[i]
|
|
1053
|
+
if (u.startsWith(':')) o[u.slice(1)] = r[i]
|
|
1054
|
+
else if (u !== r[i]) return null
|
|
1038
1055
|
}
|
|
1039
1056
|
return o
|
|
1040
1057
|
}
|
|
@@ -1045,25 +1062,25 @@ function explodeReplace(n, t, e) {
|
|
|
1045
1062
|
}
|
|
1046
1063
|
function generateVariants(n, t, e, r = Math.random) {
|
|
1047
1064
|
const o = exports.Arrays.shuffle(
|
|
1048
|
-
t.map(
|
|
1065
|
+
t.map(u => ({
|
|
1049
1066
|
variants: exports.Arrays.shuffle(
|
|
1050
|
-
|
|
1067
|
+
u.variants.map(c => c),
|
|
1051
1068
|
r
|
|
1052
1069
|
),
|
|
1053
|
-
avoid:
|
|
1070
|
+
avoid: u.avoid
|
|
1054
1071
|
})),
|
|
1055
1072
|
r
|
|
1056
1073
|
),
|
|
1057
1074
|
i = []
|
|
1058
|
-
for (const
|
|
1059
|
-
const c =
|
|
1060
|
-
|
|
1061
|
-
if (
|
|
1075
|
+
for (const u of o) {
|
|
1076
|
+
const c = u.variants.filter(f => f !== u.avoid),
|
|
1077
|
+
s = c.find(f => n.includes(f))
|
|
1078
|
+
if (s && (pushAll(i, explodeReplace(n, s, c)), i.length >= e)) break
|
|
1062
1079
|
}
|
|
1063
1080
|
if (i.length < e)
|
|
1064
|
-
for (const
|
|
1065
|
-
const c =
|
|
1066
|
-
if (c && (pushAll(i, explodeReplace(n, c,
|
|
1081
|
+
for (const u of o) {
|
|
1082
|
+
const c = u.variants.find(s => n.includes(s))
|
|
1083
|
+
if (c && (pushAll(i, explodeReplace(n, c, u.variants)), i.length >= e)) break
|
|
1067
1084
|
}
|
|
1068
1085
|
return i.slice(0, e)
|
|
1069
1086
|
}
|
|
@@ -1097,10 +1114,10 @@ function toLines(n, t, e = {}) {
|
|
|
1097
1114
|
const r = []
|
|
1098
1115
|
let o = '',
|
|
1099
1116
|
i = 0
|
|
1100
|
-
for (let
|
|
1101
|
-
const c = n[
|
|
1102
|
-
|
|
1103
|
-
if (((o += c), (i +=
|
|
1117
|
+
for (let u = 0; u < n.length; u++) {
|
|
1118
|
+
const c = n[u],
|
|
1119
|
+
s = e[c] || 1
|
|
1120
|
+
if (((o += c), (i += s), i > t)) {
|
|
1104
1121
|
const { line: f, rest: l } = breakLine(o)
|
|
1105
1122
|
r.push(f),
|
|
1106
1123
|
(o = l),
|
|
@@ -1170,8 +1187,8 @@ function resolveRemainingVariablesWithDefaults(n, t = '$', e = ':') {
|
|
|
1170
1187
|
if (n[r + o.length + 1] === e)
|
|
1171
1188
|
if (n[r + o.length + 2] === e) n = n.replace(`${t}${o}${e}${e}`, '')
|
|
1172
1189
|
else {
|
|
1173
|
-
const
|
|
1174
|
-
n = n.replace(`${t}${o}${e}${
|
|
1190
|
+
const u = readNextWord(n, r + o.length + 2)
|
|
1191
|
+
n = n.replace(`${t}${o}${e}${u}`, u)
|
|
1175
1192
|
}
|
|
1176
1193
|
r = n.indexOf(t, r + 1)
|
|
1177
1194
|
}
|
|
@@ -1183,8 +1200,8 @@ function resolveMarkdownLinks(n, t) {
|
|
|
1183
1200
|
const r = lastIndexOfBefore(n, '[', e),
|
|
1184
1201
|
o = n.indexOf(')', e)
|
|
1185
1202
|
if (r !== -1 && o !== -1) {
|
|
1186
|
-
const [i,
|
|
1187
|
-
c = t(i,
|
|
1203
|
+
const [i, u] = n.slice(r + 1, o).split(']('),
|
|
1204
|
+
c = t(i, u)
|
|
1188
1205
|
n = n.slice(0, r) + c + n.slice(o + 1)
|
|
1189
1206
|
}
|
|
1190
1207
|
e = n.indexOf('](', e + 1)
|
|
@@ -1214,17 +1231,17 @@ function selectMax(n, t) {
|
|
|
1214
1231
|
let e = null,
|
|
1215
1232
|
r = -1 / 0
|
|
1216
1233
|
for (const [o, i] of Object.entries(n)) {
|
|
1217
|
-
const
|
|
1218
|
-
|
|
1234
|
+
const u = t(i)
|
|
1235
|
+
u > r && ((r = u), (e = o))
|
|
1219
1236
|
}
|
|
1220
1237
|
return e ? [e, n[e]] : null
|
|
1221
1238
|
}
|
|
1222
1239
|
function reposition(n, t, e, r) {
|
|
1223
|
-
const o = n.find(
|
|
1224
|
-
i = n.find(
|
|
1240
|
+
const o = n.find(u => u[t] === e),
|
|
1241
|
+
i = n.find(u => u[t] === e + r)
|
|
1225
1242
|
o && i ? ((o[t] = e + r), (i[t] = e)) : o && (o[t] = e + r),
|
|
1226
|
-
n.sort((
|
|
1227
|
-
n.forEach((
|
|
1243
|
+
n.sort((u, c) => asNumber(u[t]) - asNumber(c[t])),
|
|
1244
|
+
n.forEach((u, c) => (u[t] = c + 1))
|
|
1228
1245
|
}
|
|
1229
1246
|
function unwrapSingleKey(n) {
|
|
1230
1247
|
const t = Object.keys(n)
|
|
@@ -1238,8 +1255,8 @@ function parseCsv(n, t = ',', e = '"') {
|
|
|
1238
1255
|
const r = []
|
|
1239
1256
|
let o = '',
|
|
1240
1257
|
i = !1
|
|
1241
|
-
const
|
|
1242
|
-
for (const c of
|
|
1258
|
+
const u = n.split('')
|
|
1259
|
+
for (const c of u) c === t && !i ? (r.push(o), (o = '')) : c === e && ((!o && !i) || i) ? (i = !i) : (o += c)
|
|
1243
1260
|
return r.push(o), r
|
|
1244
1261
|
}
|
|
1245
1262
|
function humanizeProgress(n) {
|
|
@@ -1283,6 +1300,13 @@ function fromMillis(n) {
|
|
|
1283
1300
|
function createTimeDigits(n) {
|
|
1284
1301
|
return String(Math.floor(n)).padStart(2, '0')
|
|
1285
1302
|
}
|
|
1303
|
+
function normalizeTime(n) {
|
|
1304
|
+
let [t, e] = n.split(':')
|
|
1305
|
+
isNumber(parseInt(t, 10)) || (t = '0'), isNumber(parseInt(e, 10)) || (e = '0')
|
|
1306
|
+
let r = clamp(asInteger(t), 0, 23),
|
|
1307
|
+
o = clamp(asInteger(e), 0, 59)
|
|
1308
|
+
return `${createTimeDigits(r)}:${createTimeDigits(o)}`
|
|
1309
|
+
}
|
|
1286
1310
|
function humanizeTime(n) {
|
|
1287
1311
|
const t = Math.floor(n / 36e5)
|
|
1288
1312
|
n = n % 36e5
|
|
@@ -1332,18 +1356,18 @@ function getTimeDelta(n, t) {
|
|
|
1332
1356
|
const r = (e = t?.now) !== null && e !== void 0 ? e : Date.now(),
|
|
1333
1357
|
o = t?.labels || DefaultTimeDeltaLabels,
|
|
1334
1358
|
i = exports.Types.isDate(n) ? n.getTime() : n
|
|
1335
|
-
let
|
|
1336
|
-
return
|
|
1359
|
+
let u = (r - i) / 1e3
|
|
1360
|
+
return u < 10
|
|
1337
1361
|
? o.now()
|
|
1338
|
-
:
|
|
1339
|
-
? o.seconds(Math.floor(
|
|
1340
|
-
: ((
|
|
1341
|
-
|
|
1342
|
-
? o.minutes(Math.floor(
|
|
1343
|
-
: ((
|
|
1344
|
-
|
|
1345
|
-
? o.hours(Math.floor(
|
|
1346
|
-
: ((
|
|
1362
|
+
: u < 120
|
|
1363
|
+
? o.seconds(Math.floor(u))
|
|
1364
|
+
: ((u /= 60),
|
|
1365
|
+
u < 120
|
|
1366
|
+
? o.minutes(Math.floor(u))
|
|
1367
|
+
: ((u /= 60),
|
|
1368
|
+
u < 48
|
|
1369
|
+
? o.hours(Math.floor(u))
|
|
1370
|
+
: ((u /= 24), u < 14 ? o.days(Math.floor(u)) : ((u /= 7), o.weeks(Math.floor(u))))))
|
|
1347
1371
|
}
|
|
1348
1372
|
function secondsToHumanTime(n, t = DefaultTimeDeltaLabels) {
|
|
1349
1373
|
return getTimeDelta(0, { now: n * 1e3, labels: t })
|
|
@@ -1351,11 +1375,11 @@ function secondsToHumanTime(n, t = DefaultTimeDeltaLabels) {
|
|
|
1351
1375
|
function countCycles(n, t, e) {
|
|
1352
1376
|
var r, o, i
|
|
1353
1377
|
const c = ((r = e?.now) !== null && r !== void 0 ? r : Date.now()) - n,
|
|
1354
|
-
|
|
1378
|
+
s = Math.floor(c / t),
|
|
1355
1379
|
f =
|
|
1356
1380
|
t / ((o = e?.precision) !== null && o !== void 0 ? o : 1) -
|
|
1357
1381
|
Math.ceil((c % t) / ((i = e?.precision) !== null && i !== void 0 ? i : 1))
|
|
1358
|
-
return { cycles:
|
|
1382
|
+
return { cycles: s, remaining: f }
|
|
1359
1383
|
}
|
|
1360
1384
|
const throttleTimers = {}
|
|
1361
1385
|
function throttle(n, t) {
|
|
@@ -1371,10 +1395,10 @@ function getProgress(n, t, e, r) {
|
|
|
1371
1395
|
r || (r = Date.now())
|
|
1372
1396
|
const o = t / e,
|
|
1373
1397
|
i = r - n,
|
|
1374
|
-
|
|
1375
|
-
c =
|
|
1376
|
-
|
|
1377
|
-
return { deltaMs: i, progress: o, baseTimeMs:
|
|
1398
|
+
u = i / t,
|
|
1399
|
+
c = u * e,
|
|
1400
|
+
s = c - i
|
|
1401
|
+
return { deltaMs: i, progress: o, baseTimeMs: u, totalTimeMs: c, remainingTimeMs: s }
|
|
1378
1402
|
}
|
|
1379
1403
|
const dayNumberIndex = {
|
|
1380
1404
|
0: 'sunday',
|
|
@@ -1443,8 +1467,8 @@ async function getCached(n, t, e) {
|
|
|
1443
1467
|
o = tinyCache[n]
|
|
1444
1468
|
if (o && o.validUntil > r) return o.value
|
|
1445
1469
|
const i = await e(),
|
|
1446
|
-
|
|
1447
|
-
return (tinyCache[n] = { value: i, validUntil:
|
|
1470
|
+
u = r + t
|
|
1471
|
+
return (tinyCache[n] = { value: i, validUntil: u }), i
|
|
1448
1472
|
}
|
|
1449
1473
|
function joinUrl(...n) {
|
|
1450
1474
|
return n
|
|
@@ -1454,9 +1478,9 @@ function joinUrl(...n) {
|
|
|
1454
1478
|
}
|
|
1455
1479
|
function replaceBetweenStrings(n, t, e, r, o = !0) {
|
|
1456
1480
|
const i = n.indexOf(t),
|
|
1457
|
-
|
|
1458
|
-
if (i === -1 ||
|
|
1459
|
-
return o ? n.substring(0, i + t.length) + r + n.substring(
|
|
1481
|
+
u = n.indexOf(e, i + t.length)
|
|
1482
|
+
if (i === -1 || u === -1) throw Error('Start or end not found')
|
|
1483
|
+
return o ? n.substring(0, i + t.length) + r + n.substring(u) : n.substring(0, i) + r + n.substring(u + e.length)
|
|
1460
1484
|
}
|
|
1461
1485
|
function describeMarkdown(n) {
|
|
1462
1486
|
let t = 'p'
|
|
@@ -1536,12 +1560,12 @@ function createStatefulToggle(n) {
|
|
|
1536
1560
|
}
|
|
1537
1561
|
function organiseWithLimits(n, t, e, r, o) {
|
|
1538
1562
|
const i = {}
|
|
1539
|
-
for (const
|
|
1563
|
+
for (const u of Object.keys(t)) i[u] = []
|
|
1540
1564
|
;(i[r] = []), o && (n = n.sort(o))
|
|
1541
|
-
for (const
|
|
1542
|
-
const c =
|
|
1543
|
-
|
|
1544
|
-
i[
|
|
1565
|
+
for (const u of n) {
|
|
1566
|
+
const c = u[e],
|
|
1567
|
+
s = t[c] ? c : r
|
|
1568
|
+
i[s].length >= t[s] ? i[r].push(u) : i[s].push(u)
|
|
1545
1569
|
}
|
|
1546
1570
|
return i
|
|
1547
1571
|
}
|
|
@@ -1609,12 +1633,12 @@ function formatNumber(n, t) {
|
|
|
1609
1633
|
var e, r
|
|
1610
1634
|
const o = (e = t?.longForm) !== null && e !== void 0 ? e : !1,
|
|
1611
1635
|
i = t?.unit ? ` ${t.unit}` : '',
|
|
1612
|
-
|
|
1636
|
+
u = o ? longNumberUnits : shortNumberUnits,
|
|
1613
1637
|
c = (r = t?.precision) !== null && r !== void 0 ? r : 1
|
|
1614
1638
|
if (n < thresholds[0]) return `${n}${i}`
|
|
1615
|
-
for (let
|
|
1616
|
-
if (n < thresholds[
|
|
1617
|
-
return `${(n / thresholds[thresholds.length - 1]).toFixed(c)}${o ? ' ' : ''}${
|
|
1639
|
+
for (let s = 0; s < thresholds.length - 1; s++)
|
|
1640
|
+
if (n < thresholds[s + 1]) return `${(n / thresholds[s]).toFixed(c)}${o ? ' ' : ''}${u[s]}${i}`
|
|
1641
|
+
return `${(n / thresholds[thresholds.length - 1]).toFixed(c)}${o ? ' ' : ''}${u[thresholds.length - 1]}${i}`
|
|
1618
1642
|
}
|
|
1619
1643
|
function makeNumber(n) {
|
|
1620
1644
|
const t = parseFloat(n)
|
|
@@ -1694,21 +1718,21 @@ function flip(n) {
|
|
|
1694
1718
|
function getAllPermutations(n) {
|
|
1695
1719
|
const t = Object.keys(n),
|
|
1696
1720
|
e = t.map(c => n[c].length),
|
|
1697
|
-
r = e.reduce((c,
|
|
1721
|
+
r = e.reduce((c, s) => (c *= s))
|
|
1698
1722
|
let o = 1
|
|
1699
1723
|
const i = [1]
|
|
1700
1724
|
for (let c = 0; c < e.length - 1; c++) (o *= e[c]), i.push(o)
|
|
1701
|
-
const
|
|
1725
|
+
const u = []
|
|
1702
1726
|
for (let c = 0; c < r; c++) {
|
|
1703
|
-
const
|
|
1727
|
+
const s = {}
|
|
1704
1728
|
for (let f = 0; f < t.length; f++) {
|
|
1705
1729
|
const l = n[t[f]],
|
|
1706
1730
|
a = Math.floor(c / i[f]) % l.length
|
|
1707
|
-
|
|
1731
|
+
s[t[f]] = l[a]
|
|
1708
1732
|
}
|
|
1709
|
-
|
|
1733
|
+
u.push(s)
|
|
1710
1734
|
}
|
|
1711
|
-
return
|
|
1735
|
+
return u
|
|
1712
1736
|
}
|
|
1713
1737
|
function countTruthyValues(n) {
|
|
1714
1738
|
return Object.values(n).filter(t => t).length
|
|
@@ -1718,15 +1742,15 @@ function getFlatNotation(n, t, e) {
|
|
|
1718
1742
|
}
|
|
1719
1743
|
function flattenInner(n, t, e, r, o) {
|
|
1720
1744
|
if (!isObject(t)) return t
|
|
1721
|
-
for (const [i,
|
|
1745
|
+
for (const [i, u] of Object.entries(t)) {
|
|
1722
1746
|
const c = getFlatNotation(e, i, r)
|
|
1723
|
-
Array.isArray(
|
|
1747
|
+
Array.isArray(u)
|
|
1724
1748
|
? o
|
|
1725
|
-
? flattenInner(n,
|
|
1726
|
-
: (n[c] =
|
|
1727
|
-
: isObject(
|
|
1728
|
-
? flattenInner(n,
|
|
1729
|
-
: (n[c] =
|
|
1749
|
+
? flattenInner(n, u, c, !0, o)
|
|
1750
|
+
: (n[c] = u.map(s => flattenInner(Array.isArray(s) ? [] : {}, s, '', !1, o)))
|
|
1751
|
+
: isObject(u)
|
|
1752
|
+
? flattenInner(n, u, c, !1, o)
|
|
1753
|
+
: (n[c] = u)
|
|
1730
1754
|
}
|
|
1731
1755
|
return n
|
|
1732
1756
|
}
|
|
@@ -1791,9 +1815,9 @@ function makeUnique(n, t) {
|
|
|
1791
1815
|
}
|
|
1792
1816
|
function countUnique(n, t, e, r, o) {
|
|
1793
1817
|
const i = t ? n.map(t) : n,
|
|
1794
|
-
|
|
1795
|
-
for (const
|
|
1796
|
-
const c = r ? sortObjectValues(
|
|
1818
|
+
u = {}
|
|
1819
|
+
for (const s of i) u[s] = (u[s] || 0) + 1
|
|
1820
|
+
const c = r ? sortObjectValues(u, o ? (s, f) => s[1] - f[1] : (s, f) => f[1] - s[1]) : u
|
|
1797
1821
|
return e ? Object.keys(c) : c
|
|
1798
1822
|
}
|
|
1799
1823
|
function sortObjectValues(n, t) {
|
|
@@ -1805,7 +1829,7 @@ function transformToArray(n) {
|
|
|
1805
1829
|
r = n[e[0]].length
|
|
1806
1830
|
for (let o = 0; o < r; o++) {
|
|
1807
1831
|
const i = {}
|
|
1808
|
-
for (const
|
|
1832
|
+
for (const u of e) i[u] = n[u][o]
|
|
1809
1833
|
t.push(i)
|
|
1810
1834
|
}
|
|
1811
1835
|
return t
|
|
@@ -1866,9 +1890,9 @@ function makeAsyncQueue(n = 1) {
|
|
|
1866
1890
|
async function o() {
|
|
1867
1891
|
if (t.length > 0 && r < n) {
|
|
1868
1892
|
r++
|
|
1869
|
-
const
|
|
1893
|
+
const u = t.shift()
|
|
1870
1894
|
try {
|
|
1871
|
-
|
|
1895
|
+
u && (await u())
|
|
1872
1896
|
} finally {
|
|
1873
1897
|
if (--r === 0) for (; e.length > 0; ) e.shift()()
|
|
1874
1898
|
o()
|
|
@@ -1877,14 +1901,14 @@ function makeAsyncQueue(n = 1) {
|
|
|
1877
1901
|
}
|
|
1878
1902
|
async function i() {
|
|
1879
1903
|
return r
|
|
1880
|
-
? new Promise(
|
|
1881
|
-
e.push(
|
|
1904
|
+
? new Promise(u => {
|
|
1905
|
+
e.push(u)
|
|
1882
1906
|
})
|
|
1883
1907
|
: Promise.resolve()
|
|
1884
1908
|
}
|
|
1885
1909
|
return {
|
|
1886
|
-
enqueue(
|
|
1887
|
-
t.push(
|
|
1910
|
+
enqueue(u) {
|
|
1911
|
+
t.push(u), o()
|
|
1888
1912
|
},
|
|
1889
1913
|
drain: i
|
|
1890
1914
|
}
|
|
@@ -1934,29 +1958,29 @@ class Node {
|
|
|
1934
1958
|
}
|
|
1935
1959
|
function createHierarchy(n, t, e, r, o = !1) {
|
|
1936
1960
|
const i = new Map(),
|
|
1937
|
-
|
|
1938
|
-
n.forEach(
|
|
1939
|
-
const f = new Node(
|
|
1940
|
-
i.set(
|
|
1961
|
+
u = []
|
|
1962
|
+
n.forEach(s => {
|
|
1963
|
+
const f = new Node(s)
|
|
1964
|
+
i.set(s[t], f)
|
|
1941
1965
|
}),
|
|
1942
|
-
n.forEach(
|
|
1943
|
-
const f = i.get(
|
|
1966
|
+
n.forEach(s => {
|
|
1967
|
+
const f = i.get(s[t])
|
|
1944
1968
|
if (!f) return
|
|
1945
|
-
const l =
|
|
1969
|
+
const l = s[e]
|
|
1946
1970
|
if (l) {
|
|
1947
1971
|
const a = i.get(l)
|
|
1948
1972
|
a && a.children.push(f)
|
|
1949
|
-
} else
|
|
1973
|
+
} else u.push(f)
|
|
1950
1974
|
})
|
|
1951
|
-
const c =
|
|
1952
|
-
|
|
1975
|
+
const c = s => {
|
|
1976
|
+
s.children.sort((f, l) => {
|
|
1953
1977
|
const a = f.value[r],
|
|
1954
1978
|
h = l.value[r]
|
|
1955
1979
|
return o ? h - a : a - h
|
|
1956
1980
|
}),
|
|
1957
|
-
|
|
1981
|
+
s.children.forEach(c)
|
|
1958
1982
|
}
|
|
1959
|
-
return
|
|
1983
|
+
return u.forEach(c), u
|
|
1960
1984
|
}
|
|
1961
1985
|
function log2Reduce(n, t) {
|
|
1962
1986
|
if (Math.log2(n.length) % 1 !== 0) throw new Error('Array length must be a power of 2')
|
|
@@ -2066,7 +2090,7 @@ async function merkleAppend(n, t, e, r = 0) {
|
|
|
2066
2090
|
const o = new Uint8ArrayReader(t)
|
|
2067
2091
|
for (; o.max() !== 0; ) {
|
|
2068
2092
|
const i = n[r].writer.write(o)
|
|
2069
|
-
if (r === 0) for (let
|
|
2093
|
+
if (r === 0) for (let u = 0; u < n.length; u++) n[u].span += i
|
|
2070
2094
|
n[r].writer.max() === 0 && o.max() > 0 && (await merkleElevate(n, e, r))
|
|
2071
2095
|
}
|
|
2072
2096
|
return n
|
|
@@ -2087,8 +2111,8 @@ function getArgument(n, t, e, r) {
|
|
|
2087
2111
|
i = n[o]
|
|
2088
2112
|
if (!i) return (e || {})[r || t || ''] || null
|
|
2089
2113
|
if (i.includes('=')) return i.split('=')[1]
|
|
2090
|
-
const
|
|
2091
|
-
return
|
|
2114
|
+
const u = n[o + 1]
|
|
2115
|
+
return u && !u.startsWith('-') ? u : (e || {})[r || t || ''] || null
|
|
2092
2116
|
}
|
|
2093
2117
|
function getNumberArgument(n, t, e, r) {
|
|
2094
2118
|
const o = getArgument(n, t, e, r)
|
|
@@ -2100,13 +2124,13 @@ function getNumberArgument(n, t, e, r) {
|
|
|
2100
2124
|
}
|
|
2101
2125
|
}
|
|
2102
2126
|
function getBooleanArgument(n, t, e, r) {
|
|
2103
|
-
const o = n.some(
|
|
2127
|
+
const o = n.some(s => s.endsWith('-' + t)),
|
|
2104
2128
|
i = getArgument(n, t, e, r)
|
|
2105
2129
|
if (!i && o) return !0
|
|
2106
2130
|
if (!i && !o) return null
|
|
2107
|
-
const
|
|
2131
|
+
const u = ['true', '1', 'yes', 'y', 'on'],
|
|
2108
2132
|
c = ['false', '0', 'no', 'n', 'off']
|
|
2109
|
-
if (
|
|
2133
|
+
if (u.includes(i.toLowerCase())) return !0
|
|
2110
2134
|
if (c.includes(i.toLowerCase())) return !1
|
|
2111
2135
|
throw Error(`Invalid boolean argument ${t}: ${i}`)
|
|
2112
2136
|
}
|
|
@@ -2190,7 +2214,7 @@ function isBottommost(n, t, e) {
|
|
|
2190
2214
|
return !n[t][e + 1]
|
|
2191
2215
|
}
|
|
2192
2216
|
function getCorners(n, t, e) {
|
|
2193
|
-
var r, o, i,
|
|
2217
|
+
var r, o, i, u, c, s, f, l
|
|
2194
2218
|
const a = []
|
|
2195
2219
|
return n[t][e]
|
|
2196
2220
|
? isHorizontalLine(n, t, e) || isVerticalLine(n, t, e)
|
|
@@ -2199,7 +2223,7 @@ function getCorners(n, t, e) {
|
|
|
2199
2223
|
isLeftmost(n, t, e) &&
|
|
2200
2224
|
isTopmost(n, t, e) &&
|
|
2201
2225
|
a.push({ x: t, y: e }),
|
|
2202
|
-
!(!((
|
|
2226
|
+
!(!((s = n[t + 1]) === null || s === void 0) && s[e - 1]) &&
|
|
2203
2227
|
isRightmost(n, t, e) &&
|
|
2204
2228
|
isTopmost(n, t, e) &&
|
|
2205
2229
|
a.push({ x: t + 1, y: e }),
|
|
@@ -2215,7 +2239,7 @@ function getCorners(n, t, e) {
|
|
|
2215
2239
|
: (!((r = n[t - 1]) === null || r === void 0) && r[e] && n[t][e - 1] && a.push({ x: t, y: e }),
|
|
2216
2240
|
!((o = n[t + 1]) === null || o === void 0) && o[e] && n[t][e - 1] && a.push({ x: t + 1, y: e }),
|
|
2217
2241
|
!((i = n[t - 1]) === null || i === void 0) && i[e] && n[t][e + 1] && a.push({ x: t, y: e + 1 }),
|
|
2218
|
-
!((
|
|
2242
|
+
!((u = n[t + 1]) === null || u === void 0) && u[e] && n[t][e + 1] && a.push({ x: t + 1, y: e + 1 }),
|
|
2219
2243
|
a)
|
|
2220
2244
|
}
|
|
2221
2245
|
function findCorners(n, t, e, r) {
|
|
@@ -2226,43 +2250,43 @@ function findCorners(n, t, e, r) {
|
|
|
2226
2250
|
{ x: e, y: r }
|
|
2227
2251
|
]
|
|
2228
2252
|
for (let i = 0; i < n.length; i++)
|
|
2229
|
-
for (let
|
|
2230
|
-
const c = getCorners(n, i,
|
|
2231
|
-
for (const
|
|
2253
|
+
for (let u = 0; u < n[0].length; u++) {
|
|
2254
|
+
const c = getCorners(n, i, u)
|
|
2255
|
+
for (const s of c) o.some(f => f.x === s.x && f.y === s.y) || o.push(s)
|
|
2232
2256
|
}
|
|
2233
2257
|
return o.map(i => ({ x: i.x * t, y: i.y * t }))
|
|
2234
2258
|
}
|
|
2235
2259
|
function findLines(n, t) {
|
|
2236
|
-
const e = filterCoordinates(n, (
|
|
2237
|
-
Object.assign(Object.assign({},
|
|
2260
|
+
const e = filterCoordinates(n, (s, f) => n[s][f] === 0 && n[s][f + 1] !== 0, 'row-first').map(s =>
|
|
2261
|
+
Object.assign(Object.assign({}, s), { dx: 1, dy: 0 })
|
|
2238
2262
|
),
|
|
2239
|
-
r = filterCoordinates(n, (
|
|
2240
|
-
Object.assign(Object.assign({},
|
|
2263
|
+
r = filterCoordinates(n, (s, f) => n[s][f] === 0 && n[s][f - 1] !== 0, 'row-first').map(s =>
|
|
2264
|
+
Object.assign(Object.assign({}, s), { dx: 1, dy: 0 })
|
|
2241
2265
|
),
|
|
2242
2266
|
o = filterCoordinates(
|
|
2243
2267
|
n,
|
|
2244
|
-
(
|
|
2268
|
+
(s, f) => {
|
|
2245
2269
|
var l
|
|
2246
|
-
return n[
|
|
2270
|
+
return n[s][f] === 0 && ((l = n[s - 1]) === null || l === void 0 ? void 0 : l[f]) !== 0
|
|
2247
2271
|
},
|
|
2248
2272
|
'column-first'
|
|
2249
|
-
).map(
|
|
2273
|
+
).map(s => Object.assign(Object.assign({}, s), { dx: 0, dy: 1 })),
|
|
2250
2274
|
i = filterCoordinates(
|
|
2251
2275
|
n,
|
|
2252
|
-
(
|
|
2276
|
+
(s, f) => {
|
|
2253
2277
|
var l
|
|
2254
|
-
return n[
|
|
2278
|
+
return n[s][f] === 0 && ((l = n[s + 1]) === null || l === void 0 ? void 0 : l[f]) !== 0
|
|
2255
2279
|
},
|
|
2256
2280
|
'column-first'
|
|
2257
|
-
).map(
|
|
2258
|
-
e.forEach(
|
|
2259
|
-
const
|
|
2260
|
-
c = group([...r, ...e], (
|
|
2261
|
-
return [...
|
|
2262
|
-
.map(
|
|
2263
|
-
.map(
|
|
2264
|
-
start: multiplyPoint(
|
|
2265
|
-
end: multiplyPoint(addPoint(
|
|
2281
|
+
).map(s => Object.assign(Object.assign({}, s), { dx: 0, dy: 1 }))
|
|
2282
|
+
e.forEach(s => s.y++), i.forEach(s => s.x++)
|
|
2283
|
+
const u = group([...o, ...i], (s, f) => s.x === f.x && s.y - 1 === f.y),
|
|
2284
|
+
c = group([...r, ...e], (s, f) => s.y === f.y && s.x - 1 === f.x)
|
|
2285
|
+
return [...u, ...c]
|
|
2286
|
+
.map(s => ({ start: s[0], end: last(s) }))
|
|
2287
|
+
.map(s => ({
|
|
2288
|
+
start: multiplyPoint(s.start, t),
|
|
2289
|
+
end: multiplyPoint(addPoint(s.end, { x: s.start.dx, y: s.start.dy }), t)
|
|
2266
2290
|
}))
|
|
2267
2291
|
}
|
|
2268
2292
|
function getAngleInRadians(n, t) {
|
|
@@ -2275,37 +2299,37 @@ function getLineIntersectionPoint(n, t, e, r) {
|
|
|
2275
2299
|
const o = (r.y - e.y) * (t.x - n.x) - (r.x - e.x) * (t.y - n.y)
|
|
2276
2300
|
if (o === 0) return null
|
|
2277
2301
|
let i = n.y - e.y,
|
|
2278
|
-
|
|
2279
|
-
const c = (r.x - e.x) * i - (r.y - e.y) *
|
|
2280
|
-
|
|
2302
|
+
u = n.x - e.x
|
|
2303
|
+
const c = (r.x - e.x) * i - (r.y - e.y) * u,
|
|
2304
|
+
s = (t.x - n.x) * i - (t.y - n.y) * u
|
|
2281
2305
|
return (
|
|
2282
2306
|
(i = c / o),
|
|
2283
|
-
(
|
|
2284
|
-
i > 0 && i < 1 &&
|
|
2307
|
+
(u = s / o),
|
|
2308
|
+
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
|
|
2285
2309
|
)
|
|
2286
2310
|
}
|
|
2287
2311
|
function raycast(n, t, e) {
|
|
2288
2312
|
const r = [],
|
|
2289
2313
|
o = pushPoint(n, e, 1e4)
|
|
2290
2314
|
for (const i of t) {
|
|
2291
|
-
const
|
|
2292
|
-
|
|
2315
|
+
const u = getLineIntersectionPoint(n, o, i.start, i.end)
|
|
2316
|
+
u && r.push(u)
|
|
2293
2317
|
}
|
|
2294
2318
|
return r.length
|
|
2295
|
-
? r.reduce((i,
|
|
2296
|
-
const c = getDistanceBetweenPoints(n,
|
|
2297
|
-
|
|
2298
|
-
return c <
|
|
2319
|
+
? r.reduce((i, u) => {
|
|
2320
|
+
const c = getDistanceBetweenPoints(n, u),
|
|
2321
|
+
s = getDistanceBetweenPoints(n, i)
|
|
2322
|
+
return c < s ? u : i
|
|
2299
2323
|
})
|
|
2300
2324
|
: null
|
|
2301
2325
|
}
|
|
2302
2326
|
function raycastCircle(n, t, e) {
|
|
2303
2327
|
const o = getSortedRayAngles(n, e),
|
|
2304
2328
|
i = []
|
|
2305
|
-
for (const
|
|
2306
|
-
const c = raycast(n, t,
|
|
2307
|
-
|
|
2308
|
-
c && i.push(c),
|
|
2329
|
+
for (const u of o) {
|
|
2330
|
+
const c = raycast(n, t, u - 0.001),
|
|
2331
|
+
s = raycast(n, t, u + 0.001)
|
|
2332
|
+
c && i.push(c), s && i.push(s)
|
|
2309
2333
|
}
|
|
2310
2334
|
return i
|
|
2311
2335
|
}
|
|
@@ -2425,7 +2449,8 @@ function raycastCircle(n, t, e) {
|
|
|
2425
2449
|
seconds,
|
|
2426
2450
|
minutes,
|
|
2427
2451
|
hours,
|
|
2428
|
-
make: makeDate
|
|
2452
|
+
make: makeDate,
|
|
2453
|
+
normalizeTime
|
|
2429
2454
|
}),
|
|
2430
2455
|
(exports.Objects = {
|
|
2431
2456
|
safeParse,
|