@tempots/std 0.9.7 → 0.10.4
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/README.md +1 -3
- package/array.cjs +1 -0
- package/{arrays.d.ts → array.d.ts} +7 -7
- package/array.js +223 -0
- package/bigint.cjs +1 -0
- package/bigint.js +96 -110
- package/boolean.cjs +1 -0
- package/boolean.js +44 -0
- package/domain.cjs +1 -0
- package/domain.d.ts +22 -0
- package/domain.js +1 -0
- package/equal.cjs +1 -0
- package/equal.js +68 -0
- package/function.cjs +1 -0
- package/function.js +29 -0
- package/index.cjs +1 -0
- package/index.d.ts +0 -0
- package/index.js +1 -0
- package/maybe.cjs +1 -0
- package/maybe.d.ts +3 -3
- package/maybe.js +8 -24
- package/number.cjs +1 -0
- package/{numbers.d.ts → number.d.ts} +2 -5
- package/number.js +103 -0
- package/object.cjs +1 -0
- package/object.d.ts +8 -0
- package/object.js +30 -0
- package/package.json +95 -25
- package/regexp.cjs +1 -0
- package/regexp.js +14 -0
- package/string.cjs +3 -0
- package/{strings.d.ts → string.d.ts} +0 -2
- package/string.js +396 -0
- package/arrays.js +0 -249
- package/async-result.d.ts +0 -37
- package/async-result.js +0 -75
- package/booleans.js +0 -68
- package/colors/cmyk.d.ts +0 -21
- package/colors/cmyk.js +0 -54
- package/colors/convert.d.ts +0 -283
- package/colors/convert.js +0 -742
- package/colors/hsl.d.ts +0 -24
- package/colors/hsl.js +0 -56
- package/colors/hsla.d.ts +0 -18
- package/colors/hsla.js +0 -35
- package/colors/hsluv.d.ts +0 -24
- package/colors/hsluv.js +0 -56
- package/colors/hsv.d.ts +0 -24
- package/colors/hsv.js +0 -54
- package/colors/lab.d.ts +0 -24
- package/colors/lab.js +0 -54
- package/colors/lch.d.ts +0 -19
- package/colors/lch.js +0 -44
- package/colors/luv.d.ts +0 -19
- package/colors/luv.js +0 -45
- package/colors/rgb.d.ts +0 -13
- package/colors/rgb.js +0 -47
- package/colors/rgba.d.ts +0 -12
- package/colors/rgba.js +0 -44
- package/colors/srgb.d.ts +0 -24
- package/colors/srgb.js +0 -51
- package/colors/xyz.d.ts +0 -19
- package/colors/xyz.js +0 -41
- package/edit.d.ts +0 -20
- package/edit.js +0 -29
- package/equals.js +0 -122
- package/functions.js +0 -38
- package/json.d.ts +0 -14
- package/json.js +0 -33
- package/match.d.ts +0 -16
- package/match.js +0 -45
- package/memoize.d.ts +0 -1
- package/memoize.js +0 -9
- package/newtype.d.ts +0 -28
- package/newtype.js +0 -29
- package/numbers.js +0 -183
- package/objects.d.ts +0 -9
- package/objects.js +0 -33
- package/ord.d.ts +0 -19
- package/ord.js +0 -73
- package/reg-exps.js +0 -43
- package/result.d.ts +0 -31
- package/result.js +0 -95
- package/strings.js +0 -685
- package/types/assert.d.ts +0 -12
- package/types/assert.js +0 -13
- package/types/differentiate.d.ts +0 -13
- package/types/differentiate.js +0 -14
- package/types/functions.d.ts +0 -22
- package/types/functions.js +0 -13
- package/types/generic.d.ts +0 -9
- package/types/generic.js +0 -13
- package/types/objects.d.ts +0 -50
- package/types/objects.js +0 -13
- package/types/tuples.d.ts +0 -44
- package/types/tuples.js +0 -24
- package/types/utility.d.ts +0 -2
- package/types/utility.js +0 -1
- package/uuid.d.ts +0 -13
- package/uuid.js +0 -56
- package/validation.d.ts +0 -23
- package/validation.js +0 -44
- /package/{booleans.d.ts → boolean.d.ts} +0 -0
- /package/{equals.d.ts → equal.d.ts} +0 -0
- /package/{functions.d.ts → function.d.ts} +0 -0
- /package/{reg-exps.d.ts → regexp.d.ts} +0 -0
package/string.js
ADDED
|
@@ -0,0 +1,396 @@
|
|
|
1
|
+
import { any as c, all as b, range as A, fill as O } from "./array.js";
|
|
2
|
+
import { map as p } from "./regexp.js";
|
|
3
|
+
function a(n, t, r) {
|
|
4
|
+
return n.split(t).join(r);
|
|
5
|
+
}
|
|
6
|
+
function J(n, t) {
|
|
7
|
+
const r = n.indexOf(t);
|
|
8
|
+
return r < 0 ? "" : n.substring(r + t.length);
|
|
9
|
+
}
|
|
10
|
+
function Q(n, t) {
|
|
11
|
+
const r = n.lastIndexOf(t);
|
|
12
|
+
return r < 0 ? "" : n.substring(r + t.length);
|
|
13
|
+
}
|
|
14
|
+
function V(n, t) {
|
|
15
|
+
const r = n.indexOf(t);
|
|
16
|
+
return r < 0 ? "" : n.substring(0, r);
|
|
17
|
+
}
|
|
18
|
+
function X(n, t) {
|
|
19
|
+
const r = n.lastIndexOf(t);
|
|
20
|
+
return r < 0 ? "" : n.substring(0, r);
|
|
21
|
+
}
|
|
22
|
+
function h(n) {
|
|
23
|
+
return n.substring(0, 1).toUpperCase() + n.substring(1);
|
|
24
|
+
}
|
|
25
|
+
const d = (n) => n.toUpperCase();
|
|
26
|
+
function Y(n, t = !1) {
|
|
27
|
+
return t ? p(h(n), R, d) : p(h(n), P, d);
|
|
28
|
+
}
|
|
29
|
+
function v(n) {
|
|
30
|
+
return n.replace(q, `
|
|
31
|
+
`);
|
|
32
|
+
}
|
|
33
|
+
function nn(n, t) {
|
|
34
|
+
return n == null && t == null ? 0 : n == null ? -1 : t == null ? 1 : y(n.toLowerCase(), t.toLowerCase());
|
|
35
|
+
}
|
|
36
|
+
function L(n, t) {
|
|
37
|
+
return n.substring(0, n.length - t.length) === t;
|
|
38
|
+
}
|
|
39
|
+
function tn(n, t) {
|
|
40
|
+
return n.substring(0, n.length - t.length).toLowerCase() === t.toLowerCase();
|
|
41
|
+
}
|
|
42
|
+
function W(n, t) {
|
|
43
|
+
return n.substring(0, t.length) === t;
|
|
44
|
+
}
|
|
45
|
+
function rn(n, t) {
|
|
46
|
+
return n.substring(0, t.length).toLowerCase() === t.toLowerCase();
|
|
47
|
+
}
|
|
48
|
+
function en(n, t) {
|
|
49
|
+
return E(
|
|
50
|
+
n.toLowerCase(),
|
|
51
|
+
t.map((r) => r.toLowerCase())
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
function on(n, t) {
|
|
55
|
+
return _(
|
|
56
|
+
n.toLowerCase(),
|
|
57
|
+
t.map((r) => r.toLowerCase())
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
function sn(n) {
|
|
61
|
+
return n.trim().replace(m, " ");
|
|
62
|
+
}
|
|
63
|
+
function y(n, t) {
|
|
64
|
+
return n < t ? -1 : n > t ? 1 : 0;
|
|
65
|
+
}
|
|
66
|
+
function w(n, t) {
|
|
67
|
+
return n.toLowerCase().includes(t.toLowerCase());
|
|
68
|
+
}
|
|
69
|
+
function l(n, t) {
|
|
70
|
+
return n.includes(t);
|
|
71
|
+
}
|
|
72
|
+
function un(n, t) {
|
|
73
|
+
return n.split(t).length - 1;
|
|
74
|
+
}
|
|
75
|
+
function fn(n, t) {
|
|
76
|
+
return c(t, (r) => w(n, r));
|
|
77
|
+
}
|
|
78
|
+
function cn(n, t) {
|
|
79
|
+
return c(t, (r) => l(n, r));
|
|
80
|
+
}
|
|
81
|
+
function ln(n, t) {
|
|
82
|
+
return b(t, (r) => w(n, r));
|
|
83
|
+
}
|
|
84
|
+
function an(n, t) {
|
|
85
|
+
return b(t, (r) => l(n, r));
|
|
86
|
+
}
|
|
87
|
+
function gn(n) {
|
|
88
|
+
return n.replace("_", "-");
|
|
89
|
+
}
|
|
90
|
+
function pn(n, t) {
|
|
91
|
+
const r = Math.min(n.length, t.length);
|
|
92
|
+
for (let e = 0; e < r; e++)
|
|
93
|
+
if (n.substring(e, e + 1) !== t.substring(e, e + 1)) return e;
|
|
94
|
+
return r;
|
|
95
|
+
}
|
|
96
|
+
function z(n, t = 20, r = "…") {
|
|
97
|
+
const e = n.length, i = r.length;
|
|
98
|
+
return e > t ? t < i ? r.substr(i - t, t) : n.substr(0, t - i) + r : n;
|
|
99
|
+
}
|
|
100
|
+
function hn(n, t = 20, r = "…") {
|
|
101
|
+
const e = n.length, i = r.length;
|
|
102
|
+
if (e > t) {
|
|
103
|
+
if (t <= i)
|
|
104
|
+
return z(n, t, r);
|
|
105
|
+
const u = Math.ceil((t - i) / 2), f = Math.floor((t - i) / 2);
|
|
106
|
+
return n.substr(0, u) + r + n.substr(e - f, f);
|
|
107
|
+
} else return n;
|
|
108
|
+
}
|
|
109
|
+
function E(n, t) {
|
|
110
|
+
return c(t, (r) => L(n, r));
|
|
111
|
+
}
|
|
112
|
+
function dn(n, t) {
|
|
113
|
+
return g(n).filter(t).join("");
|
|
114
|
+
}
|
|
115
|
+
function Cn(n, t) {
|
|
116
|
+
return $(n).filter(t).map((e) => String.fromCharCode(e)).join("");
|
|
117
|
+
}
|
|
118
|
+
function bn(n, t) {
|
|
119
|
+
const r = n.indexOf(t);
|
|
120
|
+
return r < 0 ? "" : n.substring(r);
|
|
121
|
+
}
|
|
122
|
+
function An(n, t = 2166136261) {
|
|
123
|
+
let r = t;
|
|
124
|
+
for (let e = 0, i = n.length; e < i; e++)
|
|
125
|
+
r ^= n.charCodeAt(e), r += (r << 1) + (r << 4) + (r << 7) + (r << 8) + (r << 24);
|
|
126
|
+
return r >>> 0;
|
|
127
|
+
}
|
|
128
|
+
function Ln(n) {
|
|
129
|
+
return n != null && n.length > 0;
|
|
130
|
+
}
|
|
131
|
+
function wn(n) {
|
|
132
|
+
return a(T(n), "_", " ");
|
|
133
|
+
}
|
|
134
|
+
function In(n) {
|
|
135
|
+
return n.length > 0 && !x.test(n);
|
|
136
|
+
}
|
|
137
|
+
function mn(n) {
|
|
138
|
+
return D.test(n);
|
|
139
|
+
}
|
|
140
|
+
function Sn(n) {
|
|
141
|
+
return !Z.test(n);
|
|
142
|
+
}
|
|
143
|
+
function On(n) {
|
|
144
|
+
return n.toLowerCase() === n;
|
|
145
|
+
}
|
|
146
|
+
function Wn(n) {
|
|
147
|
+
return n.toUpperCase() === n;
|
|
148
|
+
}
|
|
149
|
+
function yn(n, t) {
|
|
150
|
+
return n != null && n !== "" ? n : t;
|
|
151
|
+
}
|
|
152
|
+
function zn(n) {
|
|
153
|
+
return G.test(n);
|
|
154
|
+
}
|
|
155
|
+
function En(n) {
|
|
156
|
+
return n == null || n === "";
|
|
157
|
+
}
|
|
158
|
+
function Bn(n) {
|
|
159
|
+
return n.substring(0, 1).toLowerCase() + n.substring(1);
|
|
160
|
+
}
|
|
161
|
+
function B(n, t = 1) {
|
|
162
|
+
return n.substring(
|
|
163
|
+
Math.floor((n.length - t + 1) * Math.random()),
|
|
164
|
+
t
|
|
165
|
+
);
|
|
166
|
+
}
|
|
167
|
+
function j(n, t) {
|
|
168
|
+
return A(t, () => B(n)).join("");
|
|
169
|
+
}
|
|
170
|
+
function jn(n) {
|
|
171
|
+
return j(k, n);
|
|
172
|
+
}
|
|
173
|
+
function _n(n, t) {
|
|
174
|
+
return g(t).map(n);
|
|
175
|
+
}
|
|
176
|
+
function $n(n, t) {
|
|
177
|
+
return a(n, t, "");
|
|
178
|
+
}
|
|
179
|
+
function Mn(n, t) {
|
|
180
|
+
return L(n, t) ? n.substring(0, n.length - t.length) : n;
|
|
181
|
+
}
|
|
182
|
+
function Nn(n, t, r) {
|
|
183
|
+
return n.substring(0, t) + n.substring(t + r);
|
|
184
|
+
}
|
|
185
|
+
function Tn(n, t) {
|
|
186
|
+
return W(n, t) ? n.substring(t.length) : n;
|
|
187
|
+
}
|
|
188
|
+
function Un(n, t) {
|
|
189
|
+
const r = n.indexOf(t);
|
|
190
|
+
return r < 0 ? n : n.substring(0, r) + n.substring(r + t.length);
|
|
191
|
+
}
|
|
192
|
+
function I(n, t) {
|
|
193
|
+
return O(t, n).join("");
|
|
194
|
+
}
|
|
195
|
+
function kn(n) {
|
|
196
|
+
const t = g(n);
|
|
197
|
+
return t.reverse(), t.join("");
|
|
198
|
+
}
|
|
199
|
+
function Pn(n) {
|
|
200
|
+
return n.includes('"') ? n.includes("'") ? '"' + a(n, '"', '\\"') + '"' : "'" + n + "'" : '"' + n + '"';
|
|
201
|
+
}
|
|
202
|
+
function Zn(n, t) {
|
|
203
|
+
const r = n.indexOf(t);
|
|
204
|
+
return r < 0 ? [n] : [n.substring(0, r), n.substring(r + t.length)];
|
|
205
|
+
}
|
|
206
|
+
function _(n, t) {
|
|
207
|
+
return c(t, (r) => n.startsWith(r));
|
|
208
|
+
}
|
|
209
|
+
function xn(n) {
|
|
210
|
+
return n.replace(H, "");
|
|
211
|
+
}
|
|
212
|
+
function Rn(n, t, r = t) {
|
|
213
|
+
return `${t}${n}${r}`;
|
|
214
|
+
}
|
|
215
|
+
function g(n) {
|
|
216
|
+
return n.split("");
|
|
217
|
+
}
|
|
218
|
+
function $(n) {
|
|
219
|
+
return A(n.length, (t) => n.charCodeAt(t));
|
|
220
|
+
}
|
|
221
|
+
function Dn(n, t) {
|
|
222
|
+
const r = [];
|
|
223
|
+
for (; n.length > 0; )
|
|
224
|
+
r.push(n.substring(0, t)), n = n.substr(t, n.length - t);
|
|
225
|
+
return r;
|
|
226
|
+
}
|
|
227
|
+
function Gn(n) {
|
|
228
|
+
return n.split(S);
|
|
229
|
+
}
|
|
230
|
+
function Hn(n, t) {
|
|
231
|
+
return N(M(n, t), t);
|
|
232
|
+
}
|
|
233
|
+
function M(n, t) {
|
|
234
|
+
let r = 0;
|
|
235
|
+
for (let e = 0; e < n.length && l(t, n.charAt(e)); e++)
|
|
236
|
+
r++;
|
|
237
|
+
return n.substring(r);
|
|
238
|
+
}
|
|
239
|
+
function N(n, t) {
|
|
240
|
+
const r = n.length;
|
|
241
|
+
let e = r, i;
|
|
242
|
+
for (let u = 0; u < r && (i = r - u - 1, l(t, n.charAt(i))); u++)
|
|
243
|
+
e = i;
|
|
244
|
+
return n.substring(0, e);
|
|
245
|
+
}
|
|
246
|
+
function T(n) {
|
|
247
|
+
return n = n.replace(/::/g, "/"), n = n.replace(/([A-Z]+)([A-Z][a-z])/g, "$1_$2"), n = n.replace(/([a-z\d])([A-Z])/g, "$1_$2"), n = n.replace(/-/g, "_"), n.toLowerCase();
|
|
248
|
+
}
|
|
249
|
+
function qn(n) {
|
|
250
|
+
return n.substring(0, 1).toUpperCase() + n.substring(1);
|
|
251
|
+
}
|
|
252
|
+
function Fn(n, t) {
|
|
253
|
+
const r = n.indexOf(t);
|
|
254
|
+
return r < 0 ? n : n.substring(0, r);
|
|
255
|
+
}
|
|
256
|
+
function Kn(n, t = 78, r = "", e = `
|
|
257
|
+
`) {
|
|
258
|
+
return n.split(S).map(
|
|
259
|
+
(i) => U(i.replace(m, " ").trim(), t, r, e)
|
|
260
|
+
).join(e);
|
|
261
|
+
}
|
|
262
|
+
function C(n, t) {
|
|
263
|
+
if (t < 0 || t >= n.length) return !1;
|
|
264
|
+
const r = n.charCodeAt(t);
|
|
265
|
+
return r === 9 || r === 10 || r === 11 || r === 12 || r === 13 || r === 32;
|
|
266
|
+
}
|
|
267
|
+
function Jn(n) {
|
|
268
|
+
if (typeof Buffer < "u")
|
|
269
|
+
return Buffer.from(n).toString("base64");
|
|
270
|
+
if (typeof btoa < "u")
|
|
271
|
+
return btoa(n);
|
|
272
|
+
throw new Error("no implementation provided for base64 encoding");
|
|
273
|
+
}
|
|
274
|
+
function Qn(n) {
|
|
275
|
+
if (typeof Buffer < "u")
|
|
276
|
+
return Buffer.from(n, "base64").toString("utf8");
|
|
277
|
+
if (typeof atob < "u")
|
|
278
|
+
return atob(n);
|
|
279
|
+
throw new Error("no implementation provided for base64 decoding");
|
|
280
|
+
}
|
|
281
|
+
function U(n, t, r, e) {
|
|
282
|
+
const i = [], u = n.length, f = r.length;
|
|
283
|
+
let s = 0;
|
|
284
|
+
for (t -= f; ; ) {
|
|
285
|
+
if (s + t >= u - f) {
|
|
286
|
+
i.push(n.substring(s));
|
|
287
|
+
break;
|
|
288
|
+
}
|
|
289
|
+
let o = 0;
|
|
290
|
+
for (; !C(n, s + t - o) && o < t; ) o++;
|
|
291
|
+
if (o === t) {
|
|
292
|
+
for (o = 0; !C(n, s + t + o) && s + t + o < u; ) o++;
|
|
293
|
+
i.push(n.substring(s, s + t + o)), s += t + o + 1;
|
|
294
|
+
} else
|
|
295
|
+
i.push(n.substring(s, s + t - o)), s += t - o + 1;
|
|
296
|
+
}
|
|
297
|
+
return r + i.join(e + r);
|
|
298
|
+
}
|
|
299
|
+
function Vn(n, t, r) {
|
|
300
|
+
const e = r - n.length;
|
|
301
|
+
return e > 0 ? I(t, e) + n : n;
|
|
302
|
+
}
|
|
303
|
+
function Xn(n, t, r) {
|
|
304
|
+
const e = r - n.length;
|
|
305
|
+
return e > 0 ? n + I(t, e) : n;
|
|
306
|
+
}
|
|
307
|
+
function Yn(n, t) {
|
|
308
|
+
const r = n.lastIndexOf(t);
|
|
309
|
+
return r >= 0 ? [n.substring(0, r), n.substring(r + t.length)] : [n];
|
|
310
|
+
}
|
|
311
|
+
function vn(n, t) {
|
|
312
|
+
const r = n.indexOf(t);
|
|
313
|
+
return r >= 0 ? [n.substring(0, r), n.substring(r + t.length)] : [n];
|
|
314
|
+
}
|
|
315
|
+
const k = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", P = /[^a-zA-Z]([a-z])/g, Z = /[^\t\n\r ]/, x = /[^a-zA-Z]/, R = /[ \t\r\n][a-z]/g, D = /^[a-z0-9]+$/i, G = /^[0-9]+$/, H = /<\/?[a-z]+[^>]*>/gi, m = /[ \t\r\n]+/g, S = /\r\n|\n\r|\n|\r/g, q = /\r\n|\n\r|\r/g;
|
|
316
|
+
export {
|
|
317
|
+
J as after,
|
|
318
|
+
Q as afterLast,
|
|
319
|
+
V as before,
|
|
320
|
+
X as beforeLast,
|
|
321
|
+
v as canonicalizeNewlines,
|
|
322
|
+
h as capitalize,
|
|
323
|
+
Y as capitalizeWords,
|
|
324
|
+
sn as collapse,
|
|
325
|
+
y as compare,
|
|
326
|
+
nn as compareCaseInsensitive,
|
|
327
|
+
l as contains,
|
|
328
|
+
an as containsAll,
|
|
329
|
+
ln as containsAllCaseInsensitive,
|
|
330
|
+
cn as containsAny,
|
|
331
|
+
fn as containsAnyCaseInsensitive,
|
|
332
|
+
w as containsCaseInsensitive,
|
|
333
|
+
un as count,
|
|
334
|
+
gn as dasherize,
|
|
335
|
+
Qn as decodeBase64,
|
|
336
|
+
pn as diffIndex,
|
|
337
|
+
z as ellipsis,
|
|
338
|
+
hn as ellipsisMiddle,
|
|
339
|
+
Jn as encodeBase64,
|
|
340
|
+
L as endsWith,
|
|
341
|
+
E as endsWithAny,
|
|
342
|
+
en as endsWithAnyCaseInsensitive,
|
|
343
|
+
tn as endsWithCaseInsensitive,
|
|
344
|
+
dn as filter,
|
|
345
|
+
Cn as filterCharcode,
|
|
346
|
+
bn as from,
|
|
347
|
+
Ln as hasContent,
|
|
348
|
+
An as hashCode,
|
|
349
|
+
wn as humanize,
|
|
350
|
+
yn as ifEmpty,
|
|
351
|
+
In as isAlpha,
|
|
352
|
+
mn as isAlphaNum,
|
|
353
|
+
Sn as isBreakingWhitespace,
|
|
354
|
+
zn as isDigitsOnly,
|
|
355
|
+
En as isEmpty,
|
|
356
|
+
On as isLowerCase,
|
|
357
|
+
C as isSpaceAt,
|
|
358
|
+
Wn as isUpperCase,
|
|
359
|
+
Bn as lowerCaseFirst,
|
|
360
|
+
Vn as lpad,
|
|
361
|
+
_n as map,
|
|
362
|
+
Pn as quote,
|
|
363
|
+
B as random,
|
|
364
|
+
j as randomSequence,
|
|
365
|
+
jn as randomSequence64,
|
|
366
|
+
$n as remove,
|
|
367
|
+
Mn as removeAfter,
|
|
368
|
+
Nn as removeAt,
|
|
369
|
+
Tn as removeBefore,
|
|
370
|
+
Un as removeOne,
|
|
371
|
+
I as repeat,
|
|
372
|
+
a as replace,
|
|
373
|
+
kn as reverse,
|
|
374
|
+
Xn as rpad,
|
|
375
|
+
vn as splitOnFirst,
|
|
376
|
+
Yn as splitOnLast,
|
|
377
|
+
Zn as splitOnce,
|
|
378
|
+
W as startsWith,
|
|
379
|
+
_ as startsWithAny,
|
|
380
|
+
on as startsWithAnyCaseInsensitive,
|
|
381
|
+
rn as startsWithCaseInsensitive,
|
|
382
|
+
xn as stripTags,
|
|
383
|
+
Rn as surround,
|
|
384
|
+
g as toArray,
|
|
385
|
+
$ as toCharcodes,
|
|
386
|
+
Dn as toChunks,
|
|
387
|
+
Gn as toLines,
|
|
388
|
+
Hn as trimChars,
|
|
389
|
+
M as trimCharsLeft,
|
|
390
|
+
N as trimCharsRight,
|
|
391
|
+
T as underscore,
|
|
392
|
+
Fn as upTo,
|
|
393
|
+
qn as upperCaseFirst,
|
|
394
|
+
Kn as wrapColumns,
|
|
395
|
+
U as wrapLine
|
|
396
|
+
};
|
package/arrays.js
DELETED
|
@@ -1,249 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Copyright 2019 Google LLC
|
|
3
|
-
Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
you may not use this file except in compliance with the License.
|
|
5
|
-
You may obtain a copy of the License at
|
|
6
|
-
https://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
-
Unless required by applicable law or agreed to in writing, software
|
|
8
|
-
distributed under the License is distributed on an "AS IS" BASIS,
|
|
9
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
10
|
-
See the License for the specific language governing permissions and
|
|
11
|
-
limitations under the License.
|
|
12
|
-
*/
|
|
13
|
-
/**
|
|
14
|
-
* Utility functions to manipulate `Array` values.
|
|
15
|
-
*/
|
|
16
|
-
import { Maybe } from './maybe';
|
|
17
|
-
import { keys } from './objects';
|
|
18
|
-
export function map(arr, f) {
|
|
19
|
-
return Array.from({ length: arr.length }, (_, i) => f(arr[i], i));
|
|
20
|
-
}
|
|
21
|
-
export function mapNotNull(arr, f) {
|
|
22
|
-
const buff = [];
|
|
23
|
-
for (let i = 0; i < arr.length; i++) {
|
|
24
|
-
const v = f(arr[i], i);
|
|
25
|
-
if (v != null) {
|
|
26
|
-
buff.push(v);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
return buff;
|
|
30
|
-
}
|
|
31
|
-
export function flatMap(arr, f) {
|
|
32
|
-
const buff = [];
|
|
33
|
-
for (const el of arr) {
|
|
34
|
-
buff.push(...f(el));
|
|
35
|
-
}
|
|
36
|
-
return buff;
|
|
37
|
-
}
|
|
38
|
-
export function head(arr) {
|
|
39
|
-
return arr.length > 0 ? arr[0] : Maybe.nothing;
|
|
40
|
-
}
|
|
41
|
-
export function tail(arr) {
|
|
42
|
-
return arr.slice(1);
|
|
43
|
-
}
|
|
44
|
-
export function equals(a, b, equality) {
|
|
45
|
-
if (a.length !== b.length)
|
|
46
|
-
return false;
|
|
47
|
-
else {
|
|
48
|
-
for (let i = 0; i < a.length; i++) {
|
|
49
|
-
if (!equality(a[i], b[i]))
|
|
50
|
-
return false;
|
|
51
|
-
}
|
|
52
|
-
return true;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
export function makeEquals(equality) {
|
|
56
|
-
return function (a, b) {
|
|
57
|
-
return equals(a, b, equality);
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
export function isEmpty(arr) {
|
|
61
|
-
return arr.length === 0;
|
|
62
|
-
}
|
|
63
|
-
export function hasValues(arr) {
|
|
64
|
-
return arr.length > 0;
|
|
65
|
-
}
|
|
66
|
-
export function filter(arr, predicate) {
|
|
67
|
-
const buff = [];
|
|
68
|
-
for (const a of arr)
|
|
69
|
-
if (predicate(a))
|
|
70
|
-
buff.push(a);
|
|
71
|
-
return buff;
|
|
72
|
-
}
|
|
73
|
-
export function filterNulls(arr) {
|
|
74
|
-
return filter(arr, v => v != null);
|
|
75
|
-
}
|
|
76
|
-
export function flatten(arr) {
|
|
77
|
-
return [].concat(...arr);
|
|
78
|
-
}
|
|
79
|
-
export function foldLeft(arr, f, b) {
|
|
80
|
-
for (const a of arr) {
|
|
81
|
-
b = f(b, a);
|
|
82
|
-
}
|
|
83
|
-
return b;
|
|
84
|
-
}
|
|
85
|
-
export function all(arr, predicate) {
|
|
86
|
-
for (const a of arr) {
|
|
87
|
-
if (!predicate(a)) {
|
|
88
|
-
return false;
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
return true;
|
|
92
|
-
}
|
|
93
|
-
export function any(arr, predicate) {
|
|
94
|
-
for (const a of arr) {
|
|
95
|
-
if (predicate(a)) {
|
|
96
|
-
return true;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
return false;
|
|
100
|
-
}
|
|
101
|
-
export function each(arr, f) {
|
|
102
|
-
for (const a of arr)
|
|
103
|
-
f(a);
|
|
104
|
-
}
|
|
105
|
-
export function concat(...arrs) {
|
|
106
|
-
return [].concat(...arrs);
|
|
107
|
-
}
|
|
108
|
-
export function makeCompare(comparef, shorterFirst = true) {
|
|
109
|
-
return function (a, b) {
|
|
110
|
-
if (a.length < b.length) {
|
|
111
|
-
return -1 * (shorterFirst ? 1 : -1);
|
|
112
|
-
}
|
|
113
|
-
else if (a.length > b.length) {
|
|
114
|
-
return 1 * (shorterFirst ? 1 : -1);
|
|
115
|
-
}
|
|
116
|
-
for (let i = 0; i < a.length; i++) {
|
|
117
|
-
const ord = comparef(a[i], b[i]);
|
|
118
|
-
if (ord !== 0)
|
|
119
|
-
return ord;
|
|
120
|
-
}
|
|
121
|
-
return 0;
|
|
122
|
-
};
|
|
123
|
-
}
|
|
124
|
-
export function sort(compare, arr) {
|
|
125
|
-
return arr.slice().sort(compare);
|
|
126
|
-
}
|
|
127
|
-
export function range(length, f) {
|
|
128
|
-
return Array.from({ length }, (_, i) => f(i));
|
|
129
|
-
}
|
|
130
|
-
export function numbersRange(length, startAt = 0) {
|
|
131
|
-
return range(length, i => startAt + i);
|
|
132
|
-
}
|
|
133
|
-
export function fill(length, value) {
|
|
134
|
-
return range(length, () => value);
|
|
135
|
-
}
|
|
136
|
-
export function distinctPrimitive(values) {
|
|
137
|
-
return Array.from(new Set(values));
|
|
138
|
-
}
|
|
139
|
-
export function distinctByPredicate(values, predicate) {
|
|
140
|
-
const map = {};
|
|
141
|
-
values.forEach(v => {
|
|
142
|
-
map[predicate(v)] = v;
|
|
143
|
-
});
|
|
144
|
-
return keys(map).map(k => map[k]);
|
|
145
|
-
}
|
|
146
|
-
export function remove(arr, item, predicate) {
|
|
147
|
-
let index;
|
|
148
|
-
if (predicate !== undefined) {
|
|
149
|
-
index = arr.findIndex(predicate);
|
|
150
|
-
}
|
|
151
|
-
else {
|
|
152
|
-
index = arr.indexOf(item);
|
|
153
|
-
}
|
|
154
|
-
if (index < 0) {
|
|
155
|
-
return false;
|
|
156
|
-
}
|
|
157
|
-
else {
|
|
158
|
-
arr.splice(index, 1);
|
|
159
|
-
return true;
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
export function ofIterableIterator(it) {
|
|
163
|
-
const buff = [];
|
|
164
|
-
for (let r = it.next(); !(r.done ?? false); r = it.next()) {
|
|
165
|
-
buff.push(r.value);
|
|
166
|
-
}
|
|
167
|
-
return buff;
|
|
168
|
-
}
|
|
169
|
-
export function diffOperations(from, to, getKey) {
|
|
170
|
-
const ops = {
|
|
171
|
-
removals: [],
|
|
172
|
-
swaps: [],
|
|
173
|
-
inserts: []
|
|
174
|
-
};
|
|
175
|
-
const { removals, inserts, swaps } = ops;
|
|
176
|
-
const mapB = new Map();
|
|
177
|
-
to.forEach((v, i) => mapB.set(getKey(v), i));
|
|
178
|
-
const indexesOfAThatDoNotExistInB = from
|
|
179
|
-
.map((v, i) => [v, i])
|
|
180
|
-
.filter(([v]) => !mapB.has(getKey(v)))
|
|
181
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
182
|
-
.map(([_, i]) => i);
|
|
183
|
-
for (let i = indexesOfAThatDoNotExistInB.length - 1; i >= 0; i--) {
|
|
184
|
-
const p = indexesOfAThatDoNotExistInB[i];
|
|
185
|
-
const last = removals.length > 0 ? removals[removals.length - 1] : undefined;
|
|
186
|
-
if ((last != null) && last.at === p + 1) {
|
|
187
|
-
last.at--;
|
|
188
|
-
last.qt++;
|
|
189
|
-
}
|
|
190
|
-
else {
|
|
191
|
-
removals.push({ at: p, qt: 1 });
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
const mapA = new Map();
|
|
195
|
-
from.forEach((v, i) => mapA.set(getKey(v), i));
|
|
196
|
-
const indexesOfBThatDoNotExistInA = to
|
|
197
|
-
.map((v, i) => [v, i])
|
|
198
|
-
.filter(([v]) => !mapA.has(getKey(v)))
|
|
199
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
200
|
-
.map(([_, i]) => i);
|
|
201
|
-
for (const p of indexesOfBThatDoNotExistInA) {
|
|
202
|
-
const last = inserts.length > 0 ? inserts[inserts.length - 1] : undefined;
|
|
203
|
-
if ((last != null) && last.at + last.values.length === p) {
|
|
204
|
-
last.values.push(to[p]);
|
|
205
|
-
}
|
|
206
|
-
else {
|
|
207
|
-
inserts.push({ at: p, values: [to[p]] });
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
const ra = from.filter((_, i) => !indexesOfAThatDoNotExistInB.includes(i));
|
|
211
|
-
const mapRA = new Map();
|
|
212
|
-
for (let i = 0; i < ra.length; i++) {
|
|
213
|
-
mapRA.set(getKey(ra[i]), i);
|
|
214
|
-
}
|
|
215
|
-
const rb = to.filter((_, i) => !indexesOfBThatDoNotExistInA.includes(i));
|
|
216
|
-
for (let i = 0; i < rb.length; i++) {
|
|
217
|
-
const bk = getKey(rb[i]);
|
|
218
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
219
|
-
const ai = mapRA.get(bk);
|
|
220
|
-
if (ai == null || i === ai)
|
|
221
|
-
continue;
|
|
222
|
-
const ak = getKey(ra[i]);
|
|
223
|
-
mapRA.delete(ak);
|
|
224
|
-
swaps.push({ from: i, to: ai });
|
|
225
|
-
}
|
|
226
|
-
return ops;
|
|
227
|
-
}
|
|
228
|
-
export function applyOperations(operations, start) {
|
|
229
|
-
const buff = [...start];
|
|
230
|
-
for (const { at, qt } of operations.removals) {
|
|
231
|
-
buff.splice(at, qt);
|
|
232
|
-
}
|
|
233
|
-
for (const { from, to } of operations.swaps) {
|
|
234
|
-
const t = buff[to];
|
|
235
|
-
buff[to] = buff[from];
|
|
236
|
-
buff[from] = t;
|
|
237
|
-
}
|
|
238
|
-
for (const op of operations.inserts) {
|
|
239
|
-
buff.splice(op.at, 0, ...op.values);
|
|
240
|
-
}
|
|
241
|
-
return buff;
|
|
242
|
-
}
|
|
243
|
-
export function joinWithConjunction(arr, conjunction = ' and ', separator = ', ') {
|
|
244
|
-
if (arr.length === 0)
|
|
245
|
-
return '';
|
|
246
|
-
if (arr.length === 1)
|
|
247
|
-
return String(arr[0]);
|
|
248
|
-
return `${arr.slice(0, -1).join(separator)}${conjunction}${String(arr[arr.length - 1])}`;
|
|
249
|
-
}
|
package/async-result.d.ts
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
export interface Idle {
|
|
2
|
-
type: 'idle';
|
|
3
|
-
}
|
|
4
|
-
export interface Loading {
|
|
5
|
-
type: 'loading';
|
|
6
|
-
}
|
|
7
|
-
export interface Success<V> {
|
|
8
|
-
type: 'success';
|
|
9
|
-
value: V;
|
|
10
|
-
}
|
|
11
|
-
export interface Failure<E> {
|
|
12
|
-
type: 'failure';
|
|
13
|
-
error: E;
|
|
14
|
-
}
|
|
15
|
-
export type AsyncResult<V, E> = Idle | Loading | Success<V> | Failure<E>;
|
|
16
|
-
export declare const AsyncResult: {
|
|
17
|
-
idle: {
|
|
18
|
-
type: "idle";
|
|
19
|
-
};
|
|
20
|
-
loading: {
|
|
21
|
-
type: "loading";
|
|
22
|
-
};
|
|
23
|
-
success<V>(value: V): AsyncResult<V, never>;
|
|
24
|
-
failure<E>(error: E): AsyncResult<never, E>;
|
|
25
|
-
isSuccess<V_1, E_1>(r: AsyncResult<V_1, E_1>): r is Success<V_1>;
|
|
26
|
-
isFailure<V_2, E_2>(r: AsyncResult<V_2, E_2>): r is Failure<E_2>;
|
|
27
|
-
isIdle<V_3, E_3>(r: AsyncResult<V_3, E_3>): r is Idle;
|
|
28
|
-
isLoading<V_4, E_4>(r: AsyncResult<V_4, E_4>): r is Loading;
|
|
29
|
-
getOrElse<V_5, E_5>(r: AsyncResult<V_5, E_5>, alt: V_5): V_5;
|
|
30
|
-
getOrElseLazy<V_6, E_6>(r: AsyncResult<V_6, E_6>, altf: () => V_6): V_6;
|
|
31
|
-
getOrNull<V_7, E_7>(r: AsyncResult<V_7, E_7>): V_7 | null;
|
|
32
|
-
getOrUndefined<V_8, E_8>(r: AsyncResult<V_8, E_8>): V_8 | undefined;
|
|
33
|
-
cmatch: <V1, V2, E_9>(success: (value: V1) => V2, failure: (error: E_9) => V2, loading: () => V2, idle?: () => V2) => (r: AsyncResult<V1, E_9>) => V2;
|
|
34
|
-
match: <V1_1, V2_1, E_10>(r: AsyncResult<V1_1, E_10>, success: (value: V1_1) => V2_1, failure: (error: E_10) => V2_1, loading: () => V2_1, idle?: () => V2_1) => V2_1;
|
|
35
|
-
whenSuccess: <V_9, E_11>(apply: (v: V_9) => void) => (r: AsyncResult<V_9, E_11>) => AsyncResult<V_9, E_11>;
|
|
36
|
-
whenFailure: <V_10, E_12>(apply: (e: E_12) => void) => (r: AsyncResult<V_10, E_12>) => AsyncResult<V_10, E_12>;
|
|
37
|
-
};
|