@goodbyenjn/utils 26.3.0 → 26.4.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/README.md +131 -66
- package/dist/chunks/{chunk-5ed3bc8a.js → chunk-11b9216b.js} +218 -351
- package/dist/chunks/chunk-1b381080.js +25 -0
- package/dist/chunks/chunk-3c6f28c7.d.ts +39 -0
- package/dist/chunks/chunk-3ce2ea14.js +36 -0
- package/dist/chunks/chunk-71e0c144.d.ts +168 -0
- package/dist/chunks/chunk-9fe6b612.d.ts +10 -0
- package/dist/chunks/chunk-bd9f56dd.d.ts +175 -0
- package/dist/common.d.ts +2 -195
- package/dist/common.js +2 -3
- package/dist/exec.d.ts +129 -0
- package/dist/exec.js +759 -0
- package/dist/fs.d.ts +422 -98
- package/dist/fs.js +999 -876
- package/dist/global-types.d.ts +146 -58
- package/dist/json.d.ts +29 -0
- package/dist/json.js +3 -0
- package/dist/remeda.d.ts +12 -12288
- package/dist/remeda.js +2 -3
- package/dist/result.d.ts +2 -2
- package/dist/result.js +2 -3
- package/dist/types.d.ts +3 -2
- package/dist/types.js +1 -1
- package/package.json +27 -18
- package/dist/chunks/chunk-b970a8d0.js +0 -2782
- package/dist/chunks/chunk-d1860346.d.ts +0 -154
- package/dist/chunks/chunk-e931fe39.d.ts +0 -11978
- package/dist/shell.d.ts +0 -111
- package/dist/shell.js +0 -781
|
@@ -1,35 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var __defProp = Object.defineProperty;
|
|
6
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
7
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
8
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
9
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
10
|
-
var __commonJSMin = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
|
|
11
|
-
var __copyProps = (to, from, except, desc) => {
|
|
12
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
-
for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
14
|
-
key = keys[i];
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except) {
|
|
16
|
-
__defProp(to, key, {
|
|
17
|
-
get: ((k) => from[k]).bind(null, key),
|
|
18
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
return to;
|
|
24
|
-
};
|
|
25
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
26
|
-
value: mod,
|
|
27
|
-
enumerable: true
|
|
28
|
-
}) : target, mod));
|
|
29
|
-
|
|
30
|
-
//#endregion
|
|
31
|
-
//#region node_modules/.pnpm/safe-stable-stringify@2.5.0/node_modules/safe-stable-stringify/index.js
|
|
32
|
-
var require_safe_stable_stringify = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
1
|
+
import { a as __toESM, t as __commonJSMin } from "./chunk-3ce2ea14.js";
|
|
2
|
+
import { add, addProp, allPass, anyPass, capitalize, ceil, chunk, clamp, clone, concat, conditional, constant, countBy, debounce as debounce$1, defaultTo, difference, differenceWith, divide, doNothing, drop, dropFirstBy, dropLast, dropLastWhile, dropWhile, endsWith, entries, evolve, filter, find, findIndex, findLast, findLastIndex, first, firstBy, flat, flatMap, floor, forEach, forEachObj, fromEntries, fromKeys, funnel, groupBy, groupByProp, hasAtLeast, hasSubObject, identity, indexBy, intersection, intersectionWith, invert, isArray, isBigInt, isBoolean, isDate, isDeepEqual, isDefined, isEmpty, isEmptyish, isError, isFunction, isIncludedIn, isNonNull, isNonNullish, isNot, isNullish, isNumber, isObjectType, isObjectType as isObjectType$1, isPlainObject, isPromise, isShallowEqual, isStrictEqual, isString as isString$1, isSymbol, isTruthy, join as join$1, keys, last, length, map, mapKeys, mapToObj, mapValues, mapWithFeedback, mean, meanBy, median, merge, mergeAll, mergeDeep, multiply, nthBy, objOf, omit, omitBy, once, only, partialBind, partialLastBind, partition, pathOr, pick, pickBy, pipe, piped, product, prop, pullObject, purry, purry as purry$1, randomBigInt, randomInteger, randomString, range, rankBy, reduce, reverse, round, sample, set, setPath, shuffle, sliceString, sort, sortBy, sortedIndex, sortedIndexBy, sortedIndexWith, sortedLastIndex, sortedLastIndexBy, splice, split as split$1, splitAt, splitWhen, startsWith, stringToPath, subtract, sum, sumBy, swapIndices, swapProps, take, takeFirstBy, takeLast, takeLastWhile, takeWhile, tap, times, toCamelCase, toKebabCase, toLowerCase, toSnakeCase, toTitleCase, toUpperCase, truncate, uncapitalize, unique, uniqueBy, uniqueWith, values, when, zip, zipWith } from "remeda";
|
|
3
|
+
import { accumulateAsync as accumulateP, accumulateSync as accumulate, awaitAll, buffer, chunkAsync as chunkP, compose, concatAsync as concatP, concurrency, differenceAsync as differenceP, differenceByAsync as differenceByP, differenceBySync as differenceBy, differenceWithAsync as differenceWithP, dropAsync as dropP, everyAsync as everyP, everySync as every, executeAsync as executeP, executeSync as execute, filterAsync as filterP, findAsync as findP, flatMapAsync as flatMapP, flattenAsync as flattenP, flattenSync as flatten, forEachAsync as forEachP, intersectionAsync as intersectionP, intersectionByAsync as intersectionByP, intersectionBySync as intersectionBy, intersectionWithAsync as intersectionWithP, mapAsync as mapP, peekAsync as peekP, peekSync as peek, reduceAsync as reduceP, serializeAsync as serializeP, serializeSync as serialize, someAsync as someP, someSync as some, takeAsync as takeP, throttle as throttle$1, toArrayAsync as toArrayP, toArraySync as toArray, toIteratorAsync as toIteratorP, toIteratorSync as toIterator, uniqueAsync as uniqueP, uniqueByAsync as uniqueByP, uniqueWithAsync as uniqueWithP } from "rotery";
|
|
4
|
+
const configure = __toESM(__commonJSMin(((exports, module) => {
|
|
33
5
|
const { hasOwnProperty } = Object.prototype;
|
|
34
6
|
const stringify = configure();
|
|
35
7
|
stringify.configure = configure;
|
|
@@ -110,7 +82,7 @@ var require_safe_stable_stringify = /* @__PURE__ */ __commonJSMin(((exports, mod
|
|
|
110
82
|
return `${number} items`;
|
|
111
83
|
}
|
|
112
84
|
function getUniqueReplacerSet(replacerArray) {
|
|
113
|
-
const replacerSet =
|
|
85
|
+
const replacerSet = new Set();
|
|
114
86
|
for (const value of replacerArray) if (typeof value === "string" || typeof value === "number") replacerSet.add(String(value));
|
|
115
87
|
return replacerSet;
|
|
116
88
|
}
|
|
@@ -118,9 +90,9 @@ var require_safe_stable_stringify = /* @__PURE__ */ __commonJSMin(((exports, mod
|
|
|
118
90
|
if (hasOwnProperty.call(options, "strict")) {
|
|
119
91
|
const value = options.strict;
|
|
120
92
|
if (typeof value !== "boolean") throw new TypeError("The \"strict\" argument must be of type boolean");
|
|
121
|
-
if (value) return (value
|
|
122
|
-
let message = `Object can not safely be stringified. Received type ${typeof value
|
|
123
|
-
if (typeof value
|
|
93
|
+
if (value) return (value) => {
|
|
94
|
+
let message = `Object can not safely be stringified. Received type ${typeof value}`;
|
|
95
|
+
if (typeof value !== "function") message += ` (${value.toString()})`;
|
|
124
96
|
throw new Error(message);
|
|
125
97
|
};
|
|
126
98
|
}
|
|
@@ -148,7 +120,7 @@ var require_safe_stable_stringify = /* @__PURE__ */ __commonJSMin(((exports, mod
|
|
|
148
120
|
if (value === null) return "null";
|
|
149
121
|
if (stack.indexOf(value) !== -1) return circularValue;
|
|
150
122
|
let res = "";
|
|
151
|
-
let join
|
|
123
|
+
let join = ",";
|
|
152
124
|
const originalIndentation = indentation;
|
|
153
125
|
if (Array.isArray(value)) {
|
|
154
126
|
if (value.length === 0) return "[]";
|
|
@@ -157,20 +129,20 @@ var require_safe_stable_stringify = /* @__PURE__ */ __commonJSMin(((exports, mod
|
|
|
157
129
|
if (spacer !== "") {
|
|
158
130
|
indentation += spacer;
|
|
159
131
|
res += `\n${indentation}`;
|
|
160
|
-
join
|
|
132
|
+
join = `,\n${indentation}`;
|
|
161
133
|
}
|
|
162
134
|
const maximumValuesToStringify = Math.min(value.length, maximumBreadth);
|
|
163
135
|
let i = 0;
|
|
164
136
|
for (; i < maximumValuesToStringify - 1; i++) {
|
|
165
|
-
const tmp
|
|
166
|
-
res += tmp
|
|
167
|
-
res += join
|
|
137
|
+
const tmp = stringifyFnReplacer(String(i), value, stack, replacer, spacer, indentation);
|
|
138
|
+
res += tmp !== void 0 ? tmp : "null";
|
|
139
|
+
res += join;
|
|
168
140
|
}
|
|
169
141
|
const tmp = stringifyFnReplacer(String(i), value, stack, replacer, spacer, indentation);
|
|
170
142
|
res += tmp !== void 0 ? tmp : "null";
|
|
171
143
|
if (value.length - 1 > maximumBreadth) {
|
|
172
144
|
const removedKeys = value.length - maximumBreadth - 1;
|
|
173
|
-
res += `${join
|
|
145
|
+
res += `${join}"... ${getItemCount(removedKeys)} not stringified"`;
|
|
174
146
|
}
|
|
175
147
|
if (spacer !== "") res += `\n${originalIndentation}`;
|
|
176
148
|
stack.pop();
|
|
@@ -184,24 +156,24 @@ var require_safe_stable_stringify = /* @__PURE__ */ __commonJSMin(((exports, mod
|
|
|
184
156
|
let separator = "";
|
|
185
157
|
if (spacer !== "") {
|
|
186
158
|
indentation += spacer;
|
|
187
|
-
join
|
|
159
|
+
join = `,\n${indentation}`;
|
|
188
160
|
whitespace = " ";
|
|
189
161
|
}
|
|
190
162
|
const maximumPropertiesToStringify = Math.min(keyLength, maximumBreadth);
|
|
191
163
|
if (deterministic && !isTypedArrayWithEntries(value)) keys = sort(keys, comparator);
|
|
192
164
|
stack.push(value);
|
|
193
165
|
for (let i = 0; i < maximumPropertiesToStringify; i++) {
|
|
194
|
-
const key
|
|
195
|
-
const tmp = stringifyFnReplacer(key
|
|
166
|
+
const key = keys[i];
|
|
167
|
+
const tmp = stringifyFnReplacer(key, value, stack, replacer, spacer, indentation);
|
|
196
168
|
if (tmp !== void 0) {
|
|
197
|
-
res += `${separator}${strEscape(key
|
|
198
|
-
separator = join
|
|
169
|
+
res += `${separator}${strEscape(key)}:${whitespace}${tmp}`;
|
|
170
|
+
separator = join;
|
|
199
171
|
}
|
|
200
172
|
}
|
|
201
173
|
if (keyLength > maximumBreadth) {
|
|
202
174
|
const removedKeys = keyLength - maximumBreadth;
|
|
203
175
|
res += `${separator}"...":${whitespace}"${getItemCount(removedKeys)} not stringified"`;
|
|
204
|
-
separator = join
|
|
176
|
+
separator = join;
|
|
205
177
|
}
|
|
206
178
|
if (spacer !== "" && separator.length > 1) res = `\n${indentation}${res}\n${originalIndentation}`;
|
|
207
179
|
stack.pop();
|
|
@@ -223,7 +195,7 @@ var require_safe_stable_stringify = /* @__PURE__ */ __commonJSMin(((exports, mod
|
|
|
223
195
|
if (stack.indexOf(value) !== -1) return circularValue;
|
|
224
196
|
const originalIndentation = indentation;
|
|
225
197
|
let res = "";
|
|
226
|
-
let join
|
|
198
|
+
let join = ",";
|
|
227
199
|
if (Array.isArray(value)) {
|
|
228
200
|
if (value.length === 0) return "[]";
|
|
229
201
|
if (maximumDepth < stack.length + 1) return "\"[Array]\"";
|
|
@@ -231,20 +203,20 @@ var require_safe_stable_stringify = /* @__PURE__ */ __commonJSMin(((exports, mod
|
|
|
231
203
|
if (spacer !== "") {
|
|
232
204
|
indentation += spacer;
|
|
233
205
|
res += `\n${indentation}`;
|
|
234
|
-
join
|
|
206
|
+
join = `,\n${indentation}`;
|
|
235
207
|
}
|
|
236
208
|
const maximumValuesToStringify = Math.min(value.length, maximumBreadth);
|
|
237
209
|
let i = 0;
|
|
238
210
|
for (; i < maximumValuesToStringify - 1; i++) {
|
|
239
|
-
const tmp
|
|
240
|
-
res += tmp
|
|
241
|
-
res += join
|
|
211
|
+
const tmp = stringifyArrayReplacer(String(i), value[i], stack, replacer, spacer, indentation);
|
|
212
|
+
res += tmp !== void 0 ? tmp : "null";
|
|
213
|
+
res += join;
|
|
242
214
|
}
|
|
243
215
|
const tmp = stringifyArrayReplacer(String(i), value[i], stack, replacer, spacer, indentation);
|
|
244
216
|
res += tmp !== void 0 ? tmp : "null";
|
|
245
217
|
if (value.length - 1 > maximumBreadth) {
|
|
246
218
|
const removedKeys = value.length - maximumBreadth - 1;
|
|
247
|
-
res += `${join
|
|
219
|
+
res += `${join}"... ${getItemCount(removedKeys)} not stringified"`;
|
|
248
220
|
}
|
|
249
221
|
if (spacer !== "") res += `\n${originalIndentation}`;
|
|
250
222
|
stack.pop();
|
|
@@ -254,15 +226,15 @@ var require_safe_stable_stringify = /* @__PURE__ */ __commonJSMin(((exports, mod
|
|
|
254
226
|
let whitespace = "";
|
|
255
227
|
if (spacer !== "") {
|
|
256
228
|
indentation += spacer;
|
|
257
|
-
join
|
|
229
|
+
join = `,\n${indentation}`;
|
|
258
230
|
whitespace = " ";
|
|
259
231
|
}
|
|
260
232
|
let separator = "";
|
|
261
|
-
for (const key
|
|
262
|
-
const tmp = stringifyArrayReplacer(key
|
|
233
|
+
for (const key of replacer) {
|
|
234
|
+
const tmp = stringifyArrayReplacer(key, value[key], stack, replacer, spacer, indentation);
|
|
263
235
|
if (tmp !== void 0) {
|
|
264
|
-
res += `${separator}${strEscape(key
|
|
265
|
-
separator = join
|
|
236
|
+
res += `${separator}${strEscape(key)}:${whitespace}${tmp}`;
|
|
237
|
+
separator = join;
|
|
266
238
|
}
|
|
267
239
|
}
|
|
268
240
|
if (spacer !== "" && separator.length > 1) res = `\n${indentation}${res}\n${originalIndentation}`;
|
|
@@ -293,54 +265,54 @@ var require_safe_stable_stringify = /* @__PURE__ */ __commonJSMin(((exports, mod
|
|
|
293
265
|
if (maximumDepth < stack.length + 1) return "\"[Array]\"";
|
|
294
266
|
stack.push(value);
|
|
295
267
|
indentation += spacer;
|
|
296
|
-
let res
|
|
297
|
-
const join
|
|
268
|
+
let res = `\n${indentation}`;
|
|
269
|
+
const join = `,\n${indentation}`;
|
|
298
270
|
const maximumValuesToStringify = Math.min(value.length, maximumBreadth);
|
|
299
271
|
let i = 0;
|
|
300
272
|
for (; i < maximumValuesToStringify - 1; i++) {
|
|
301
|
-
const tmp
|
|
302
|
-
res
|
|
303
|
-
res
|
|
273
|
+
const tmp = stringifyIndent(String(i), value[i], stack, spacer, indentation);
|
|
274
|
+
res += tmp !== void 0 ? tmp : "null";
|
|
275
|
+
res += join;
|
|
304
276
|
}
|
|
305
277
|
const tmp = stringifyIndent(String(i), value[i], stack, spacer, indentation);
|
|
306
|
-
res
|
|
278
|
+
res += tmp !== void 0 ? tmp : "null";
|
|
307
279
|
if (value.length - 1 > maximumBreadth) {
|
|
308
280
|
const removedKeys = value.length - maximumBreadth - 1;
|
|
309
|
-
res
|
|
281
|
+
res += `${join}"... ${getItemCount(removedKeys)} not stringified"`;
|
|
310
282
|
}
|
|
311
|
-
res
|
|
283
|
+
res += `\n${originalIndentation}`;
|
|
312
284
|
stack.pop();
|
|
313
|
-
return `[${res
|
|
285
|
+
return `[${res}]`;
|
|
314
286
|
}
|
|
315
287
|
let keys = Object.keys(value);
|
|
316
288
|
const keyLength = keys.length;
|
|
317
289
|
if (keyLength === 0) return "{}";
|
|
318
290
|
if (maximumDepth < stack.length + 1) return "\"[Object]\"";
|
|
319
291
|
indentation += spacer;
|
|
320
|
-
const join
|
|
292
|
+
const join = `,\n${indentation}`;
|
|
321
293
|
let res = "";
|
|
322
294
|
let separator = "";
|
|
323
295
|
let maximumPropertiesToStringify = Math.min(keyLength, maximumBreadth);
|
|
324
296
|
if (isTypedArrayWithEntries(value)) {
|
|
325
|
-
res += stringifyTypedArray(value, join
|
|
297
|
+
res += stringifyTypedArray(value, join, maximumBreadth);
|
|
326
298
|
keys = keys.slice(value.length);
|
|
327
299
|
maximumPropertiesToStringify -= value.length;
|
|
328
|
-
separator = join
|
|
300
|
+
separator = join;
|
|
329
301
|
}
|
|
330
302
|
if (deterministic) keys = sort(keys, comparator);
|
|
331
303
|
stack.push(value);
|
|
332
304
|
for (let i = 0; i < maximumPropertiesToStringify; i++) {
|
|
333
|
-
const key
|
|
334
|
-
const tmp = stringifyIndent(key
|
|
305
|
+
const key = keys[i];
|
|
306
|
+
const tmp = stringifyIndent(key, value[key], stack, spacer, indentation);
|
|
335
307
|
if (tmp !== void 0) {
|
|
336
|
-
res += `${separator}${strEscape(key
|
|
337
|
-
separator = join
|
|
308
|
+
res += `${separator}${strEscape(key)}: ${tmp}`;
|
|
309
|
+
separator = join;
|
|
338
310
|
}
|
|
339
311
|
}
|
|
340
312
|
if (keyLength > maximumBreadth) {
|
|
341
313
|
const removedKeys = keyLength - maximumBreadth;
|
|
342
314
|
res += `${separator}"...": "${getItemCount(removedKeys)} not stringified"`;
|
|
343
|
-
separator = join
|
|
315
|
+
separator = join;
|
|
344
316
|
}
|
|
345
317
|
if (separator !== "") res = `\n${indentation}${res}\n${originalIndentation}`;
|
|
346
318
|
stack.pop();
|
|
@@ -373,8 +345,8 @@ var require_safe_stable_stringify = /* @__PURE__ */ __commonJSMin(((exports, mod
|
|
|
373
345
|
const maximumValuesToStringify = Math.min(value.length, maximumBreadth);
|
|
374
346
|
let i = 0;
|
|
375
347
|
for (; i < maximumValuesToStringify - 1; i++) {
|
|
376
|
-
const tmp
|
|
377
|
-
res += tmp
|
|
348
|
+
const tmp = stringifySimple(String(i), value[i], stack);
|
|
349
|
+
res += tmp !== void 0 ? tmp : "null";
|
|
378
350
|
res += ",";
|
|
379
351
|
}
|
|
380
352
|
const tmp = stringifySimple(String(i), value[i], stack);
|
|
@@ -401,10 +373,10 @@ var require_safe_stable_stringify = /* @__PURE__ */ __commonJSMin(((exports, mod
|
|
|
401
373
|
if (deterministic) keys = sort(keys, comparator);
|
|
402
374
|
stack.push(value);
|
|
403
375
|
for (let i = 0; i < maximumPropertiesToStringify; i++) {
|
|
404
|
-
const key
|
|
405
|
-
const tmp = stringifySimple(key
|
|
376
|
+
const key = keys[i];
|
|
377
|
+
const tmp = stringifySimple(key, value[key], stack);
|
|
406
378
|
if (tmp !== void 0) {
|
|
407
|
-
res += `${separator}${strEscape(key
|
|
379
|
+
res += `${separator}${strEscape(key)}:${tmp}`;
|
|
408
380
|
separator = ",";
|
|
409
381
|
}
|
|
410
382
|
}
|
|
@@ -422,7 +394,7 @@ var require_safe_stable_stringify = /* @__PURE__ */ __commonJSMin(((exports, mod
|
|
|
422
394
|
default: return fail ? fail(value) : void 0;
|
|
423
395
|
}
|
|
424
396
|
}
|
|
425
|
-
function stringify
|
|
397
|
+
function stringify(value, replacer, space) {
|
|
426
398
|
if (arguments.length > 1) {
|
|
427
399
|
let spacer = "";
|
|
428
400
|
if (typeof space === "number") spacer = " ".repeat(Math.min(space, 10));
|
|
@@ -435,88 +407,70 @@ var require_safe_stable_stringify = /* @__PURE__ */ __commonJSMin(((exports, mod
|
|
|
435
407
|
}
|
|
436
408
|
return stringifySimple("", value, []);
|
|
437
409
|
}
|
|
438
|
-
return stringify
|
|
410
|
+
return stringify;
|
|
439
411
|
}
|
|
440
|
-
}));
|
|
441
|
-
|
|
412
|
+
}))(), 1).configure;
|
|
442
413
|
//#endregion
|
|
443
|
-
//#region
|
|
444
|
-
|
|
445
|
-
const configure = import_safe_stable_stringify.configure;
|
|
446
|
-
|
|
414
|
+
//#region src/json/stable.ts
|
|
415
|
+
const stableStringify = configure({ bigint: true });
|
|
447
416
|
//#endregion
|
|
448
417
|
//#region src/result/error.ts
|
|
449
|
-
const prepare = (
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
const
|
|
460
|
-
|
|
461
|
-
if (message) msg = message;
|
|
462
|
-
else while (ctxs.length > 0) {
|
|
463
|
-
msg = ctxs.shift();
|
|
464
|
-
if (msg) break;
|
|
465
|
-
}
|
|
466
|
-
const ctx = ctxs.map((line, index) => ` ${index}: ${line}`).join("\n");
|
|
467
|
-
const display = `
|
|
418
|
+
const prepare = (result, msg) => {
|
|
419
|
+
const cause = result["error"];
|
|
420
|
+
const reason = cause === void 0 ? "" : getErrorMessage(cause);
|
|
421
|
+
const contexts = result["contexts"].reverse().concat(reason || []);
|
|
422
|
+
let message = "";
|
|
423
|
+
if (msg) message = msg;
|
|
424
|
+
else while (contexts.length > 0) {
|
|
425
|
+
message = contexts.shift();
|
|
426
|
+
if (message) break;
|
|
427
|
+
}
|
|
428
|
+
const ctx = contexts.map((line, index) => ` ${index}: ${line}`).join("\n");
|
|
429
|
+
const formatted = `
|
|
468
430
|
Message:
|
|
469
|
-
${
|
|
470
|
-
|
|
431
|
+
${message || "<empty message>"}
|
|
471
432
|
Context:
|
|
472
433
|
${ctx.trim() || "<empty context>"}
|
|
473
434
|
`.trim();
|
|
435
|
+
const options = isError(cause) ? { cause } : void 0;
|
|
474
436
|
return {
|
|
475
|
-
message
|
|
476
|
-
contexts
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
options: e$9 ? { cause: e$9 } : void 0
|
|
437
|
+
message,
|
|
438
|
+
contexts,
|
|
439
|
+
formatted,
|
|
440
|
+
options
|
|
480
441
|
};
|
|
481
442
|
};
|
|
482
443
|
var ResultError = class ResultError extends Error {
|
|
483
|
-
static
|
|
444
|
+
static is(value) {
|
|
484
445
|
return value instanceof ResultError;
|
|
485
446
|
}
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
447
|
+
static fmt(result, message) {
|
|
448
|
+
return prepare(result, message).formatted;
|
|
449
|
+
}
|
|
450
|
+
#msg;
|
|
451
|
+
#ctx;
|
|
452
|
+
#formatted;
|
|
453
|
+
constructor(result, message, caller = ResultError) {
|
|
454
|
+
const prepared = prepare(result, message);
|
|
491
455
|
super(`
|
|
492
|
-
|
|
493
|
-
${prepared.
|
|
494
|
-
|
|
456
|
+
--------------------
|
|
457
|
+
${prepared.formatted}
|
|
495
458
|
Stack trace:`, prepared.options);
|
|
496
459
|
Error.captureStackTrace(this, caller || this.constructor);
|
|
497
|
-
this.#
|
|
498
|
-
this.#
|
|
499
|
-
this.#
|
|
460
|
+
this.#msg = prepared.message;
|
|
461
|
+
this.#ctx = prepared.contexts;
|
|
462
|
+
this.#formatted = prepared.formatted;
|
|
500
463
|
}
|
|
501
464
|
get msg() {
|
|
502
|
-
return this.#
|
|
465
|
+
return this.#msg;
|
|
503
466
|
}
|
|
504
|
-
get
|
|
505
|
-
return this.#
|
|
467
|
+
get contexts() {
|
|
468
|
+
return this.#ctx;
|
|
506
469
|
}
|
|
507
470
|
toString() {
|
|
508
|
-
return this.#
|
|
471
|
+
return this.#formatted;
|
|
509
472
|
}
|
|
510
473
|
};
|
|
511
|
-
|
|
512
|
-
//#endregion
|
|
513
|
-
//#region src/result/helper.ts
|
|
514
|
-
function safeTry(body, self) {
|
|
515
|
-
const yieldErr = body.call(self).next();
|
|
516
|
-
if (isPromiseLike(yieldErr)) return yieldErr.then((res) => res.value);
|
|
517
|
-
return yieldErr.value;
|
|
518
|
-
}
|
|
519
|
-
|
|
520
474
|
//#endregion
|
|
521
475
|
//#region src/result/result.ts
|
|
522
476
|
const never = void 0;
|
|
@@ -526,236 +480,208 @@ const transformError = (error, onThrow) => {
|
|
|
526
480
|
return onThrow(error);
|
|
527
481
|
};
|
|
528
482
|
var Result = class Result {
|
|
483
|
+
static is(value) {
|
|
484
|
+
return value instanceof Result;
|
|
485
|
+
}
|
|
529
486
|
static ok(value) {
|
|
530
487
|
return new Result(true, never, value);
|
|
531
488
|
}
|
|
532
489
|
static err(error) {
|
|
533
490
|
return new Result(false, error, never);
|
|
534
491
|
}
|
|
535
|
-
static
|
|
492
|
+
static try(fnOrPromise, onThrow) {
|
|
493
|
+
if (!isFunction$1(fnOrPromise) && !isPromiseLike(fnOrPromise)) {
|
|
494
|
+
const error = new TypeError("Argument must be a function or a promise");
|
|
495
|
+
return this.err(transformError(error, onThrow));
|
|
496
|
+
}
|
|
497
|
+
if (isPromiseLike(fnOrPromise)) return fnOrPromise.then((value) => this.ok(value), (error) => this.err(transformError(error, onThrow)));
|
|
536
498
|
try {
|
|
537
|
-
|
|
538
|
-
const error = /* @__PURE__ */ new TypeError("Provided argument is not callable");
|
|
539
|
-
return this.err(transformError(error, onThrow));
|
|
540
|
-
}
|
|
541
|
-
const data = callable();
|
|
499
|
+
const data = fnOrPromise();
|
|
542
500
|
if (!isPromiseLike(data)) return this.ok(data);
|
|
543
501
|
return data.then((value) => this.ok(value), (error) => this.err(transformError(error, onThrow)));
|
|
544
502
|
} catch (error) {
|
|
545
503
|
return this.err(transformError(error, onThrow));
|
|
546
504
|
}
|
|
547
505
|
}
|
|
548
|
-
static
|
|
506
|
+
static wrap(fn, onThrow) {
|
|
549
507
|
return (...args) => {
|
|
550
|
-
return this.
|
|
508
|
+
return this.try(() => fn(...args), onThrow);
|
|
551
509
|
};
|
|
552
510
|
}
|
|
553
511
|
static all(results) {
|
|
554
512
|
const values = [];
|
|
555
513
|
for (const result of results) {
|
|
556
|
-
if (result.isErr()) return this.err(result
|
|
557
|
-
values.push(result
|
|
514
|
+
if (result.isErr()) return this.err(result.error);
|
|
515
|
+
values.push(result.value);
|
|
558
516
|
}
|
|
559
517
|
return this.ok(values);
|
|
560
518
|
}
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
519
|
+
static gen(body, self) {
|
|
520
|
+
const next = body.call(self).next();
|
|
521
|
+
const handle = (result) => {
|
|
522
|
+
if (!result.done) return result.value;
|
|
523
|
+
return result.value instanceof Result ? result.value : this.ok(result.value);
|
|
524
|
+
};
|
|
525
|
+
if (isPromiseLike(next)) return next.then(handle);
|
|
526
|
+
return handle(next);
|
|
527
|
+
}
|
|
528
|
+
ok;
|
|
529
|
+
value;
|
|
530
|
+
error;
|
|
564
531
|
#contexts = [];
|
|
565
|
-
|
|
566
|
-
this.#
|
|
567
|
-
|
|
568
|
-
|
|
532
|
+
get contexts() {
|
|
533
|
+
return this.#contexts;
|
|
534
|
+
}
|
|
535
|
+
constructor(ok, error, value) {
|
|
536
|
+
this.ok = ok;
|
|
537
|
+
this.error = error;
|
|
538
|
+
this.value = value;
|
|
569
539
|
}
|
|
570
|
-
/**
|
|
571
|
-
* Check if `Result` is `OK`
|
|
572
|
-
*/
|
|
573
540
|
isOk() {
|
|
574
|
-
return this
|
|
541
|
+
return this.ok;
|
|
575
542
|
}
|
|
576
|
-
/**
|
|
577
|
-
* Check if `Result` is `OK` and the value matches the predicate
|
|
578
|
-
*/
|
|
579
543
|
isOkAnd(predicate) {
|
|
580
|
-
return this.isOk() && predicate(this
|
|
544
|
+
return this.isOk() && predicate(this.value);
|
|
581
545
|
}
|
|
582
|
-
/**
|
|
583
|
-
* Check if `Result` is `Err`
|
|
584
|
-
*/
|
|
585
546
|
isErr() {
|
|
586
|
-
return !this
|
|
547
|
+
return !this.ok;
|
|
587
548
|
}
|
|
588
|
-
/**
|
|
589
|
-
* Check if `Result` is `Err` and the error matches the predicate
|
|
590
|
-
*/
|
|
591
549
|
isErrAnd(predicate) {
|
|
592
|
-
return this.isErr() && predicate(this
|
|
550
|
+
return this.isErr() && predicate(this.error);
|
|
593
551
|
}
|
|
594
|
-
/**
|
|
595
|
-
* Maps `Result<T, E>` to `Result<U, E>`
|
|
596
|
-
*/
|
|
597
552
|
map(fn) {
|
|
598
|
-
|
|
553
|
+
if (this.isErr()) return this;
|
|
554
|
+
const result = fn(this.value);
|
|
555
|
+
return isPromiseLike(result) ? result.then(Result.ok) : Result.ok(result);
|
|
599
556
|
}
|
|
600
|
-
/**
|
|
601
|
-
* Maps `Result<T, E>` to `Result<T, F>`
|
|
602
|
-
*/
|
|
603
557
|
mapErr(fn) {
|
|
604
|
-
|
|
558
|
+
if (this.isOk()) return this;
|
|
559
|
+
const result = fn(this.error);
|
|
560
|
+
return isPromiseLike(result) ? result.then(Result.err) : Result.err(result);
|
|
605
561
|
}
|
|
606
562
|
and(result) {
|
|
607
563
|
return this.isErr() ? this : result;
|
|
608
564
|
}
|
|
609
565
|
andThen(fn) {
|
|
610
|
-
return this.isErr() ? this : fn(this
|
|
566
|
+
return this.isErr() ? this : fn(this.value);
|
|
611
567
|
}
|
|
612
568
|
or(result) {
|
|
613
569
|
return this.isOk() ? this : result;
|
|
614
570
|
}
|
|
615
571
|
orElse(fn) {
|
|
616
|
-
return this.isOk() ? this : fn(this
|
|
572
|
+
return this.isOk() ? this : fn(this.error);
|
|
617
573
|
}
|
|
618
|
-
/**
|
|
619
|
-
* Calls the function with the value if `Result` is `Ok` and returns the result unchanged
|
|
620
|
-
*/
|
|
621
574
|
inspect(fn) {
|
|
622
575
|
try {
|
|
623
|
-
this.isOk() && fn(this
|
|
576
|
+
this.isOk() && fn(this.value);
|
|
624
577
|
} catch {}
|
|
625
578
|
return this;
|
|
626
579
|
}
|
|
627
|
-
/**
|
|
628
|
-
* Calls the function with the error if `Result` is `Err` and returns the result unchanged
|
|
629
|
-
*/
|
|
630
580
|
inspectErr(fn) {
|
|
631
581
|
try {
|
|
632
|
-
this.isErr() && fn(this
|
|
582
|
+
this.isErr() && fn(this.error);
|
|
633
583
|
} catch {}
|
|
634
584
|
return this;
|
|
635
585
|
}
|
|
636
|
-
/**
|
|
637
|
-
* Unwrap the `Ok` value, or throw an error if `Result` is `Err`
|
|
638
|
-
*/
|
|
639
586
|
unwrap(message) {
|
|
640
|
-
if (this.isErr()) throw new ResultError(message !== null ? message ?? "Called unwrap on an Err value" : void 0, this
|
|
641
|
-
return this
|
|
587
|
+
if (this.isErr()) throw new ResultError(this, message !== null ? message ?? "Called `unwrap` on an `Err` value" : void 0, this.unwrap);
|
|
588
|
+
return this.value;
|
|
642
589
|
}
|
|
643
|
-
/**
|
|
644
|
-
* Unwrap the `Err` value, or throw an error if `Result` is `Ok`
|
|
645
|
-
*/
|
|
646
590
|
unwrapErr(message) {
|
|
647
|
-
if (this.isOk()) throw new ResultError(message !== null ? message ?? "Called unwrapErr on an Ok value" : void 0, this
|
|
648
|
-
return this
|
|
591
|
+
if (this.isOk()) throw new ResultError(this, message !== null ? message ?? "Called `unwrapErr` on an `Ok` value" : void 0, this.unwrapErr);
|
|
592
|
+
return this.error;
|
|
649
593
|
}
|
|
650
|
-
/**
|
|
651
|
-
* Unwrap the `Ok` value, or return the provided value if `Result` is `Err`
|
|
652
|
-
*/
|
|
653
594
|
unwrapOr(defaultValue) {
|
|
654
|
-
return this.isOk() ? this
|
|
595
|
+
return this.isOk() ? this.value : defaultValue;
|
|
655
596
|
}
|
|
656
|
-
/**
|
|
657
|
-
* Unwrap the `Ok` value, or compute it from a function if `Result` is `Err`
|
|
658
|
-
*/
|
|
659
597
|
unwrapOrElse(defaultValueGetter) {
|
|
660
|
-
return this.isOk() ? this
|
|
598
|
+
return this.isOk() ? this.value : defaultValueGetter(this.error);
|
|
661
599
|
}
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
*/
|
|
665
|
-
match(ok$1, err$1) {
|
|
666
|
-
return this.isOk() ? ok$1(this.#value) : err$1(this.#error);
|
|
600
|
+
match(ok, err) {
|
|
601
|
+
return this.isOk() ? ok(this.value) : err(this.error);
|
|
667
602
|
}
|
|
668
|
-
/**
|
|
669
|
-
* Returns an iterable object that yields the `Ok` value and `Err` value
|
|
670
|
-
*/
|
|
671
603
|
iter() {
|
|
672
604
|
if (this.isOk()) return [
|
|
673
605
|
true,
|
|
674
606
|
never,
|
|
675
|
-
this
|
|
607
|
+
this.value
|
|
676
608
|
];
|
|
677
609
|
else return [
|
|
678
610
|
false,
|
|
679
|
-
this
|
|
611
|
+
this.error,
|
|
680
612
|
never
|
|
681
613
|
];
|
|
682
614
|
}
|
|
683
615
|
*[Symbol.iterator]() {
|
|
684
|
-
if (this.isOk()) return this
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
return self;
|
|
616
|
+
if (this.isOk()) return this.value;
|
|
617
|
+
yield this;
|
|
618
|
+
return this;
|
|
688
619
|
}
|
|
689
620
|
context(context) {
|
|
690
621
|
this.#contexts.push(context);
|
|
691
622
|
return this;
|
|
692
623
|
}
|
|
693
|
-
toString() {
|
|
694
|
-
if (this.isErr()) return new ResultError(void 0, this.#error, this.#contexts).toString();
|
|
695
|
-
return `Ok(${stringify(this.#value)})`;
|
|
696
|
-
}
|
|
697
624
|
};
|
|
698
625
|
const ok = Result.ok;
|
|
699
626
|
const err = Result.err;
|
|
700
|
-
|
|
627
|
+
const isResult = Result.is;
|
|
701
628
|
//#endregion
|
|
702
|
-
//#region src/
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
629
|
+
//#region src/remeda/hasOwnProperty.ts
|
|
630
|
+
function hasOwnProperty(...args) {
|
|
631
|
+
return purry(hasOwnPropertyImplementation, args);
|
|
632
|
+
}
|
|
633
|
+
function hasOwnPropertyImplementation(data, properties) {
|
|
634
|
+
if (!isObjectType(data)) return false;
|
|
635
|
+
for (const property of properties) if (!Object.hasOwn(data, property)) return false;
|
|
636
|
+
return true;
|
|
637
|
+
}
|
|
638
|
+
//#endregion
|
|
639
|
+
//#region src/remeda/isFunction.ts
|
|
640
|
+
function isFunction$1(data) {
|
|
641
|
+
return typeof data === "function";
|
|
642
|
+
}
|
|
643
|
+
//#endregion
|
|
644
|
+
//#region src/remeda/isPromiseLike.ts
|
|
645
|
+
function isPromiseLike(data) {
|
|
646
|
+
return isObjectType(data) && isFunction(data.then) && Object.getOwnPropertyDescriptor(data, "then")?.get === void 0;
|
|
647
|
+
}
|
|
716
648
|
//#endregion
|
|
717
649
|
//#region src/common/error.ts
|
|
718
650
|
const normalizeError = (error, caller) => {
|
|
719
|
-
if (
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
651
|
+
if (isError(error)) return error;
|
|
652
|
+
const e = new Error(getErrorMessage(error));
|
|
653
|
+
Error.captureStackTrace(e, caller || normalizeError);
|
|
654
|
+
return e;
|
|
655
|
+
};
|
|
656
|
+
const getErrorMessage = (error, message) => {
|
|
657
|
+
if (isError(error)) return error.message;
|
|
658
|
+
if (message !== void 0) return message;
|
|
659
|
+
let msg;
|
|
660
|
+
if (isString$1(error) || isNumber(error) || isBigInt(error) || isBoolean(error) || isSymbol(error)) msg = error.toString();
|
|
661
|
+
else if (error === void 0) msg = "undefined";
|
|
662
|
+
else if (error === null) msg = "null";
|
|
663
|
+
else msg = stableStringify(error);
|
|
664
|
+
return msg;
|
|
728
665
|
};
|
|
729
|
-
const getErrorMessage = (error, message = "Unknown error") => error instanceof Error ? error.message : message;
|
|
730
|
-
|
|
731
666
|
//#endregion
|
|
732
667
|
//#region src/common/math.ts
|
|
733
|
-
/**
|
|
734
|
-
* @example
|
|
735
|
-
* ```
|
|
736
|
-
* const value = linear(0.5, [0, 2]) // value: 1
|
|
737
|
-
* ```
|
|
738
|
-
*/
|
|
739
668
|
const linear = (value, range) => {
|
|
740
669
|
const [min, max] = range;
|
|
741
|
-
const interpolation =
|
|
670
|
+
const interpolation = clamp(value, {
|
|
742
671
|
min: 0,
|
|
743
672
|
max: 1
|
|
744
673
|
});
|
|
745
674
|
return min + (max - min) * interpolation;
|
|
746
675
|
};
|
|
747
|
-
/**
|
|
748
|
-
* @example
|
|
749
|
-
* ```
|
|
750
|
-
* const value = scale(0.5, [0, 1], [200, 400]) // value: 300
|
|
751
|
-
* ```
|
|
752
|
-
*/
|
|
753
676
|
const scale = (value, inRange, outRange) => {
|
|
754
677
|
const [inMin, inMax] = inRange;
|
|
755
678
|
const [outMin, outMax] = outRange;
|
|
756
679
|
return linear((value - inMin) / (inMax - inMin), [outMin, outMax]);
|
|
757
680
|
};
|
|
758
|
-
|
|
681
|
+
//#endregion
|
|
682
|
+
//#region src/common/nil.ts
|
|
683
|
+
const nil = Symbol("nil");
|
|
684
|
+
const isNil = (value) => value === nil;
|
|
759
685
|
//#endregion
|
|
760
686
|
//#region src/common/parse.ts
|
|
761
687
|
const parseKey = (input, raw = input) => {
|
|
@@ -764,10 +690,10 @@ const parseKey = (input, raw = input) => {
|
|
|
764
690
|
end: 0
|
|
765
691
|
};
|
|
766
692
|
else if (/^\s/.test(input)) {
|
|
767
|
-
const { value
|
|
693
|
+
const { value, end } = parseKey(input.slice(1), raw);
|
|
768
694
|
return {
|
|
769
|
-
value
|
|
770
|
-
end: end
|
|
695
|
+
value,
|
|
696
|
+
end: end + 1
|
|
771
697
|
};
|
|
772
698
|
}
|
|
773
699
|
let value = "";
|
|
@@ -836,7 +762,6 @@ const parseValueToBoolean = (value, defaultValue) => {
|
|
|
836
762
|
if (/^(?:n|no|false|0|off)$/.test(str)) return false;
|
|
837
763
|
return defaultValue;
|
|
838
764
|
};
|
|
839
|
-
|
|
840
765
|
//#endregion
|
|
841
766
|
//#region src/common/promise.ts
|
|
842
767
|
const sleep = (ms, callback) => new Promise((resolve) => {
|
|
@@ -858,19 +783,6 @@ const createSingleton = (fn) => {
|
|
|
858
783
|
};
|
|
859
784
|
return wrapper;
|
|
860
785
|
};
|
|
861
|
-
/**
|
|
862
|
-
* @example
|
|
863
|
-
* ```
|
|
864
|
-
* const lock = createLock()
|
|
865
|
-
*
|
|
866
|
-
* lock.run(async () => {
|
|
867
|
-
* await doSomething()
|
|
868
|
-
* })
|
|
869
|
-
*
|
|
870
|
-
* // in anther context:
|
|
871
|
-
* await lock.wait() // it will wait all tasking finished
|
|
872
|
-
* ```
|
|
873
|
-
*/
|
|
874
786
|
const createLock = () => {
|
|
875
787
|
const locks = [];
|
|
876
788
|
return {
|
|
@@ -896,7 +808,7 @@ const createLock = () => {
|
|
|
896
808
|
};
|
|
897
809
|
};
|
|
898
810
|
const createPromiseWithResolvers = () => {
|
|
899
|
-
if (isFunction(Promise.withResolvers)) return Promise.withResolvers();
|
|
811
|
+
if (isFunction$1(Promise.withResolvers)) return Promise.withResolvers();
|
|
900
812
|
let resolve;
|
|
901
813
|
let reject;
|
|
902
814
|
return {
|
|
@@ -908,7 +820,6 @@ const createPromiseWithResolvers = () => {
|
|
|
908
820
|
reject
|
|
909
821
|
};
|
|
910
822
|
};
|
|
911
|
-
|
|
912
823
|
//#endregion
|
|
913
824
|
//#region src/common/string.ts
|
|
914
825
|
const REGEXP_WHITESPACE_ONLY = /^\s*$/;
|
|
@@ -951,41 +862,20 @@ const toForwardSlash = (str) => str.replace(/\\/g, "/");
|
|
|
951
862
|
const joinWithSlash = (...paths) => join("/", ...paths);
|
|
952
863
|
const splitWithSlash = (path) => split("/", path);
|
|
953
864
|
const splitByLineBreak = (str) => str.split(/\r?\n/);
|
|
954
|
-
const concatTemplateStrings = (template
|
|
955
|
-
|
|
956
|
-
* @example
|
|
957
|
-
* ```ts
|
|
958
|
-
* // Default behavior: trim both start and end
|
|
959
|
-
* const str1 = unindent`
|
|
960
|
-
* if (a) {
|
|
961
|
-
* b()
|
|
962
|
-
* }
|
|
963
|
-
* `;
|
|
964
|
-
*
|
|
965
|
-
* // Factory function: custom trim behavior
|
|
966
|
-
* const str2 = unindent(false, false)`
|
|
967
|
-
* if (a) {
|
|
968
|
-
* b()
|
|
969
|
-
* }
|
|
970
|
-
* `;
|
|
971
|
-
*
|
|
972
|
-
* // Only trim start, keep end
|
|
973
|
-
* const str3 = unindent(true, false)(" hello\n world\n");
|
|
974
|
-
* ```
|
|
975
|
-
*/
|
|
976
|
-
const unindent = (...params) => {
|
|
865
|
+
const concatTemplateStrings = (template, values) => template.reduce((acc, part, index) => acc + part + (values[index] ?? ""), "");
|
|
866
|
+
function unindent(...params) {
|
|
977
867
|
let trimStart = true;
|
|
978
868
|
let trimEnd = true;
|
|
979
|
-
const unindentImpl = (...params
|
|
980
|
-
const lines = splitByLineBreak(
|
|
869
|
+
const unindentImpl = (...params) => {
|
|
870
|
+
const lines = splitByLineBreak(isString$1(params[0]) ? params[0] : concatTemplateStrings(params[0], params.slice(1)));
|
|
981
871
|
let commonIndent = Number.POSITIVE_INFINITY;
|
|
982
872
|
let firstContentLine = -1;
|
|
983
873
|
for (let i = 0; i < lines.length; i++) {
|
|
984
874
|
const line = lines[i];
|
|
985
875
|
if (REGEXP_WHITESPACE_ONLY.test(line)) continue;
|
|
986
876
|
if (firstContentLine === -1) firstContentLine = i;
|
|
987
|
-
const indent
|
|
988
|
-
commonIndent = Math.min(commonIndent, indent
|
|
877
|
+
const indent = line.match(REGEXP_WHITESPACE_PREFIX)?.[0].length ?? 0;
|
|
878
|
+
commonIndent = Math.min(commonIndent, indent);
|
|
989
879
|
}
|
|
990
880
|
if (firstContentLine === -1) commonIndent = 0;
|
|
991
881
|
if (!Number.isFinite(commonIndent)) commonIndent = 0;
|
|
@@ -995,41 +885,20 @@ const unindent = (...params) => {
|
|
|
995
885
|
if (trimEnd) while (endIndex > startIndex && REGEXP_WHITESPACE_ONLY.test(lines[endIndex - 1])) endIndex--;
|
|
996
886
|
return lines.slice(startIndex, endIndex).map((line) => line.slice(commonIndent)).join("\n");
|
|
997
887
|
};
|
|
998
|
-
if ((
|
|
888
|
+
if ((isBoolean(params[0]) || params[0] === void 0) && (isBoolean(params[1]) || params[1] === void 0)) {
|
|
999
889
|
trimStart = params[0] !== false;
|
|
1000
890
|
trimEnd = params[1] !== false;
|
|
1001
891
|
return unindentImpl;
|
|
1002
892
|
}
|
|
1003
|
-
if (
|
|
893
|
+
if (isString$1(params[0]) || isArray(params[0])) return unindentImpl(...params);
|
|
1004
894
|
throw new TypeError(`First parameter has an invalid type: "${typeof params[0]}"`);
|
|
1005
|
-
}
|
|
1006
|
-
|
|
1007
|
-
* @example
|
|
1008
|
-
* ```ts
|
|
1009
|
-
* // Using indent count with default space character
|
|
1010
|
-
* const str1 = indent(2)`
|
|
1011
|
-
* if (a) {
|
|
1012
|
-
* b()
|
|
1013
|
-
* }
|
|
1014
|
-
* `;
|
|
1015
|
-
*
|
|
1016
|
-
* // Using custom indent string directly
|
|
1017
|
-
* const str2 = indent(">>")`
|
|
1018
|
-
* if (a) {
|
|
1019
|
-
* b()
|
|
1020
|
-
* }
|
|
1021
|
-
* `;
|
|
1022
|
-
*
|
|
1023
|
-
* // Only trim start, keep end
|
|
1024
|
-
* const str3 = indent(2, true, false)("hello\nworld\n");
|
|
1025
|
-
* ```
|
|
1026
|
-
*/
|
|
1027
|
-
const indent = (...params) => {
|
|
895
|
+
}
|
|
896
|
+
function indent(...params) {
|
|
1028
897
|
let indentString;
|
|
1029
898
|
let trimStart = true;
|
|
1030
899
|
let trimEnd = true;
|
|
1031
|
-
const indentImpl = (...params
|
|
1032
|
-
const lines = splitByLineBreak(
|
|
900
|
+
const indentImpl = (...params) => {
|
|
901
|
+
const lines = splitByLineBreak(isString$1(params[0]) ? params[0] : concatTemplateStrings(params[0], params.slice(1)));
|
|
1033
902
|
const whitespaceLines = lines.map((line) => REGEXP_WHITESPACE_ONLY.test(line));
|
|
1034
903
|
let startIndex = 0;
|
|
1035
904
|
let endIndex = lines.length;
|
|
@@ -1039,39 +908,38 @@ const indent = (...params) => {
|
|
|
1039
908
|
return whitespaceLines[index + startIndex] ? line : indentString + line;
|
|
1040
909
|
}).join("\n");
|
|
1041
910
|
};
|
|
1042
|
-
if ((
|
|
911
|
+
if ((isBoolean(params[1]) || params[1] === void 0) && (isBoolean(params[2]) || params[2] === void 0)) {
|
|
1043
912
|
trimStart = params[1] !== false;
|
|
1044
913
|
trimEnd = params[2] !== false;
|
|
1045
914
|
}
|
|
1046
|
-
if (
|
|
915
|
+
if (isNumber(params[0])) {
|
|
1047
916
|
indentString = " ".repeat(params[0]);
|
|
1048
917
|
return indentImpl;
|
|
1049
918
|
}
|
|
1050
|
-
if (
|
|
919
|
+
if (isString$1(params[0])) {
|
|
1051
920
|
indentString = params[0];
|
|
1052
921
|
return indentImpl;
|
|
1053
922
|
}
|
|
1054
923
|
throw new TypeError(`First parameter has an invalid type: "${typeof params[0]}"`);
|
|
1055
|
-
}
|
|
924
|
+
}
|
|
1056
925
|
function template(str, ...args) {
|
|
1057
926
|
const [firstArg, fallback] = args;
|
|
1058
|
-
if (
|
|
927
|
+
if (isPlainObject(firstArg)) {
|
|
1059
928
|
const mapping = firstArg;
|
|
1060
|
-
return str.replace(/\{(\w+)\}/g, (_, key) => mapping[key] || ((isFunction(fallback) ? fallback(key) : fallback) ?? key));
|
|
929
|
+
return str.replace(/\{(\w+)\}/g, (_, key) => mapping[key] || ((isFunction$1(fallback) ? fallback(key) : fallback) ?? key));
|
|
1061
930
|
} else return str.replace(/\{(\d+)\}/g, (_, key) => {
|
|
1062
931
|
const index = Number(key);
|
|
1063
932
|
if (Number.isNaN(index)) return key;
|
|
1064
933
|
return args[index];
|
|
1065
934
|
});
|
|
1066
935
|
}
|
|
1067
|
-
|
|
1068
936
|
//#endregion
|
|
1069
937
|
//#region src/common/throttle.ts
|
|
1070
938
|
const wrap = (fn, wait, options) => {
|
|
1071
939
|
const { leading, trailing } = options;
|
|
1072
940
|
let timerId;
|
|
1073
941
|
const wrapped = (...args) => {
|
|
1074
|
-
if (
|
|
942
|
+
if (isNonNullish(timerId)) return;
|
|
1075
943
|
timerId = globalThis.setTimeout(() => {
|
|
1076
944
|
timerId = void 0;
|
|
1077
945
|
trailing && fn(...args);
|
|
@@ -1079,7 +947,7 @@ const wrap = (fn, wait, options) => {
|
|
|
1079
947
|
leading && fn(...args);
|
|
1080
948
|
};
|
|
1081
949
|
wrapped.cancel = () => {
|
|
1082
|
-
if (
|
|
950
|
+
if (isNonNullish(timerId)) globalThis.clearTimeout(timerId);
|
|
1083
951
|
timerId = void 0;
|
|
1084
952
|
};
|
|
1085
953
|
return wrapped;
|
|
@@ -1098,6 +966,5 @@ const throttle = (fn, wait = 0, options = {}) => {
|
|
|
1098
966
|
trailing
|
|
1099
967
|
});
|
|
1100
968
|
};
|
|
1101
|
-
|
|
1102
969
|
//#endregion
|
|
1103
|
-
export {
|
|
970
|
+
export { differenceBy as $, pipe as $n, toIterator as $r, isArray as $t, accumulateP as A, mapValues as An, splice as Ar, flatMapP as At, chunkP as B, objOf as Bn, swapProps as Br, groupBy as Bt, isNil as C, isResult as Ci, keys as Cn, sort as Cr, findLast as Ct, getErrorMessage as D, mapKeys as Dn, sortedIndexWith as Dr, firstBy as Dt, scale as E, stableStringify as Ei, map as En, sortedIndexBy as Er, first as Et, awaitAll as F, merge as Fn, stringToPath as Fr, forEachObj as Ft, concatP as G, partialBind as Gn, takeP as Gr, indexBy as Gt, clone as H, omitBy as Hn, takeFirstBy as Hr, hasAtLeast as Ht, buffer as I, mergeAll as In, subtract as Ir, forEachP as It, constant as J, pathOr as Jn, throttle$1 as Jr, intersectionByP as Jt, concurrency as K, partialLastBind as Kn, takeWhile as Kr, intersection as Kt, capitalize as L, mergeDeep as Ln, sum as Lr, fromEntries as Lt, addProp as M, mean as Mn, splitAt as Mr, flattenP as Mt, allPass as N, meanBy as Nn, splitWhen as Nr, floor as Nt, normalizeError as O, mapP as On, sortedLastIndex as Or, flat as Ot, anyPass as P, median as Pn, startsWith as Pr, forEach as Pt, difference as Q, pickBy as Qn, toCamelCase as Qr, invert as Qt, ceil as R, multiply as Rn, sumBy as Rr, fromKeys as Rt, parseValueToBoolean as S, err as Si, join$1 as Sn, someP as Sr, findIndex as St, linear as T, ResultError as Ti, length as Tn, sortedIndex as Tr, findP as Tt, compose as U, once as Un, takeLast as Ur, hasSubObject as Ut, clamp as V, omit as Vn, take as Vr, groupByProp as Vt, concat as W, only as Wn, takeLastWhile as Wr, identity as Wt, debounce$1 as X, peekP as Xn, toArray as Xr, intersectionWith as Xt, countBy as Y, peek as Yn, times as Yr, intersectionP as Yt, defaultTo as Z, pick as Zn, toArrayP as Zr, intersectionWithP as Zt, createLock as _, zipWith as _i, isShallowEqual as _n, set as _r, execute as _t, concatTemplateStrings as a, toUpperCase as ai, isEmpty as an, randomBigInt as ar, doNothing as at, sleep as b, hasOwnProperty as bi, isSymbol as bn, sliceString as br, filterP as bt, joinWithSlash as c, unique as ci, isIncludedIn as cn, range as cr, dropLast as ct, split as d, uniqueP as di, isNot as dn, reduceP as dr, dropWhile as dt, toIteratorP as ei, isBigInt as en, piped as er, differenceByP as et, splitByLineBreak as f, uniqueWith as fi, isNullish as fn, reverse as fr, endsWith as ft, unindent as g, zip as gi, isPromise as gn, serializeP as gr, evolve as gt, toForwardSlash as h, when as hi, isPlainObject as hn, serialize as hr, everyP as ht, addSuffix as i, toTitleCase as ii, isDefined as in, purry$1 as ir, divide as it, add as j, mapWithFeedback as jn, split$1 as jr, flatten as jt, accumulate as k, mapToObj as kn, sortedLastIndexBy as kr, flatMap as kt, removePrefix as l, uniqueBy as li, isNonNull as ln, rankBy as lr, dropLastWhile as lt, template as m, values as mi, isObjectType$1 as mn, sample as mr, every as mt, throttle as n, toLowerCase as ni, isDate as nn, prop as nr, differenceWith as nt, indent as o, truncate as oi, isEmptyish as on, randomInteger as or, drop as ot, splitWithSlash as p, uniqueWithP as pi, isNumber as pn, round as pr, entries as pt, conditional as q, partition as qn, tap as qr, intersectionBy as qt, addPrefix as r, toSnakeCase as ri, isDeepEqual as rn, pullObject as rr, differenceWithP as rt, join as s, uncapitalize as si, isError as sn, randomString as sr, dropFirstBy as st, debounce as t, toKebabCase as ti, isBoolean as tn, product as tr, differenceP as tt, removeSuffix as u, uniqueByP as ui, isNonNullish as un, reduce as ur, dropP as ut, createPromiseWithResolvers as v, isPromiseLike as vi, isStrictEqual as vn, setPath as vr, executeP as vt, nil as w, ok as wi, last as wn, sortBy as wr, findLastIndex as wt, parseKeyValuePairs as x, Result as xi, isTruthy as xn, some as xr, find as xt, createSingleton as y, isFunction$1 as yi, isString$1 as yn, shuffle as yr, filter as yt, chunk as z, nthBy as zn, swapIndices as zr, funnel as zt };
|