cafe-utility 23.3.0 → 23.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 +12 -0
- package/index.js +134 -114
- package/module.mjs +2 -0
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -453,6 +453,18 @@ export declare class Optional<T> {
|
|
|
453
453
|
ifPresent(fn: (value: T) => void): this;
|
|
454
454
|
orElse(fn: () => void): void;
|
|
455
455
|
}
|
|
456
|
+
export declare class Lazy<T> {
|
|
457
|
+
private readonly supplier;
|
|
458
|
+
private value;
|
|
459
|
+
constructor(supplier: () => T);
|
|
460
|
+
get(): T;
|
|
461
|
+
}
|
|
462
|
+
export declare class AsyncLazy<T> {
|
|
463
|
+
private readonly supplier;
|
|
464
|
+
private value;
|
|
465
|
+
constructor(supplier: () => Promise<T>);
|
|
466
|
+
get(): Promise<T>;
|
|
467
|
+
}
|
|
456
468
|
interface Newable<T> extends Function {
|
|
457
469
|
new (...args: any[]): T;
|
|
458
470
|
}
|
package/index.js
CHANGED
|
@@ -14,6 +14,8 @@ Object.defineProperty(exports, '__esModule', { value: !0 }),
|
|
|
14
14
|
exports.Random =
|
|
15
15
|
exports.Binary =
|
|
16
16
|
exports.PubSubChannel =
|
|
17
|
+
exports.AsyncLazy =
|
|
18
|
+
exports.Lazy =
|
|
17
19
|
exports.Optional =
|
|
18
20
|
void 0)
|
|
19
21
|
async function invertPromise(n) {
|
|
@@ -143,13 +145,13 @@ function pickManyUnique(n, t, e, r = Math.random) {
|
|
|
143
145
|
return o
|
|
144
146
|
}
|
|
145
147
|
function pickGuaranteed(n, t, e, r, o, i = Math.random) {
|
|
146
|
-
const u = n.filter(
|
|
147
|
-
|
|
148
|
-
for (t !== null &&
|
|
149
|
-
const
|
|
150
|
-
o(u[
|
|
148
|
+
const u = n.filter(s => s !== t && s !== e),
|
|
149
|
+
c = []
|
|
150
|
+
for (t !== null && c.push(t); u.length && c.length < r; ) {
|
|
151
|
+
const s = exports.Random.intBetween(0, u.length - 1, i)
|
|
152
|
+
o(u[s], c) && c.push(u[s]), u.splice(s, 1)
|
|
151
153
|
}
|
|
152
|
-
return shuffle(
|
|
154
|
+
return shuffle(c, i), { values: c, indexOfGuaranteed: t !== null ? c.indexOf(t) : -1 }
|
|
153
155
|
}
|
|
154
156
|
function last(n) {
|
|
155
157
|
if (!n.length) throw Error('Received empty array')
|
|
@@ -189,10 +191,10 @@ function setDeep(n, t, e) {
|
|
|
189
191
|
let o = n
|
|
190
192
|
for (let i = 0; i < r.length; i++) {
|
|
191
193
|
const u = r[i],
|
|
192
|
-
|
|
194
|
+
c = i < r.length - 1 && r[i + 1].includes(']'),
|
|
193
195
|
f = u.includes(']') ? u.replace(/\[|\]/g, '') : u
|
|
194
196
|
if (i === r.length - 1) return (o[f] = e), e
|
|
195
|
-
isObject(o[f]) || (
|
|
197
|
+
isObject(o[f]) || (c ? (o[f] = []) : (o[f] = {})), (o = o[f])
|
|
196
198
|
}
|
|
197
199
|
return e
|
|
198
200
|
}
|
|
@@ -259,9 +261,9 @@ function rgbToHex(n) {
|
|
|
259
261
|
function haversineDistanceToMeters(n, t, e, r) {
|
|
260
262
|
const i = (n * Math.PI) / 180,
|
|
261
263
|
u = (e * Math.PI) / 180,
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
f = Math.sin(
|
|
264
|
+
c = ((e - n) * Math.PI) / 180,
|
|
265
|
+
s = ((r - t) * Math.PI) / 180,
|
|
266
|
+
f = Math.sin(c / 2) * Math.sin(c / 2) + Math.cos(i) * Math.cos(u) * Math.sin(s / 2) * Math.sin(s / 2)
|
|
265
267
|
return 6371e3 * (2 * Math.atan2(Math.sqrt(f), Math.sqrt(1 - f)))
|
|
266
268
|
}
|
|
267
269
|
function roundToNearest(n, t) {
|
|
@@ -783,9 +785,9 @@ function expand(n) {
|
|
|
783
785
|
o = n.slice(0, e.index),
|
|
784
786
|
i = n.slice(e.index + e[0].length)
|
|
785
787
|
let u = []
|
|
786
|
-
for (const
|
|
787
|
-
const
|
|
788
|
-
u = u.concat(
|
|
788
|
+
for (const c of r) {
|
|
789
|
+
const s = expand(o + c + i)
|
|
790
|
+
u = u.concat(s)
|
|
789
791
|
}
|
|
790
792
|
return u
|
|
791
793
|
}
|
|
@@ -1019,12 +1021,12 @@ function base64ToUint8Array(n) {
|
|
|
1019
1021
|
i = 0
|
|
1020
1022
|
for (; o < n.length; ) {
|
|
1021
1023
|
const u = BASE64_CHARS.indexOf(n.charAt(o++)),
|
|
1022
|
-
s = BASE64_CHARS.indexOf(n.charAt(o++)),
|
|
1023
1024
|
c = BASE64_CHARS.indexOf(n.charAt(o++)),
|
|
1025
|
+
s = BASE64_CHARS.indexOf(n.charAt(o++)),
|
|
1024
1026
|
f = BASE64_CHARS.indexOf(n.charAt(o++)),
|
|
1025
|
-
l = (u << 2) | (
|
|
1026
|
-
a = ((
|
|
1027
|
-
h = ((
|
|
1027
|
+
l = (u << 2) | (c >> 4),
|
|
1028
|
+
a = ((c & 15) << 4) | (s >> 2),
|
|
1029
|
+
h = ((s & 3) << 6) | f
|
|
1028
1030
|
;(r[i++] = l), i < e && (r[i++] = a), i < e && (r[i++] = h)
|
|
1029
1031
|
}
|
|
1030
1032
|
return r
|
|
@@ -1036,11 +1038,11 @@ function uint8ArrayToBase64(n) {
|
|
|
1036
1038
|
const o = n[r],
|
|
1037
1039
|
i = n[r + 1],
|
|
1038
1040
|
u = n[r + 2],
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
+
c = o >> 2,
|
|
1042
|
+
s = ((o & 3) << 4) | (i >> 4),
|
|
1041
1043
|
f = ((i & 15) << 2) | (u >> 6),
|
|
1042
1044
|
l = u & 63
|
|
1043
|
-
;(t += BASE64_CHARS[
|
|
1045
|
+
;(t += BASE64_CHARS[c] + BASE64_CHARS[s]),
|
|
1044
1046
|
r + 1 < n.length ? (t += BASE64_CHARS[f]) : e++,
|
|
1045
1047
|
r + 2 < n.length ? (t += BASE64_CHARS[l]) : e++
|
|
1046
1048
|
}
|
|
@@ -1082,7 +1084,7 @@ function generateVariants(n, t, e, r = Math.random) {
|
|
|
1082
1084
|
const o = exports.Arrays.shuffle(
|
|
1083
1085
|
t.map(u => ({
|
|
1084
1086
|
variants: exports.Arrays.shuffle(
|
|
1085
|
-
u.variants.map(
|
|
1087
|
+
u.variants.map(c => c),
|
|
1086
1088
|
r
|
|
1087
1089
|
),
|
|
1088
1090
|
avoid: u.avoid
|
|
@@ -1091,14 +1093,14 @@ function generateVariants(n, t, e, r = Math.random) {
|
|
|
1091
1093
|
),
|
|
1092
1094
|
i = []
|
|
1093
1095
|
for (const u of o) {
|
|
1094
|
-
const
|
|
1095
|
-
|
|
1096
|
-
if (
|
|
1096
|
+
const c = u.variants.filter(f => f !== u.avoid),
|
|
1097
|
+
s = c.find(f => n.includes(f))
|
|
1098
|
+
if (s && (pushAll(i, explodeReplace(n, s, c)), i.length >= e)) break
|
|
1097
1099
|
}
|
|
1098
1100
|
if (i.length < e)
|
|
1099
1101
|
for (const u of o) {
|
|
1100
|
-
const
|
|
1101
|
-
if (
|
|
1102
|
+
const c = u.variants.find(s => n.includes(s))
|
|
1103
|
+
if (c && (pushAll(i, explodeReplace(n, c, u.variants)), i.length >= e)) break
|
|
1102
1104
|
}
|
|
1103
1105
|
return i.slice(0, e)
|
|
1104
1106
|
}
|
|
@@ -1133,9 +1135,9 @@ function toLines(n, t, e = {}) {
|
|
|
1133
1135
|
let o = '',
|
|
1134
1136
|
i = 0
|
|
1135
1137
|
for (let u = 0; u < n.length; u++) {
|
|
1136
|
-
const
|
|
1137
|
-
|
|
1138
|
-
if (((o +=
|
|
1138
|
+
const c = n[u],
|
|
1139
|
+
s = e[c] || 1
|
|
1140
|
+
if (((o += c), (i += s), i > t)) {
|
|
1139
1141
|
const { line: f, rest: l } = breakLine(o)
|
|
1140
1142
|
r.push(f),
|
|
1141
1143
|
(o = l),
|
|
@@ -1190,8 +1192,8 @@ function resolveVariableWithDefaultSyntax(n, t, e, r = '$', o = ':') {
|
|
|
1190
1192
|
if (n[i + t.length + 1] === o)
|
|
1191
1193
|
if (n[i + t.length + 2] === o) n = n.replace(`${r}${t}${o}${o}`, e)
|
|
1192
1194
|
else {
|
|
1193
|
-
const
|
|
1194
|
-
n = n.replace(`${r}${t}${o}${
|
|
1195
|
+
const c = readNextWord(n, i + t.length + 2, ['_'])
|
|
1196
|
+
n = n.replace(`${r}${t}${o}${c}`, e)
|
|
1195
1197
|
}
|
|
1196
1198
|
else n = n.replace(`${r}${t}`, e)
|
|
1197
1199
|
i = n.indexOf(`${r}${t}`, i + e.length)
|
|
@@ -1219,8 +1221,8 @@ function resolveMarkdownLinks(n, t) {
|
|
|
1219
1221
|
o = n.indexOf(')', e)
|
|
1220
1222
|
if (r !== -1 && o !== -1) {
|
|
1221
1223
|
const [i, u] = n.slice(r + 1, o).split(']('),
|
|
1222
|
-
|
|
1223
|
-
n = n.slice(0, r) +
|
|
1224
|
+
c = t(i, u)
|
|
1225
|
+
n = n.slice(0, r) + c + n.slice(o + 1)
|
|
1224
1226
|
}
|
|
1225
1227
|
e = n.indexOf('](', e + 1)
|
|
1226
1228
|
}
|
|
@@ -1258,8 +1260,8 @@ function reposition(n, t, e, r) {
|
|
|
1258
1260
|
const o = n.find(u => u[t] === e),
|
|
1259
1261
|
i = n.find(u => u[t] === e + r)
|
|
1260
1262
|
o && i ? ((o[t] = e + r), (i[t] = e)) : o && (o[t] = e + r),
|
|
1261
|
-
n.sort((u,
|
|
1262
|
-
n.forEach((u,
|
|
1263
|
+
n.sort((u, c) => asNumber(u[t]) - asNumber(c[t])),
|
|
1264
|
+
n.forEach((u, c) => (u[t] = c + 1))
|
|
1263
1265
|
}
|
|
1264
1266
|
function unwrapSingleKey(n) {
|
|
1265
1267
|
const t = Object.keys(n)
|
|
@@ -1274,7 +1276,7 @@ function parseCsv(n, t = ',', e = '"') {
|
|
|
1274
1276
|
let o = '',
|
|
1275
1277
|
i = !1
|
|
1276
1278
|
const u = n.split('')
|
|
1277
|
-
for (const
|
|
1279
|
+
for (const c of u) c === t && !i ? (r.push(o), (o = '')) : c === e && ((!o && !i) || i) ? (i = !i) : (o += c)
|
|
1278
1280
|
return r.push(o), r
|
|
1279
1281
|
}
|
|
1280
1282
|
function humanizeProgress(n) {
|
|
@@ -1392,12 +1394,12 @@ function secondsToHumanTime(n, t = DefaultTimeDeltaLabels) {
|
|
|
1392
1394
|
}
|
|
1393
1395
|
function countCycles(n, t, e) {
|
|
1394
1396
|
var r, o, i
|
|
1395
|
-
const
|
|
1396
|
-
|
|
1397
|
+
const c = ((r = e?.now) !== null && r !== void 0 ? r : Date.now()) - n,
|
|
1398
|
+
s = Math.floor(c / t),
|
|
1397
1399
|
f =
|
|
1398
1400
|
t / ((o = e?.precision) !== null && o !== void 0 ? o : 1) -
|
|
1399
|
-
Math.ceil((
|
|
1400
|
-
return { cycles:
|
|
1401
|
+
Math.ceil((c % t) / ((i = e?.precision) !== null && i !== void 0 ? i : 1))
|
|
1402
|
+
return { cycles: s, remaining: f }
|
|
1401
1403
|
}
|
|
1402
1404
|
const throttleTimers = {}
|
|
1403
1405
|
function throttle(n, t) {
|
|
@@ -1414,9 +1416,9 @@ function getProgress(n, t, e, r) {
|
|
|
1414
1416
|
const o = t / e,
|
|
1415
1417
|
i = r - n,
|
|
1416
1418
|
u = i / t,
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
return { deltaMs: i, progress: o, baseTimeMs: u, totalTimeMs:
|
|
1419
|
+
c = u * e,
|
|
1420
|
+
s = c - i
|
|
1421
|
+
return { deltaMs: i, progress: o, baseTimeMs: u, totalTimeMs: c, remainingTimeMs: s }
|
|
1420
1422
|
}
|
|
1421
1423
|
const dayNumberIndex = {
|
|
1422
1424
|
0: 'sunday',
|
|
@@ -1584,9 +1586,9 @@ function organiseWithLimits(n, t, e, r, o) {
|
|
|
1584
1586
|
for (const u of Object.keys(t)) i[u] = []
|
|
1585
1587
|
;(i[r] = []), o && (n = n.sort(o))
|
|
1586
1588
|
for (const u of n) {
|
|
1587
|
-
const
|
|
1588
|
-
|
|
1589
|
-
i[
|
|
1589
|
+
const c = u[e],
|
|
1590
|
+
s = t[c] ? c : r
|
|
1591
|
+
i[s].length >= t[s] ? i[r].push(u) : i[s].push(u)
|
|
1590
1592
|
}
|
|
1591
1593
|
return i
|
|
1592
1594
|
}
|
|
@@ -1655,11 +1657,11 @@ function formatNumber(n, t) {
|
|
|
1655
1657
|
const o = (e = t?.longForm) !== null && e !== void 0 ? e : !1,
|
|
1656
1658
|
i = t?.unit ? ` ${t.unit}` : '',
|
|
1657
1659
|
u = o ? longNumberUnits : shortNumberUnits,
|
|
1658
|
-
|
|
1660
|
+
c = (r = t?.precision) !== null && r !== void 0 ? r : 1
|
|
1659
1661
|
if (n < thresholds[0]) return `${n}${i}`
|
|
1660
|
-
for (let
|
|
1661
|
-
if (n < thresholds[
|
|
1662
|
-
return `${(n / thresholds[thresholds.length - 1]).toFixed(
|
|
1662
|
+
for (let s = 0; s < thresholds.length - 1; s++)
|
|
1663
|
+
if (n < thresholds[s + 1]) return `${(n / thresholds[s]).toFixed(c)}${o ? ' ' : ''}${u[s]}${i}`
|
|
1664
|
+
return `${(n / thresholds[thresholds.length - 1]).toFixed(c)}${o ? ' ' : ''}${u[thresholds.length - 1]}${i}`
|
|
1663
1665
|
}
|
|
1664
1666
|
function makeNumber(n) {
|
|
1665
1667
|
const t = parseFloat(n)
|
|
@@ -1738,20 +1740,20 @@ function flip(n) {
|
|
|
1738
1740
|
}
|
|
1739
1741
|
function getAllPermutations(n) {
|
|
1740
1742
|
const t = Object.keys(n),
|
|
1741
|
-
e = t.map(
|
|
1742
|
-
r = e.reduce((
|
|
1743
|
+
e = t.map(c => n[c].length),
|
|
1744
|
+
r = e.reduce((c, s) => (c *= s))
|
|
1743
1745
|
let o = 1
|
|
1744
1746
|
const i = [1]
|
|
1745
|
-
for (let
|
|
1747
|
+
for (let c = 0; c < e.length - 1; c++) (o *= e[c]), i.push(o)
|
|
1746
1748
|
const u = []
|
|
1747
|
-
for (let
|
|
1748
|
-
const
|
|
1749
|
+
for (let c = 0; c < r; c++) {
|
|
1750
|
+
const s = {}
|
|
1749
1751
|
for (let f = 0; f < t.length; f++) {
|
|
1750
1752
|
const l = n[t[f]],
|
|
1751
|
-
a = Math.floor(
|
|
1752
|
-
|
|
1753
|
+
a = Math.floor(c / i[f]) % l.length
|
|
1754
|
+
s[t[f]] = l[a]
|
|
1753
1755
|
}
|
|
1754
|
-
u.push(
|
|
1756
|
+
u.push(s)
|
|
1755
1757
|
}
|
|
1756
1758
|
return u
|
|
1757
1759
|
}
|
|
@@ -1764,14 +1766,14 @@ function getFlatNotation(n, t, e) {
|
|
|
1764
1766
|
function flattenInner(n, t, e, r, o) {
|
|
1765
1767
|
if (!isObject(t)) return t
|
|
1766
1768
|
for (const [i, u] of Object.entries(t)) {
|
|
1767
|
-
const
|
|
1769
|
+
const c = getFlatNotation(e, i, r)
|
|
1768
1770
|
Array.isArray(u)
|
|
1769
1771
|
? o
|
|
1770
|
-
? flattenInner(n, u,
|
|
1771
|
-
: (n[
|
|
1772
|
+
? flattenInner(n, u, c, !0, o)
|
|
1773
|
+
: (n[c] = u.map(s => flattenInner(Array.isArray(s) ? [] : {}, s, '', !1, o)))
|
|
1772
1774
|
: isObject(u)
|
|
1773
|
-
? flattenInner(n, u,
|
|
1774
|
-
: (n[
|
|
1775
|
+
? flattenInner(n, u, c, !1, o)
|
|
1776
|
+
: (n[c] = u)
|
|
1775
1777
|
}
|
|
1776
1778
|
return n
|
|
1777
1779
|
}
|
|
@@ -1837,9 +1839,9 @@ function makeUnique(n, t) {
|
|
|
1837
1839
|
function countUnique(n, t, e, r, o) {
|
|
1838
1840
|
const i = t ? n.map(t) : n,
|
|
1839
1841
|
u = {}
|
|
1840
|
-
for (const
|
|
1841
|
-
const
|
|
1842
|
-
return e ? Object.keys(
|
|
1842
|
+
for (const s of i) u[s] = (u[s] || 0) + 1
|
|
1843
|
+
const c = r ? sortObjectValues(u, o ? (s, f) => s[1] - f[1] : (s, f) => f[1] - s[1]) : u
|
|
1844
|
+
return e ? Object.keys(c) : c
|
|
1843
1845
|
}
|
|
1844
1846
|
function sortObjectValues(n, t) {
|
|
1845
1847
|
return Object.fromEntries(Object.entries(n).sort(t))
|
|
@@ -1956,6 +1958,24 @@ class Optional {
|
|
|
1956
1958
|
}
|
|
1957
1959
|
}
|
|
1958
1960
|
exports.Optional = Optional
|
|
1961
|
+
class Lazy {
|
|
1962
|
+
constructor(t) {
|
|
1963
|
+
;(this.supplier = t), (this.value = null)
|
|
1964
|
+
}
|
|
1965
|
+
get() {
|
|
1966
|
+
return this.value || (this.value = this.supplier()), this.value
|
|
1967
|
+
}
|
|
1968
|
+
}
|
|
1969
|
+
exports.Lazy = Lazy
|
|
1970
|
+
class AsyncLazy {
|
|
1971
|
+
constructor(t) {
|
|
1972
|
+
;(this.supplier = t), (this.value = null)
|
|
1973
|
+
}
|
|
1974
|
+
async get() {
|
|
1975
|
+
return this.value || (this.value = await this.supplier()), this.value
|
|
1976
|
+
}
|
|
1977
|
+
}
|
|
1978
|
+
exports.AsyncLazy = AsyncLazy
|
|
1959
1979
|
function findInstance(n, t) {
|
|
1960
1980
|
const e = n.find(r => r instanceof t)
|
|
1961
1981
|
return Optional.of(e)
|
|
@@ -1980,28 +2000,28 @@ class Node {
|
|
|
1980
2000
|
function createHierarchy(n, t, e, r, o = !1) {
|
|
1981
2001
|
const i = new Map(),
|
|
1982
2002
|
u = []
|
|
1983
|
-
n.forEach(
|
|
1984
|
-
const f = new Node(
|
|
1985
|
-
i.set(
|
|
2003
|
+
n.forEach(s => {
|
|
2004
|
+
const f = new Node(s)
|
|
2005
|
+
i.set(s[t], f)
|
|
1986
2006
|
}),
|
|
1987
|
-
n.forEach(
|
|
1988
|
-
const f = i.get(
|
|
2007
|
+
n.forEach(s => {
|
|
2008
|
+
const f = i.get(s[t])
|
|
1989
2009
|
if (!f) return
|
|
1990
|
-
const l =
|
|
2010
|
+
const l = s[e]
|
|
1991
2011
|
if (l) {
|
|
1992
2012
|
const a = i.get(l)
|
|
1993
2013
|
a && a.children.push(f)
|
|
1994
2014
|
} else u.push(f)
|
|
1995
2015
|
})
|
|
1996
|
-
const
|
|
1997
|
-
|
|
2016
|
+
const c = s => {
|
|
2017
|
+
s.children.sort((f, l) => {
|
|
1998
2018
|
const a = f.value[r],
|
|
1999
2019
|
h = l.value[r]
|
|
2000
2020
|
return o ? h - a : a - h
|
|
2001
2021
|
}),
|
|
2002
|
-
|
|
2022
|
+
s.children.forEach(c)
|
|
2003
2023
|
}
|
|
2004
|
-
return u.forEach(
|
|
2024
|
+
return u.forEach(c), u
|
|
2005
2025
|
}
|
|
2006
2026
|
function log2Reduce(n, t) {
|
|
2007
2027
|
if (Math.log2(n.length) % 1 !== 0) throw new Error('Array length must be a power of 2')
|
|
@@ -2128,7 +2148,7 @@ function tickPlaybook(n) {
|
|
|
2128
2148
|
)
|
|
2129
2149
|
}
|
|
2130
2150
|
function getArgument(n, t, e, r) {
|
|
2131
|
-
const o = n.findIndex(
|
|
2151
|
+
const o = n.findIndex(c => c === `--${t}` || c.startsWith(`--${t}=`)),
|
|
2132
2152
|
i = n[o]
|
|
2133
2153
|
if (!i) return (e || {})[r || t || ''] || null
|
|
2134
2154
|
if (i.includes('=')) return i.split('=')[1]
|
|
@@ -2145,14 +2165,14 @@ function getNumberArgument(n, t, e, r) {
|
|
|
2145
2165
|
}
|
|
2146
2166
|
}
|
|
2147
2167
|
function getBooleanArgument(n, t, e, r) {
|
|
2148
|
-
const o = n.some(
|
|
2168
|
+
const o = n.some(s => s.endsWith('-' + t)),
|
|
2149
2169
|
i = getArgument(n, t, e, r)
|
|
2150
2170
|
if (!i && o) return !0
|
|
2151
2171
|
if (!i && !o) return null
|
|
2152
2172
|
const u = ['true', '1', 'yes', 'y', 'on'],
|
|
2153
|
-
|
|
2173
|
+
c = ['false', '0', 'no', 'n', 'off']
|
|
2154
2174
|
if (u.includes(i.toLowerCase())) return !0
|
|
2155
|
-
if (
|
|
2175
|
+
if (c.includes(i.toLowerCase())) return !1
|
|
2156
2176
|
throw Error(`Invalid boolean argument ${t}: ${i}`)
|
|
2157
2177
|
}
|
|
2158
2178
|
function requireStringArgument(n, t, e, r) {
|
|
@@ -2235,16 +2255,16 @@ function isBottommost(n, t, e) {
|
|
|
2235
2255
|
return !n[t][e + 1]
|
|
2236
2256
|
}
|
|
2237
2257
|
function getCorners(n, t, e) {
|
|
2238
|
-
var r, o, i, u,
|
|
2258
|
+
var r, o, i, u, c, s, f, l
|
|
2239
2259
|
const a = []
|
|
2240
2260
|
return n[t][e]
|
|
2241
2261
|
? isHorizontalLine(n, t, e) || isVerticalLine(n, t, e)
|
|
2242
2262
|
? []
|
|
2243
|
-
: (!(!((
|
|
2263
|
+
: (!(!((c = n[t - 1]) === null || c === void 0) && c[e - 1]) &&
|
|
2244
2264
|
isLeftmost(n, t, e) &&
|
|
2245
2265
|
isTopmost(n, t, e) &&
|
|
2246
2266
|
a.push({ x: t, y: e }),
|
|
2247
|
-
!(!((
|
|
2267
|
+
!(!((s = n[t + 1]) === null || s === void 0) && s[e - 1]) &&
|
|
2248
2268
|
isRightmost(n, t, e) &&
|
|
2249
2269
|
isTopmost(n, t, e) &&
|
|
2250
2270
|
a.push({ x: t + 1, y: e }),
|
|
@@ -2272,42 +2292,42 @@ function findCorners(n, t, e, r) {
|
|
|
2272
2292
|
]
|
|
2273
2293
|
for (let i = 0; i < n.length; i++)
|
|
2274
2294
|
for (let u = 0; u < n[0].length; u++) {
|
|
2275
|
-
const
|
|
2276
|
-
for (const
|
|
2295
|
+
const c = getCorners(n, i, u)
|
|
2296
|
+
for (const s of c) o.some(f => f.x === s.x && f.y === s.y) || o.push(s)
|
|
2277
2297
|
}
|
|
2278
2298
|
return o.map(i => ({ x: i.x * t, y: i.y * t }))
|
|
2279
2299
|
}
|
|
2280
2300
|
function findLines(n, t) {
|
|
2281
|
-
const e = filterCoordinates(n, (
|
|
2282
|
-
Object.assign(Object.assign({},
|
|
2301
|
+
const e = filterCoordinates(n, (s, f) => n[s][f] === 0 && n[s][f + 1] !== 0, 'row-first').map(s =>
|
|
2302
|
+
Object.assign(Object.assign({}, s), { dx: 1, dy: 0 })
|
|
2283
2303
|
),
|
|
2284
|
-
r = filterCoordinates(n, (
|
|
2285
|
-
Object.assign(Object.assign({},
|
|
2304
|
+
r = filterCoordinates(n, (s, f) => n[s][f] === 0 && n[s][f - 1] !== 0, 'row-first').map(s =>
|
|
2305
|
+
Object.assign(Object.assign({}, s), { dx: 1, dy: 0 })
|
|
2286
2306
|
),
|
|
2287
2307
|
o = filterCoordinates(
|
|
2288
2308
|
n,
|
|
2289
|
-
(
|
|
2309
|
+
(s, f) => {
|
|
2290
2310
|
var l
|
|
2291
|
-
return n[
|
|
2311
|
+
return n[s][f] === 0 && ((l = n[s - 1]) === null || l === void 0 ? void 0 : l[f]) !== 0
|
|
2292
2312
|
},
|
|
2293
2313
|
'column-first'
|
|
2294
|
-
).map(
|
|
2314
|
+
).map(s => Object.assign(Object.assign({}, s), { dx: 0, dy: 1 })),
|
|
2295
2315
|
i = filterCoordinates(
|
|
2296
2316
|
n,
|
|
2297
|
-
(
|
|
2317
|
+
(s, f) => {
|
|
2298
2318
|
var l
|
|
2299
|
-
return n[
|
|
2319
|
+
return n[s][f] === 0 && ((l = n[s + 1]) === null || l === void 0 ? void 0 : l[f]) !== 0
|
|
2300
2320
|
},
|
|
2301
2321
|
'column-first'
|
|
2302
|
-
).map(
|
|
2303
|
-
e.forEach(
|
|
2304
|
-
const u = group([...o, ...i], (
|
|
2305
|
-
|
|
2306
|
-
return [...u, ...
|
|
2307
|
-
.map(
|
|
2308
|
-
.map(
|
|
2309
|
-
start: multiplyPoint(
|
|
2310
|
-
end: multiplyPoint(addPoint(
|
|
2322
|
+
).map(s => Object.assign(Object.assign({}, s), { dx: 0, dy: 1 }))
|
|
2323
|
+
e.forEach(s => s.y++), i.forEach(s => s.x++)
|
|
2324
|
+
const u = group([...o, ...i], (s, f) => s.x === f.x && s.y - 1 === f.y),
|
|
2325
|
+
c = group([...r, ...e], (s, f) => s.y === f.y && s.x - 1 === f.x)
|
|
2326
|
+
return [...u, ...c]
|
|
2327
|
+
.map(s => ({ start: s[0], end: last(s) }))
|
|
2328
|
+
.map(s => ({
|
|
2329
|
+
start: multiplyPoint(s.start, t),
|
|
2330
|
+
end: multiplyPoint(addPoint(s.end, { x: s.start.dx, y: s.start.dy }), t)
|
|
2311
2331
|
}))
|
|
2312
2332
|
}
|
|
2313
2333
|
function getAngleInRadians(n, t) {
|
|
@@ -2321,11 +2341,11 @@ function getLineIntersectionPoint(n, t, e, r) {
|
|
|
2321
2341
|
if (o === 0) return null
|
|
2322
2342
|
let i = n.y - e.y,
|
|
2323
2343
|
u = n.x - e.x
|
|
2324
|
-
const
|
|
2325
|
-
|
|
2344
|
+
const c = (r.x - e.x) * i - (r.y - e.y) * u,
|
|
2345
|
+
s = (t.x - n.x) * i - (t.y - n.y) * u
|
|
2326
2346
|
return (
|
|
2327
|
-
(i =
|
|
2328
|
-
(u =
|
|
2347
|
+
(i = c / o),
|
|
2348
|
+
(u = s / o),
|
|
2329
2349
|
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
|
|
2330
2350
|
)
|
|
2331
2351
|
}
|
|
@@ -2338,9 +2358,9 @@ function raycast(n, t, e) {
|
|
|
2338
2358
|
}
|
|
2339
2359
|
return r.length
|
|
2340
2360
|
? r.reduce((i, u) => {
|
|
2341
|
-
const
|
|
2342
|
-
|
|
2343
|
-
return
|
|
2361
|
+
const c = getDistanceBetweenPoints(n, u),
|
|
2362
|
+
s = getDistanceBetweenPoints(n, i)
|
|
2363
|
+
return c < s ? u : i
|
|
2344
2364
|
})
|
|
2345
2365
|
: null
|
|
2346
2366
|
}
|
|
@@ -2348,9 +2368,9 @@ function raycastCircle(n, t, e) {
|
|
|
2348
2368
|
const o = getSortedRayAngles(n, e),
|
|
2349
2369
|
i = []
|
|
2350
2370
|
for (const u of o) {
|
|
2351
|
-
const
|
|
2352
|
-
|
|
2353
|
-
|
|
2371
|
+
const c = raycast(n, t, u - 0.001),
|
|
2372
|
+
s = raycast(n, t, u + 0.001)
|
|
2373
|
+
c && i.push(c), s && i.push(s)
|
|
2354
2374
|
}
|
|
2355
2375
|
return i
|
|
2356
2376
|
}
|
package/module.mjs
CHANGED