cafe-utility 14.1.0 → 15.0.1
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 +18 -11
- package/index.js +198 -165
- package/module.mjs +1 -1
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -54,7 +54,6 @@ declare function isBoolean(value: any): value is boolean;
|
|
|
54
54
|
declare function isDate(value: any): value is Date;
|
|
55
55
|
declare function isBlank(value: any): boolean;
|
|
56
56
|
declare function isId(value: any): value is number;
|
|
57
|
-
declare function isNumbool(value: any): value is 0 | 1;
|
|
58
57
|
declare function randomLetterString(length: number, generator?: () => number): string;
|
|
59
58
|
declare function randomAlphanumericString(length: number, generator?: () => number): string;
|
|
60
59
|
declare function randomRichAsciiString(length: number, generator?: () => number): string;
|
|
@@ -70,7 +69,6 @@ declare function asDate(date: any): Date;
|
|
|
70
69
|
declare function asNullableString(string: any): string | null;
|
|
71
70
|
declare function asEmptiableString(string: any): string;
|
|
72
71
|
declare function asId(value: any): number;
|
|
73
|
-
declare function asNumbool(value: any): 0 | 1;
|
|
74
72
|
declare function asTime(value: any): string;
|
|
75
73
|
declare function asArray(value: any): unknown[];
|
|
76
74
|
declare function asObject(value: any): Record<string, unknown>;
|
|
@@ -112,6 +110,7 @@ declare function interpolate(a: number, b: number, t: number): number;
|
|
|
112
110
|
declare function sum(array: number[]): number;
|
|
113
111
|
declare function average(array: number[]): number;
|
|
114
112
|
declare function median(array: number[]): number;
|
|
113
|
+
declare function getDistanceFromMidpoint(position: number, length: number): number;
|
|
115
114
|
declare function range(start: number, end: number): number[];
|
|
116
115
|
declare function includesAny(string: string, substrings: string[]): boolean;
|
|
117
116
|
declare function isChinese(string: string): boolean;
|
|
@@ -178,7 +177,9 @@ type StringSegment = {
|
|
|
178
177
|
symbol: string | null;
|
|
179
178
|
string: string;
|
|
180
179
|
};
|
|
181
|
-
declare function
|
|
180
|
+
declare function splitFormatting(string: string, symbol: string): StringSegment[];
|
|
181
|
+
declare function splitHashtags(string: string): StringSegment[];
|
|
182
|
+
declare function splitUrls(string: string): StringSegment[];
|
|
182
183
|
declare function base64ToUint8Array(base64: string): Uint8Array;
|
|
183
184
|
declare function uint8ArrayToBase64(array: Uint8Array): string;
|
|
184
185
|
declare function hexToUint8Array(hex: string): Uint8Array;
|
|
@@ -354,12 +355,16 @@ declare function makeAsyncQueue(concurrency?: number): {
|
|
|
354
355
|
enqueue(fn: () => Promise<void>): void;
|
|
355
356
|
drain: () => Promise<void>;
|
|
356
357
|
};
|
|
357
|
-
export declare class
|
|
358
|
-
|
|
359
|
-
constructor(value: T | null);
|
|
360
|
-
|
|
361
|
-
|
|
358
|
+
export declare class Optional<T> {
|
|
359
|
+
value: T | null | undefined;
|
|
360
|
+
constructor(value: T | null | undefined);
|
|
361
|
+
ifPresent(fn: (value: T) => void): this;
|
|
362
|
+
orElse(fn: () => void): void;
|
|
362
363
|
}
|
|
364
|
+
interface Newable<T> extends Function {
|
|
365
|
+
new (...args: any[]): T;
|
|
366
|
+
}
|
|
367
|
+
declare function findInstance<T, K extends T>(array: T[], type: Newable<K>): Optional<K>;
|
|
363
368
|
type Playbook<T> = {
|
|
364
369
|
ttl: number;
|
|
365
370
|
ttlMax?: number;
|
|
@@ -447,6 +452,7 @@ export declare const Arrays: {
|
|
|
447
452
|
requireNumberArgument: typeof requireNumberArgument;
|
|
448
453
|
bringToFront: typeof bringToFront;
|
|
449
454
|
bringToFrontInPlace: typeof bringToFrontInPlace;
|
|
455
|
+
findInstance: typeof findInstance;
|
|
450
456
|
};
|
|
451
457
|
export declare const System: {
|
|
452
458
|
sleepMillis: typeof sleepMillis;
|
|
@@ -460,6 +466,7 @@ export declare const Numbers: {
|
|
|
460
466
|
sum: typeof sum;
|
|
461
467
|
average: typeof average;
|
|
462
468
|
median: typeof median;
|
|
469
|
+
getDistanceFromMidpoint: typeof getDistanceFromMidpoint;
|
|
463
470
|
clamp: typeof clamp;
|
|
464
471
|
range: typeof range;
|
|
465
472
|
interpolate: typeof interpolate;
|
|
@@ -575,7 +582,6 @@ export declare const Types: {
|
|
|
575
582
|
isDate: typeof isDate;
|
|
576
583
|
isBlank: typeof isBlank;
|
|
577
584
|
isId: typeof isId;
|
|
578
|
-
isNumbool: typeof isNumbool;
|
|
579
585
|
isNullable: typeof isNullable;
|
|
580
586
|
asString: typeof asString;
|
|
581
587
|
asNumber: typeof asNumber;
|
|
@@ -585,7 +591,6 @@ export declare const Types: {
|
|
|
585
591
|
asNullableString: typeof asNullableString;
|
|
586
592
|
asEmptiableString: typeof asEmptiableString;
|
|
587
593
|
asId: typeof asId;
|
|
588
|
-
asNumbool: typeof asNumbool;
|
|
589
594
|
asTime: typeof asTime;
|
|
590
595
|
asArray: typeof asArray;
|
|
591
596
|
asObject: typeof asObject;
|
|
@@ -665,7 +670,9 @@ export declare const Strings: {
|
|
|
665
670
|
describeMarkdown: typeof describeMarkdown;
|
|
666
671
|
isBalanced: typeof isBalanced;
|
|
667
672
|
textToFormat: typeof textToFormat;
|
|
668
|
-
|
|
673
|
+
splitFormatting: typeof splitFormatting;
|
|
674
|
+
splitHashtags: typeof splitHashtags;
|
|
675
|
+
splitUrls: typeof splitUrls;
|
|
669
676
|
hexToUint8Array: typeof hexToUint8Array;
|
|
670
677
|
uint8ArrayToHex: typeof uint8ArrayToHex;
|
|
671
678
|
base64ToUint8Array: typeof base64ToUint8Array;
|
package/index.js
CHANGED
|
@@ -13,7 +13,7 @@ Object.defineProperty(exports, '__esModule', { value: !0 }),
|
|
|
13
13
|
exports.System =
|
|
14
14
|
exports.Arrays =
|
|
15
15
|
exports.Random =
|
|
16
|
-
exports.
|
|
16
|
+
exports.Optional =
|
|
17
17
|
void 0)
|
|
18
18
|
async function invertPromise(n) {
|
|
19
19
|
return new Promise((e, t) => n.then(t, e))
|
|
@@ -126,13 +126,13 @@ function pickManyUnique(n, e, t, r = Math.random) {
|
|
|
126
126
|
return o
|
|
127
127
|
}
|
|
128
128
|
function pickGuaranteed(n, e, t, r, o, i = Math.random) {
|
|
129
|
-
const u = n.filter(
|
|
130
|
-
|
|
131
|
-
for (e !== null &&
|
|
132
|
-
const
|
|
133
|
-
o(u[
|
|
129
|
+
const u = n.filter(s => s !== e && s !== t),
|
|
130
|
+
c = []
|
|
131
|
+
for (e !== null && c.push(e); u.length && c.length < r; ) {
|
|
132
|
+
const s = exports.Random.intBetween(0, u.length - 1, i)
|
|
133
|
+
o(u[s], c) && c.push(u[s]), u.splice(s, 1)
|
|
134
134
|
}
|
|
135
|
-
return shuffle(
|
|
135
|
+
return shuffle(c, i), { values: c, indexOfGuaranteed: e !== null ? c.indexOf(e) : -1 }
|
|
136
136
|
}
|
|
137
137
|
function last(n) {
|
|
138
138
|
return n[n.length - 1]
|
|
@@ -167,10 +167,10 @@ function setDeep(n, e, t) {
|
|
|
167
167
|
let o = n
|
|
168
168
|
for (let i = 0; i < r.length; i++) {
|
|
169
169
|
const u = r[i],
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
if (i === r.length - 1) return (o[
|
|
173
|
-
isObject(o[
|
|
170
|
+
c = i < r.length - 1 && r[i + 1].includes(']'),
|
|
171
|
+
l = u.includes(']') ? u.replace(/\[|\]/g, '') : u
|
|
172
|
+
if (i === r.length - 1) return (o[l] = t), t
|
|
173
|
+
isObject(o[l]) || (c ? (o[l] = []) : (o[l] = {})), (o = o[l])
|
|
174
174
|
}
|
|
175
175
|
return t
|
|
176
176
|
}
|
|
@@ -277,9 +277,6 @@ function isBlank(n) {
|
|
|
277
277
|
function isId(n) {
|
|
278
278
|
return isNumber(n) && Number.isInteger(n) && n >= 1
|
|
279
279
|
}
|
|
280
|
-
function isNumbool(n) {
|
|
281
|
-
return n === 0 || n === 1
|
|
282
|
-
}
|
|
283
280
|
const symbols = '!@#$%^&*()_+-=[]{}|;:<>?,./',
|
|
284
281
|
symbolsArray = '!@#$%^&*()_+-=[]{}|;:<>?,./'.split(''),
|
|
285
282
|
lowercaseAlphabet = 'abcdefghijklmnopqrstuvwxyz',
|
|
@@ -370,11 +367,6 @@ function asId(n) {
|
|
|
370
367
|
if (!isId(e)) throw new TypeError('Expected id, got: ' + n)
|
|
371
368
|
return e
|
|
372
369
|
}
|
|
373
|
-
function asNumbool(n) {
|
|
374
|
-
if (n === 1 || n === '1') return 1
|
|
375
|
-
if (n === 0 || n === '0') return 0
|
|
376
|
-
throw new TypeError('Expected numbool, got: ' + n)
|
|
377
|
-
}
|
|
378
370
|
function asTime(n) {
|
|
379
371
|
if (!isString(n)) throw new TypeError('Expected time, got: ' + n)
|
|
380
372
|
const e = n.split(':')
|
|
@@ -547,6 +539,9 @@ function median(n) {
|
|
|
547
539
|
t = Math.floor(e.length / 2)
|
|
548
540
|
return e.length % 2 === 0 ? (e[t] + e[t - 1]) / 2 : e[t]
|
|
549
541
|
}
|
|
542
|
+
function getDistanceFromMidpoint(n, e) {
|
|
543
|
+
return n - (e - 1) / 2
|
|
544
|
+
}
|
|
550
545
|
function range(n, e) {
|
|
551
546
|
const t = []
|
|
552
547
|
for (let r = n; r <= e; r++) t.push(r)
|
|
@@ -686,9 +681,9 @@ function expand(n) {
|
|
|
686
681
|
o = n.slice(0, t.index),
|
|
687
682
|
i = n.slice(t.index + t[0].length)
|
|
688
683
|
let u = []
|
|
689
|
-
for (const
|
|
690
|
-
const
|
|
691
|
-
u = u.concat(
|
|
684
|
+
for (const c of r) {
|
|
685
|
+
const s = expand(o + c + i)
|
|
686
|
+
u = u.concat(s)
|
|
692
687
|
}
|
|
693
688
|
return u
|
|
694
689
|
}
|
|
@@ -759,6 +754,14 @@ function indexOfEarliest(n, e, t = 0) {
|
|
|
759
754
|
}
|
|
760
755
|
return r
|
|
761
756
|
}
|
|
757
|
+
function indexOfWordBreak(n, e = 0) {
|
|
758
|
+
for (let t = e; t < n.length; t++) if (!isLetterOrDigit(n[t])) return t
|
|
759
|
+
return -1
|
|
760
|
+
}
|
|
761
|
+
function indexOfHashtag(n, e = 0) {
|
|
762
|
+
for (let t = e; t < n.length; t++) if (n[t] === '#' && isLetterOrDigit(n[t + 1])) return t
|
|
763
|
+
return -1
|
|
764
|
+
}
|
|
762
765
|
function lastIndexOfBefore(n, e, t = 0) {
|
|
763
766
|
return n.slice(0, t).lastIndexOf(e)
|
|
764
767
|
}
|
|
@@ -826,37 +829,71 @@ function replaceBlocks(n, e, t) {
|
|
|
826
829
|
;(r = n.indexOf(o, r) + i.length), (n = n.replace(o, i))
|
|
827
830
|
}
|
|
828
831
|
}
|
|
829
|
-
function
|
|
830
|
-
const
|
|
831
|
-
let
|
|
832
|
-
for (;
|
|
833
|
-
const
|
|
834
|
-
if (
|
|
835
|
-
|
|
832
|
+
function splitFormatting(n, e) {
|
|
833
|
+
const t = []
|
|
834
|
+
let r = 0
|
|
835
|
+
for (; r < n.length; ) {
|
|
836
|
+
const o = n.indexOf(e, r)
|
|
837
|
+
if (o === -1) {
|
|
838
|
+
t.push({ string: n.slice(r), symbol: null })
|
|
836
839
|
break
|
|
837
840
|
}
|
|
838
|
-
const
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
841
|
+
const i = n.indexOf(e, o + e.length)
|
|
842
|
+
if ((o > r && i !== -1 && t.push({ string: n.slice(r, o), symbol: null }), i === -1)) {
|
|
843
|
+
t.push({ string: n.slice(r), symbol: null })
|
|
844
|
+
break
|
|
845
|
+
}
|
|
846
|
+
t.push({ string: n.slice(o + e.length, i), symbol: e }), (r = i + e.length)
|
|
847
|
+
}
|
|
848
|
+
return t
|
|
849
|
+
}
|
|
850
|
+
function splitHashtags(n) {
|
|
851
|
+
const e = []
|
|
852
|
+
let t = 0
|
|
853
|
+
for (; t < n.length; ) {
|
|
854
|
+
const r = indexOfHashtag(n, t)
|
|
855
|
+
if (r === -1) {
|
|
856
|
+
e.push({ string: n.slice(t), symbol: null })
|
|
851
857
|
break
|
|
852
858
|
}
|
|
853
|
-
|
|
854
|
-
|
|
859
|
+
const o = indexOfWordBreak(n, r + 1)
|
|
860
|
+
if (o === -1) {
|
|
861
|
+
e.push({ string: n.slice(t, r), symbol: null }), e.push({ string: n.slice(r + 1), symbol: '#' })
|
|
855
862
|
break
|
|
856
863
|
}
|
|
857
|
-
r.push({ string: n.slice(
|
|
864
|
+
r > t && e.push({ string: n.slice(t, r), symbol: null }),
|
|
865
|
+
e.push({ string: n.slice(r + 1, o), symbol: '#' }),
|
|
866
|
+
(t = o)
|
|
858
867
|
}
|
|
859
|
-
return
|
|
868
|
+
return e
|
|
869
|
+
}
|
|
870
|
+
function splitUrls(n) {
|
|
871
|
+
const e = []
|
|
872
|
+
let t = 0
|
|
873
|
+
for (; t < n.length; ) {
|
|
874
|
+
const r = indexOfEarliest(n, ['http://', 'https://'], t)
|
|
875
|
+
if (r === -1) {
|
|
876
|
+
e.push({ string: n.slice(t), symbol: null })
|
|
877
|
+
break
|
|
878
|
+
}
|
|
879
|
+
const o = indexOfEarliest(
|
|
880
|
+
n,
|
|
881
|
+
[
|
|
882
|
+
' ',
|
|
883
|
+
`
|
|
884
|
+
`
|
|
885
|
+
],
|
|
886
|
+
r
|
|
887
|
+
)
|
|
888
|
+
if (o === -1) {
|
|
889
|
+
r > t && e.push({ string: n.slice(t, r), symbol: null }), e.push({ string: n.slice(r), symbol: 'http' })
|
|
890
|
+
break
|
|
891
|
+
}
|
|
892
|
+
r > t && e.push({ string: n.slice(t, r), symbol: null }),
|
|
893
|
+
e.push({ string: n.slice(r, o), symbol: 'http' }),
|
|
894
|
+
(t = o)
|
|
895
|
+
}
|
|
896
|
+
return e
|
|
860
897
|
}
|
|
861
898
|
const BASE64_CHARS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='
|
|
862
899
|
function base64ToUint8Array(n) {
|
|
@@ -868,13 +905,13 @@ function base64ToUint8Array(n) {
|
|
|
868
905
|
i = 0
|
|
869
906
|
for (; o < n.length; ) {
|
|
870
907
|
const u = BASE64_CHARS.indexOf(n.charAt(o++)),
|
|
871
|
-
s = BASE64_CHARS.indexOf(n.charAt(o++)),
|
|
872
908
|
c = BASE64_CHARS.indexOf(n.charAt(o++)),
|
|
873
|
-
|
|
874
|
-
l = (
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
909
|
+
s = BASE64_CHARS.indexOf(n.charAt(o++)),
|
|
910
|
+
l = BASE64_CHARS.indexOf(n.charAt(o++)),
|
|
911
|
+
f = (u << 2) | (c >> 4),
|
|
912
|
+
a = ((c & 15) << 4) | (s >> 2),
|
|
913
|
+
h = ((s & 3) << 6) | l
|
|
914
|
+
;(r[i++] = f), i < t && (r[i++] = a), i < t && (r[i++] = h)
|
|
878
915
|
}
|
|
879
916
|
return r
|
|
880
917
|
}
|
|
@@ -885,13 +922,13 @@ function uint8ArrayToBase64(n) {
|
|
|
885
922
|
const o = n[r],
|
|
886
923
|
i = n[r + 1],
|
|
887
924
|
u = n[r + 2],
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
;(e += BASE64_CHARS[
|
|
893
|
-
r + 1 < n.length ? (e += BASE64_CHARS[
|
|
894
|
-
r + 2 < n.length ? (e += BASE64_CHARS[
|
|
925
|
+
c = o >> 2,
|
|
926
|
+
s = ((o & 3) << 4) | (i >> 4),
|
|
927
|
+
l = ((i & 15) << 2) | (u >> 6),
|
|
928
|
+
f = u & 63
|
|
929
|
+
;(e += BASE64_CHARS[c] + BASE64_CHARS[s]),
|
|
930
|
+
r + 1 < n.length ? (e += BASE64_CHARS[l]) : t++,
|
|
931
|
+
r + 2 < n.length ? (e += BASE64_CHARS[f]) : t++
|
|
895
932
|
}
|
|
896
933
|
return t && (e += t === 1 ? '=' : '=='), e
|
|
897
934
|
}
|
|
@@ -931,7 +968,7 @@ function generateVariants(n, e, t, r = Math.random) {
|
|
|
931
968
|
const o = exports.Arrays.shuffle(
|
|
932
969
|
e.map(u => ({
|
|
933
970
|
variants: exports.Arrays.shuffle(
|
|
934
|
-
u.variants.map(
|
|
971
|
+
u.variants.map(c => c),
|
|
935
972
|
r
|
|
936
973
|
),
|
|
937
974
|
avoid: u.avoid
|
|
@@ -940,14 +977,14 @@ function generateVariants(n, e, t, r = Math.random) {
|
|
|
940
977
|
),
|
|
941
978
|
i = []
|
|
942
979
|
for (const u of o) {
|
|
943
|
-
const
|
|
944
|
-
|
|
945
|
-
if (
|
|
980
|
+
const c = u.variants.filter(l => l !== u.avoid),
|
|
981
|
+
s = c.find(l => n.includes(l))
|
|
982
|
+
if (s && (pushAll(i, explodeReplace(n, s, c)), i.length >= t)) break
|
|
946
983
|
}
|
|
947
984
|
if (i.length < t)
|
|
948
985
|
for (const u of o) {
|
|
949
|
-
const
|
|
950
|
-
if (
|
|
986
|
+
const c = u.variants.find(s => n.includes(s))
|
|
987
|
+
if (c && (pushAll(i, explodeReplace(n, c, u.variants)), i.length >= t)) break
|
|
951
988
|
}
|
|
952
989
|
return i.slice(0, t)
|
|
953
990
|
}
|
|
@@ -999,8 +1036,8 @@ function resolveVariableWithDefaultSyntax(n, e, t, r = '$', o = ':') {
|
|
|
999
1036
|
if (n[i + e.length + 1] === o)
|
|
1000
1037
|
if (n[i + e.length + 2] === o) n = n.replace(`${r}${e}${o}${o}`, t)
|
|
1001
1038
|
else {
|
|
1002
|
-
const
|
|
1003
|
-
n = n.replace(`${r}${e}${o}${
|
|
1039
|
+
const c = readNextWord(n, i + e.length + 2, ['_'])
|
|
1040
|
+
n = n.replace(`${r}${e}${o}${c}`, t)
|
|
1004
1041
|
}
|
|
1005
1042
|
else n = n.replace(`${r}${e}`, t)
|
|
1006
1043
|
i = n.indexOf(`${r}${e}`, i + t.length)
|
|
@@ -1028,8 +1065,8 @@ function resolveMarkdownLinks(n, e) {
|
|
|
1028
1065
|
o = n.indexOf(')', t)
|
|
1029
1066
|
if (r !== -1 && o !== -1) {
|
|
1030
1067
|
const [i, u] = n.slice(r + 1, o).split(']('),
|
|
1031
|
-
|
|
1032
|
-
n = n.slice(0, r) +
|
|
1068
|
+
c = e(i, u)
|
|
1069
|
+
n = n.slice(0, r) + c + n.slice(o + 1)
|
|
1033
1070
|
}
|
|
1034
1071
|
t = n.indexOf('](', t + 1)
|
|
1035
1072
|
}
|
|
@@ -1062,7 +1099,7 @@ function parseCsv(n, e = ',', t = '"') {
|
|
|
1062
1099
|
let o = '',
|
|
1063
1100
|
i = !1
|
|
1064
1101
|
const u = n.split('')
|
|
1065
|
-
for (const
|
|
1102
|
+
for (const c of u) c === e && !i ? (r.push(o), (o = '')) : c === t && ((!o && !i) || i) ? (i = !i) : (o += c)
|
|
1066
1103
|
return r.push(o), r
|
|
1067
1104
|
}
|
|
1068
1105
|
function humanizeProgress(n) {
|
|
@@ -1143,12 +1180,12 @@ function getAgoStructured(n, e) {
|
|
|
1143
1180
|
}
|
|
1144
1181
|
function countCycles(n, e, t) {
|
|
1145
1182
|
var r, o, i
|
|
1146
|
-
const
|
|
1147
|
-
|
|
1148
|
-
|
|
1183
|
+
const c = ((r = t?.now) !== null && r !== void 0 ? r : Date.now()) - n,
|
|
1184
|
+
s = Math.floor(c / e),
|
|
1185
|
+
l =
|
|
1149
1186
|
e / ((o = t?.precision) !== null && o !== void 0 ? o : 1) -
|
|
1150
|
-
Math.ceil((
|
|
1151
|
-
return { cycles:
|
|
1187
|
+
Math.ceil((c % e) / ((i = t?.precision) !== null && i !== void 0 ? i : 1))
|
|
1188
|
+
return { cycles: s, remaining: l }
|
|
1152
1189
|
}
|
|
1153
1190
|
const throttleTimers = {}
|
|
1154
1191
|
function throttle(n, e) {
|
|
@@ -1165,9 +1202,9 @@ function getProgress(n, e, t, r) {
|
|
|
1165
1202
|
const o = e / t,
|
|
1166
1203
|
i = r - n,
|
|
1167
1204
|
u = i / e,
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
return { deltaMs: i, progress: o, baseTimeMs: u, totalTimeMs:
|
|
1205
|
+
c = u * t,
|
|
1206
|
+
s = c - i
|
|
1207
|
+
return { deltaMs: i, progress: o, baseTimeMs: u, totalTimeMs: c, remainingTimeMs: s }
|
|
1171
1208
|
}
|
|
1172
1209
|
const dayNumberIndex = {
|
|
1173
1210
|
0: 'sunday',
|
|
@@ -1332,9 +1369,9 @@ function organiseWithLimits(n, e, t, r, o) {
|
|
|
1332
1369
|
for (const u of Object.keys(e)) i[u] = []
|
|
1333
1370
|
;(i[r] = []), o && (n = n.sort(o))
|
|
1334
1371
|
for (const u of n) {
|
|
1335
|
-
const
|
|
1336
|
-
|
|
1337
|
-
i[
|
|
1372
|
+
const c = u[t],
|
|
1373
|
+
s = e[c] ? c : r
|
|
1374
|
+
i[s].length >= e[s] ? i[r].push(u) : i[s].push(u)
|
|
1338
1375
|
}
|
|
1339
1376
|
return i
|
|
1340
1377
|
}
|
|
@@ -1398,11 +1435,11 @@ function formatNumber(n, e) {
|
|
|
1398
1435
|
const o = (t = e?.longForm) !== null && t !== void 0 ? t : !1,
|
|
1399
1436
|
i = e?.unit ? ` ${e.unit}` : '',
|
|
1400
1437
|
u = o ? longNumberUnits : shortNumberUnits,
|
|
1401
|
-
|
|
1438
|
+
c = (r = e?.precision) !== null && r !== void 0 ? r : 1
|
|
1402
1439
|
if (n < thresholds[0]) return `${n}${i}`
|
|
1403
|
-
for (let
|
|
1404
|
-
if (n < thresholds[
|
|
1405
|
-
return `${(n / thresholds[thresholds.length - 1]).toFixed(
|
|
1440
|
+
for (let s = 0; s < thresholds.length - 1; s++)
|
|
1441
|
+
if (n < thresholds[s + 1]) return `${(n / thresholds[s]).toFixed(c)}${o ? ' ' : ''}${u[s]}${i}`
|
|
1442
|
+
return `${(n / thresholds[thresholds.length - 1]).toFixed(c)}${o ? ' ' : ''}${u[thresholds.length - 1]}${i}`
|
|
1406
1443
|
}
|
|
1407
1444
|
function makeNumber(n) {
|
|
1408
1445
|
const e = parseFloat(n)
|
|
@@ -1481,20 +1518,20 @@ function flip(n) {
|
|
|
1481
1518
|
}
|
|
1482
1519
|
function getAllPermutations(n) {
|
|
1483
1520
|
const e = Object.keys(n),
|
|
1484
|
-
t = e.map(
|
|
1485
|
-
r = t.reduce((
|
|
1521
|
+
t = e.map(c => n[c].length),
|
|
1522
|
+
r = t.reduce((c, s) => (c *= s))
|
|
1486
1523
|
let o = 1
|
|
1487
1524
|
const i = [1]
|
|
1488
|
-
for (let
|
|
1525
|
+
for (let c = 0; c < t.length - 1; c++) (o *= t[c]), i.push(o)
|
|
1489
1526
|
const u = []
|
|
1490
|
-
for (let
|
|
1491
|
-
const
|
|
1492
|
-
for (let
|
|
1493
|
-
const
|
|
1494
|
-
a = Math.floor(
|
|
1495
|
-
|
|
1527
|
+
for (let c = 0; c < r; c++) {
|
|
1528
|
+
const s = {}
|
|
1529
|
+
for (let l = 0; l < e.length; l++) {
|
|
1530
|
+
const f = n[e[l]],
|
|
1531
|
+
a = Math.floor(c / i[l]) % f.length
|
|
1532
|
+
s[e[l]] = f[a]
|
|
1496
1533
|
}
|
|
1497
|
-
u.push(
|
|
1534
|
+
u.push(s)
|
|
1498
1535
|
}
|
|
1499
1536
|
return u
|
|
1500
1537
|
}
|
|
@@ -1507,14 +1544,14 @@ function getFlatNotation(n, e, t) {
|
|
|
1507
1544
|
function flattenInner(n, e, t, r, o) {
|
|
1508
1545
|
if (!isObject(e)) return e
|
|
1509
1546
|
for (const [i, u] of Object.entries(e)) {
|
|
1510
|
-
const
|
|
1547
|
+
const c = getFlatNotation(t, i, r)
|
|
1511
1548
|
Array.isArray(u)
|
|
1512
1549
|
? o
|
|
1513
|
-
? flattenInner(n, u,
|
|
1514
|
-
: (n[
|
|
1550
|
+
? flattenInner(n, u, c, !0, o)
|
|
1551
|
+
: (n[c] = u.map(s => flattenInner(Array.isArray(s) ? [] : {}, s, '', !1, o)))
|
|
1515
1552
|
: isObject(u)
|
|
1516
|
-
? flattenInner(n, u,
|
|
1517
|
-
: (n[
|
|
1553
|
+
? flattenInner(n, u, c, !1, o)
|
|
1554
|
+
: (n[c] = u)
|
|
1518
1555
|
}
|
|
1519
1556
|
return n
|
|
1520
1557
|
}
|
|
@@ -1580,9 +1617,9 @@ function makeUnique(n, e) {
|
|
|
1580
1617
|
function countUnique(n, e, t, r, o) {
|
|
1581
1618
|
const i = e ? n.map(e) : n,
|
|
1582
1619
|
u = {}
|
|
1583
|
-
for (const
|
|
1584
|
-
const
|
|
1585
|
-
return t ? Object.keys(
|
|
1620
|
+
for (const s of i) u[s] = (u[s] || 0) + 1
|
|
1621
|
+
const c = r ? sortObjectValues(u, o ? (s, l) => s[1] - l[1] : (s, l) => l[1] - s[1]) : u
|
|
1622
|
+
return t ? Object.keys(c) : c
|
|
1586
1623
|
}
|
|
1587
1624
|
function sortObjectValues(n, e) {
|
|
1588
1625
|
return Object.fromEntries(Object.entries(n).sort(e))
|
|
@@ -1674,29 +1711,23 @@ function makeAsyncQueue(n = 1) {
|
|
|
1674
1711
|
drain: i
|
|
1675
1712
|
}
|
|
1676
1713
|
}
|
|
1677
|
-
class
|
|
1714
|
+
class Optional {
|
|
1678
1715
|
constructor(e) {
|
|
1679
1716
|
this.value = e
|
|
1680
1717
|
}
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
if (isPromise(this.value)) return new Maybe(this.value.then(t => (t != null ? e(t) : null)).catch(() => null))
|
|
1684
|
-
try {
|
|
1685
|
-
const t = e(this.value)
|
|
1686
|
-
return new Maybe(t)
|
|
1687
|
-
} catch {
|
|
1688
|
-
return new Maybe(null)
|
|
1689
|
-
}
|
|
1718
|
+
ifPresent(e) {
|
|
1719
|
+
return this.value && e(this.value), this
|
|
1690
1720
|
}
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
} catch {
|
|
1695
|
-
return null
|
|
1696
|
-
}
|
|
1721
|
+
orElse(e) {
|
|
1722
|
+
var t
|
|
1723
|
+
;((t = this.value) !== null && t !== void 0) || e()
|
|
1697
1724
|
}
|
|
1698
1725
|
}
|
|
1699
|
-
exports.
|
|
1726
|
+
exports.Optional = Optional
|
|
1727
|
+
function findInstance(n, e) {
|
|
1728
|
+
const t = n.find(r => r instanceof e)
|
|
1729
|
+
return new Optional(t)
|
|
1730
|
+
}
|
|
1700
1731
|
function tickPlaybook(n) {
|
|
1701
1732
|
if (n.length === 0) return null
|
|
1702
1733
|
const e = n[0]
|
|
@@ -1706,7 +1737,7 @@ function tickPlaybook(n) {
|
|
|
1706
1737
|
)
|
|
1707
1738
|
}
|
|
1708
1739
|
function getArgument(n, e, t, r) {
|
|
1709
|
-
const o = n.findIndex(
|
|
1740
|
+
const o = n.findIndex(c => c.endsWith('-' + e) || c.includes('-' + e + '=')),
|
|
1710
1741
|
i = n[o]
|
|
1711
1742
|
if (!i) return (t || {})[r || e || ''] || null
|
|
1712
1743
|
if (i.includes('=')) return i.split('=')[1]
|
|
@@ -1723,14 +1754,14 @@ function getNumberArgument(n, e, t, r) {
|
|
|
1723
1754
|
}
|
|
1724
1755
|
}
|
|
1725
1756
|
function getBooleanArgument(n, e, t, r) {
|
|
1726
|
-
const o = n.some(
|
|
1757
|
+
const o = n.some(s => s.endsWith('-' + e)),
|
|
1727
1758
|
i = getArgument(n, e, t, r)
|
|
1728
1759
|
if (!i && o) return !0
|
|
1729
1760
|
if (!i && !o) return null
|
|
1730
1761
|
const u = ['true', '1', 'yes', 'y', 'on'],
|
|
1731
|
-
|
|
1762
|
+
c = ['false', '0', 'no', 'n', 'off']
|
|
1732
1763
|
if (u.includes(i.toLowerCase())) return !0
|
|
1733
|
-
if (
|
|
1764
|
+
if (c.includes(i.toLowerCase())) return !1
|
|
1734
1765
|
throw Error(`Invalid boolean argument ${e}: ${i}`)
|
|
1735
1766
|
}
|
|
1736
1767
|
function requireStringArgument(n, e, t, r) {
|
|
@@ -1813,24 +1844,24 @@ function isBottommost(n, e, t) {
|
|
|
1813
1844
|
return !n[e][t + 1]
|
|
1814
1845
|
}
|
|
1815
1846
|
function getCorners(n, e, t) {
|
|
1816
|
-
var r, o, i, u, s,
|
|
1847
|
+
var r, o, i, u, c, s, l, f
|
|
1817
1848
|
const a = []
|
|
1818
1849
|
return n[e][t]
|
|
1819
1850
|
? isHorizontalLine(n, e, t) || isVerticalLine(n, e, t)
|
|
1820
1851
|
? []
|
|
1821
|
-
: (!(!((
|
|
1852
|
+
: (!(!((c = n[e - 1]) === null || c === void 0) && c[t - 1]) &&
|
|
1822
1853
|
isLeftmost(n, e, t) &&
|
|
1823
1854
|
isTopmost(n, e, t) &&
|
|
1824
1855
|
a.push({ x: e, y: t }),
|
|
1825
|
-
!(!((
|
|
1856
|
+
!(!((s = n[e + 1]) === null || s === void 0) && s[t - 1]) &&
|
|
1826
1857
|
isRightmost(n, e, t) &&
|
|
1827
1858
|
isTopmost(n, e, t) &&
|
|
1828
1859
|
a.push({ x: e + 1, y: t }),
|
|
1829
|
-
!(!((
|
|
1860
|
+
!(!((l = n[e - 1]) === null || l === void 0) && l[t + 1]) &&
|
|
1830
1861
|
isLeftmost(n, e, t) &&
|
|
1831
1862
|
isBottommost(n, e, t) &&
|
|
1832
1863
|
a.push({ x: e, y: t + 1 }),
|
|
1833
|
-
!(!((
|
|
1864
|
+
!(!((f = n[e + 1]) === null || f === void 0) && f[t + 1]) &&
|
|
1834
1865
|
isRightmost(n, e, t) &&
|
|
1835
1866
|
isBottommost(n, e, t) &&
|
|
1836
1867
|
a.push({ x: e + 1, y: t + 1 }),
|
|
@@ -1850,42 +1881,42 @@ function findCorners(n, e, t, r) {
|
|
|
1850
1881
|
]
|
|
1851
1882
|
for (let i = 0; i < n.length; i++)
|
|
1852
1883
|
for (let u = 0; u < n[0].length; u++) {
|
|
1853
|
-
const
|
|
1854
|
-
for (const
|
|
1884
|
+
const c = getCorners(n, i, u)
|
|
1885
|
+
for (const s of c) o.some(l => l.x === s.x && l.y === s.y) || o.push(s)
|
|
1855
1886
|
}
|
|
1856
1887
|
return o.map(i => ({ x: i.x * e, y: i.y * e }))
|
|
1857
1888
|
}
|
|
1858
1889
|
function findLines(n, e) {
|
|
1859
|
-
const t = filterCoordinates(n, (
|
|
1860
|
-
Object.assign(Object.assign({},
|
|
1890
|
+
const t = filterCoordinates(n, (s, l) => n[s][l] === 0 && n[s][l + 1] !== 0, 'row-first').map(s =>
|
|
1891
|
+
Object.assign(Object.assign({}, s), { dx: 1, dy: 0 })
|
|
1861
1892
|
),
|
|
1862
|
-
r = filterCoordinates(n, (
|
|
1863
|
-
Object.assign(Object.assign({},
|
|
1893
|
+
r = filterCoordinates(n, (s, l) => n[s][l] === 0 && n[s][l - 1] !== 0, 'row-first').map(s =>
|
|
1894
|
+
Object.assign(Object.assign({}, s), { dx: 1, dy: 0 })
|
|
1864
1895
|
),
|
|
1865
1896
|
o = filterCoordinates(
|
|
1866
1897
|
n,
|
|
1867
|
-
(
|
|
1868
|
-
var
|
|
1869
|
-
return n[
|
|
1898
|
+
(s, l) => {
|
|
1899
|
+
var f
|
|
1900
|
+
return n[s][l] === 0 && ((f = n[s - 1]) === null || f === void 0 ? void 0 : f[l]) !== 0
|
|
1870
1901
|
},
|
|
1871
1902
|
'column-first'
|
|
1872
|
-
).map(
|
|
1903
|
+
).map(s => Object.assign(Object.assign({}, s), { dx: 0, dy: 1 })),
|
|
1873
1904
|
i = filterCoordinates(
|
|
1874
1905
|
n,
|
|
1875
|
-
(
|
|
1876
|
-
var
|
|
1877
|
-
return n[
|
|
1906
|
+
(s, l) => {
|
|
1907
|
+
var f
|
|
1908
|
+
return n[s][l] === 0 && ((f = n[s + 1]) === null || f === void 0 ? void 0 : f[l]) !== 0
|
|
1878
1909
|
},
|
|
1879
1910
|
'column-first'
|
|
1880
|
-
).map(
|
|
1881
|
-
t.forEach(
|
|
1882
|
-
const u = group([...o, ...i], (
|
|
1883
|
-
|
|
1884
|
-
return [...u, ...
|
|
1885
|
-
.map(
|
|
1886
|
-
.map(
|
|
1887
|
-
start: multiplyPoint(
|
|
1888
|
-
end: multiplyPoint(addPoint(
|
|
1911
|
+
).map(s => Object.assign(Object.assign({}, s), { dx: 0, dy: 1 }))
|
|
1912
|
+
t.forEach(s => s.y++), i.forEach(s => s.x++)
|
|
1913
|
+
const u = group([...o, ...i], (s, l) => s.x === l.x && s.y - 1 === l.y),
|
|
1914
|
+
c = group([...r, ...t], (s, l) => s.y === l.y && s.x - 1 === l.x)
|
|
1915
|
+
return [...u, ...c]
|
|
1916
|
+
.map(s => ({ start: s[0], end: last(s) }))
|
|
1917
|
+
.map(s => ({
|
|
1918
|
+
start: multiplyPoint(s.start, e),
|
|
1919
|
+
end: multiplyPoint(addPoint(s.end, { x: s.start.dx, y: s.start.dy }), e)
|
|
1889
1920
|
}))
|
|
1890
1921
|
}
|
|
1891
1922
|
function getAngleInRadians(n, e) {
|
|
@@ -1899,11 +1930,11 @@ function getLineIntersectionPoint(n, e, t, r) {
|
|
|
1899
1930
|
if (o === 0) return null
|
|
1900
1931
|
let i = n.y - t.y,
|
|
1901
1932
|
u = n.x - t.x
|
|
1902
|
-
const
|
|
1903
|
-
|
|
1933
|
+
const c = (r.x - t.x) * i - (r.y - t.y) * u,
|
|
1934
|
+
s = (e.x - n.x) * i - (e.y - n.y) * u
|
|
1904
1935
|
return (
|
|
1905
|
-
(i =
|
|
1906
|
-
(u =
|
|
1936
|
+
(i = c / o),
|
|
1937
|
+
(u = s / o),
|
|
1907
1938
|
i > 0 && i < 1 && u > 0 && u < 1 ? { x: n.x + i * (e.x - n.x), y: n.y + i * (e.y - n.y) } : null
|
|
1908
1939
|
)
|
|
1909
1940
|
}
|
|
@@ -1916,9 +1947,9 @@ function raycast(n, e, t) {
|
|
|
1916
1947
|
}
|
|
1917
1948
|
return r.length
|
|
1918
1949
|
? r.reduce((i, u) => {
|
|
1919
|
-
const
|
|
1920
|
-
|
|
1921
|
-
return
|
|
1950
|
+
const c = getDistanceBetweenPoints(n, u),
|
|
1951
|
+
s = getDistanceBetweenPoints(n, i)
|
|
1952
|
+
return c < s ? u : i
|
|
1922
1953
|
})
|
|
1923
1954
|
: null
|
|
1924
1955
|
}
|
|
@@ -1926,9 +1957,9 @@ function raycastCircle(n, e, t) {
|
|
|
1926
1957
|
const o = getSortedRayAngles(n, t),
|
|
1927
1958
|
i = []
|
|
1928
1959
|
for (const u of o) {
|
|
1929
|
-
const
|
|
1930
|
-
|
|
1931
|
-
|
|
1960
|
+
const c = raycast(n, e, u - 0.001),
|
|
1961
|
+
s = raycast(n, e, u + 0.001)
|
|
1962
|
+
c && i.push(c), s && i.push(s)
|
|
1932
1963
|
}
|
|
1933
1964
|
return i
|
|
1934
1965
|
}
|
|
@@ -1976,7 +2007,8 @@ function raycastCircle(n, e, t) {
|
|
|
1976
2007
|
requireStringArgument,
|
|
1977
2008
|
requireNumberArgument,
|
|
1978
2009
|
bringToFront,
|
|
1979
|
-
bringToFrontInPlace
|
|
2010
|
+
bringToFrontInPlace,
|
|
2011
|
+
findInstance
|
|
1980
2012
|
}),
|
|
1981
2013
|
(exports.System = { sleepMillis, forever, scheduleMany, waitFor, expandError }),
|
|
1982
2014
|
(exports.Numbers = {
|
|
@@ -1984,6 +2016,7 @@ function raycastCircle(n, e, t) {
|
|
|
1984
2016
|
sum,
|
|
1985
2017
|
average,
|
|
1986
2018
|
median,
|
|
2019
|
+
getDistanceFromMidpoint,
|
|
1987
2020
|
clamp,
|
|
1988
2021
|
range,
|
|
1989
2022
|
interpolate,
|
|
@@ -2091,7 +2124,6 @@ function raycastCircle(n, e, t) {
|
|
|
2091
2124
|
isDate,
|
|
2092
2125
|
isBlank,
|
|
2093
2126
|
isId,
|
|
2094
|
-
isNumbool,
|
|
2095
2127
|
isNullable,
|
|
2096
2128
|
asString,
|
|
2097
2129
|
asNumber,
|
|
@@ -2101,7 +2133,6 @@ function raycastCircle(n, e, t) {
|
|
|
2101
2133
|
asNullableString,
|
|
2102
2134
|
asEmptiableString,
|
|
2103
2135
|
asId,
|
|
2104
|
-
asNumbool,
|
|
2105
2136
|
asTime,
|
|
2106
2137
|
asArray,
|
|
2107
2138
|
asObject,
|
|
@@ -2181,7 +2212,9 @@ function raycastCircle(n, e, t) {
|
|
|
2181
2212
|
describeMarkdown,
|
|
2182
2213
|
isBalanced,
|
|
2183
2214
|
textToFormat,
|
|
2184
|
-
|
|
2215
|
+
splitFormatting,
|
|
2216
|
+
splitHashtags,
|
|
2217
|
+
splitUrls,
|
|
2185
2218
|
hexToUint8Array,
|
|
2186
2219
|
uint8ArrayToHex,
|
|
2187
2220
|
base64ToUint8Array,
|
package/module.mjs
CHANGED
|
@@ -12,5 +12,5 @@ export const Random = utility.Random
|
|
|
12
12
|
export const Strings = utility.Strings
|
|
13
13
|
export const System = utility.System
|
|
14
14
|
export const Types = utility.Types
|
|
15
|
-
export const
|
|
15
|
+
export const Optional = utility.Optional
|
|
16
16
|
export const Vector = utility.Vector
|