@ls-stack/utils 3.65.0 → 3.67.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/dist/{arrayUtils.d.cts → arrayUtils.d.mts} +24 -23
- package/dist/arrayUtils.mjs +249 -0
- package/dist/assertions-qMxfVhSu.mjs +207 -0
- package/dist/{assertions.d.ts → assertions.d.mts} +4 -3
- package/dist/assertions.mjs +3 -0
- package/dist/asyncQueue.d.mts +497 -0
- package/dist/asyncQueue.mjs +757 -0
- package/dist/{awaitDebounce.d.cts → awaitDebounce.d.mts} +11 -6
- package/dist/awaitDebounce.mjs +54 -0
- package/dist/{cache.d.ts → cache.d.mts} +76 -68
- package/dist/cache.mjs +355 -0
- package/dist/castValues-DfICShCc.mjs +19 -0
- package/dist/{castValues.d.cts → castValues.d.mts} +3 -2
- package/dist/castValues.mjs +3 -0
- package/dist/{concurrentCalls.d.ts → concurrentCalls.d.mts} +74 -65
- package/dist/concurrentCalls.mjs +295 -0
- package/dist/consoleFmt.d.mts +55 -0
- package/dist/consoleFmt.mjs +63 -0
- package/dist/conversions-DTmwEMIu.mjs +12 -0
- package/dist/conversions.d.mts +4 -0
- package/dist/conversions.mjs +3 -0
- package/dist/createThrottleController.d.mts +18 -0
- package/dist/createThrottleController.mjs +40 -0
- package/dist/debounce.d.mts +47 -0
- package/dist/debounce.mjs +117 -0
- package/dist/dedent.d.mts +74 -0
- package/dist/dedent.mjs +80 -0
- package/dist/deepEqual-C7EZEixx.mjs +78 -0
- package/dist/{deepEqual.d.cts → deepEqual.d.mts} +3 -2
- package/dist/deepEqual.mjs +3 -0
- package/dist/{deepReplaceValues.d.cts → deepReplaceValues.d.mts} +4 -3
- package/dist/deepReplaceValues.mjs +61 -0
- package/dist/diffParser.d.mts +79 -0
- package/dist/diffParser.mjs +424 -0
- package/dist/enhancedMap.d.mts +21 -0
- package/dist/enhancedMap.mjs +69 -0
- package/dist/exhaustiveMatch.d.mts +10 -0
- package/dist/exhaustiveMatch.mjs +48 -0
- package/dist/{filterObjectOrArrayKeys.d.cts → filterObjectOrArrayKeys.d.mts} +15 -8
- package/dist/filterObjectOrArrayKeys.mjs +497 -0
- package/dist/{getAutoIncrementId.d.cts → getAutoIncrementId.d.mts} +9 -5
- package/dist/getAutoIncrementId.mjs +53 -0
- package/dist/{getCompositeKey.d.cts → getCompositeKey.d.mts} +3 -2
- package/dist/getCompositeKey.mjs +50 -0
- package/dist/{getValueStableKey.d.cts → getValueStableKey.d.mts} +5 -3
- package/dist/getValueStableKey.mjs +17 -0
- package/dist/{hash.d.cts → hash.d.mts} +3 -2
- package/dist/hash.mjs +28 -0
- package/dist/interpolate.d.mts +17 -0
- package/dist/interpolate.mjs +28 -0
- package/dist/{iteratorUtils.d.cts → iteratorUtils.d.mts} +5 -4
- package/dist/iteratorUtils.mjs +39 -0
- package/dist/keepPrevIfUnchanged.d.mts +12 -0
- package/dist/keepPrevIfUnchanged.mjs +9 -0
- package/dist/keyedMap.d.mts +76 -0
- package/dist/keyedMap.mjs +139 -0
- package/dist/keyedSet.d.mts +77 -0
- package/dist/keyedSet.mjs +129 -0
- package/dist/{levenshtein.d.cts → levenshtein.d.mts} +3 -2
- package/dist/levenshtein.mjs +121 -0
- package/dist/main.d.mts +4 -0
- package/dist/main.mjs +7 -0
- package/dist/matchPath.d.mts +50 -0
- package/dist/matchPath.mjs +81 -0
- package/dist/mathUtils-BDP1lM_z.mjs +81 -0
- package/dist/{mathUtils.d.cts → mathUtils.d.mts} +3 -2
- package/dist/mathUtils.mjs +3 -0
- package/dist/{mutationUtils.d.cts → mutationUtils.d.mts} +6 -5
- package/dist/mutationUtils.mjs +44 -0
- package/dist/{objUtils.d.ts → objUtils.d.mts} +8 -6
- package/dist/objUtils.mjs +115 -0
- package/dist/parallelAsyncCalls.d.mts +83 -0
- package/dist/parallelAsyncCalls.mjs +121 -0
- package/dist/partialEqual.d.mts +139 -0
- package/dist/partialEqual.mjs +1055 -0
- package/dist/promiseUtils.d.mts +9 -0
- package/dist/promiseUtils.mjs +17 -0
- package/dist/regexUtils.d.mts +18 -0
- package/dist/regexUtils.mjs +34 -0
- package/dist/{retryOnError.d.cts → retryOnError.d.mts} +38 -37
- package/dist/retryOnError.mjs +91 -0
- package/dist/{runShellCmd.d.ts → runShellCmd.d.mts} +24 -15
- package/dist/runShellCmd.mjs +151 -0
- package/dist/{safeJson.d.cts → safeJson.d.mts} +3 -2
- package/dist/safeJson.mjs +30 -0
- package/dist/{saferTyping.d.cts → saferTyping.d.mts} +4 -3
- package/dist/saferTyping.mjs +45 -0
- package/dist/serializeXML.d.mts +23 -0
- package/dist/serializeXML.mjs +74 -0
- package/dist/{shallowEqual.d.cts → shallowEqual.d.mts} +3 -2
- package/dist/shallowEqual.mjs +54 -0
- package/dist/sleep.d.mts +4 -0
- package/dist/sleep.mjs +7 -0
- package/dist/stringUtils-DjhWOiYn.mjs +113 -0
- package/dist/{stringUtils.d.cts → stringUtils.d.mts} +3 -2
- package/dist/stringUtils.mjs +3 -0
- package/dist/{testUtils.d.ts → testUtils.d.mts} +83 -52
- package/dist/testUtils.mjs +310 -0
- package/dist/{throttle.d.ts → throttle.d.mts} +18 -17
- package/dist/throttle.mjs +102 -0
- package/dist/time-sr2lhQRw.mjs +67 -0
- package/dist/{time.d.ts → time.d.mts} +8 -7
- package/dist/time.mjs +3 -0
- package/dist/{timers.d.cts → timers.d.mts} +22 -13
- package/dist/timers.mjs +220 -0
- package/dist/{tsResult.d.cts → tsResult.d.mts} +52 -48
- package/dist/tsResult.mjs +142 -0
- package/dist/typeGuards-B1mzA-Rz.mjs +128 -0
- package/dist/{typeGuards.d.cts → typeGuards.d.mts} +3 -2
- package/dist/typeGuards.mjs +3 -0
- package/dist/{typeUtils.d.ts → typeUtils.d.mts} +13 -34
- package/dist/typeUtils.mjs +1 -0
- package/dist/{typedStrings.d.cts → typedStrings.d.mts} +5 -4
- package/dist/typedStrings.mjs +131 -0
- package/dist/typingFnUtils-Bb8drgKF.mjs +101 -0
- package/dist/{typingFnUtils.d.cts → typingFnUtils.d.mts} +13 -22
- package/dist/typingFnUtils.mjs +3 -0
- package/dist/{typingTestUtils.d.cts → typingTestUtils.d.mts} +11 -15
- package/dist/typingTestUtils.mjs +80 -0
- package/dist/typingUtils.d.mts +20 -0
- package/dist/typingUtils.mjs +1 -0
- package/dist/yamlStringify.d.mts +17 -0
- package/dist/yamlStringify.mjs +189 -0
- package/package.json +65 -242
- package/dist/arrayUtils.cjs +0 -229
- package/dist/arrayUtils.d.ts +0 -171
- package/dist/arrayUtils.js +0 -42
- package/dist/assertions.cjs +0 -107
- package/dist/assertions.d.cts +0 -192
- package/dist/assertions.js +0 -25
- package/dist/asyncQueue.cjs +0 -672
- package/dist/asyncQueue.d.cts +0 -488
- package/dist/asyncQueue.d.ts +0 -488
- package/dist/asyncQueue.js +0 -631
- package/dist/awaitDebounce.cjs +0 -106
- package/dist/awaitDebounce.d.ts +0 -41
- package/dist/awaitDebounce.js +0 -28
- package/dist/cache.cjs +0 -367
- package/dist/cache.d.cts +0 -228
- package/dist/cache.js +0 -19
- package/dist/castValues.cjs +0 -50
- package/dist/castValues.d.ts +0 -4
- package/dist/castValues.js +0 -8
- package/dist/chunk-5DZT3Z5Z.js +0 -8
- package/dist/chunk-6FBIEPWU.js +0 -96
- package/dist/chunk-6FIBVC2P.js +0 -56
- package/dist/chunk-7CQPOM5I.js +0 -100
- package/dist/chunk-B6DNOZCP.js +0 -369
- package/dist/chunk-BM4PYVOX.js +0 -109
- package/dist/chunk-C2SVCIWE.js +0 -57
- package/dist/chunk-CCUPDGSZ.js +0 -132
- package/dist/chunk-DBOWTYR4.js +0 -49
- package/dist/chunk-DFXNVEH6.js +0 -14
- package/dist/chunk-DX2524CZ.js +0 -314
- package/dist/chunk-GMJTLFM6.js +0 -60
- package/dist/chunk-IATIXMCE.js +0 -20
- package/dist/chunk-II4R3VVX.js +0 -25
- package/dist/chunk-JF2MDHOJ.js +0 -40
- package/dist/chunk-JQFUKJU5.js +0 -71
- package/dist/chunk-MI4UE2PQ.js +0 -561
- package/dist/chunk-PUKVXYYL.js +0 -52
- package/dist/chunk-QQS7I7ZL.js +0 -16
- package/dist/chunk-VAAMRG4K.js +0 -20
- package/dist/chunk-WFQJUJTC.js +0 -182
- package/dist/chunk-ZXIKIA5B.js +0 -178
- package/dist/concurrentCalls.cjs +0 -406
- package/dist/concurrentCalls.d.cts +0 -116
- package/dist/concurrentCalls.js +0 -346
- package/dist/consoleFmt.cjs +0 -85
- package/dist/consoleFmt.d.cts +0 -54
- package/dist/consoleFmt.d.ts +0 -54
- package/dist/consoleFmt.js +0 -60
- package/dist/conversions.cjs +0 -44
- package/dist/conversions.d.cts +0 -3
- package/dist/conversions.d.ts +0 -3
- package/dist/conversions.js +0 -6
- package/dist/createThrottleController.cjs +0 -193
- package/dist/createThrottleController.d.cts +0 -13
- package/dist/createThrottleController.d.ts +0 -13
- package/dist/createThrottleController.js +0 -61
- package/dist/debounce.cjs +0 -157
- package/dist/debounce.d.cts +0 -46
- package/dist/debounce.d.ts +0 -46
- package/dist/debounce.js +0 -8
- package/dist/dedent.cjs +0 -104
- package/dist/dedent.d.cts +0 -73
- package/dist/dedent.d.ts +0 -73
- package/dist/dedent.js +0 -79
- package/dist/deepEqual.cjs +0 -96
- package/dist/deepEqual.d.ts +0 -21
- package/dist/deepEqual.js +0 -8
- package/dist/deepReplaceValues.cjs +0 -87
- package/dist/deepReplaceValues.d.ts +0 -27
- package/dist/deepReplaceValues.js +0 -7
- package/dist/enhancedMap.cjs +0 -131
- package/dist/enhancedMap.d.cts +0 -20
- package/dist/enhancedMap.d.ts +0 -20
- package/dist/enhancedMap.js +0 -10
- package/dist/exhaustiveMatch.cjs +0 -66
- package/dist/exhaustiveMatch.d.cts +0 -9
- package/dist/exhaustiveMatch.d.ts +0 -9
- package/dist/exhaustiveMatch.js +0 -40
- package/dist/filterObjectOrArrayKeys.cjs +0 -619
- package/dist/filterObjectOrArrayKeys.d.ts +0 -88
- package/dist/filterObjectOrArrayKeys.js +0 -9
- package/dist/getAutoIncrementId.cjs +0 -44
- package/dist/getAutoIncrementId.d.ts +0 -46
- package/dist/getAutoIncrementId.js +0 -18
- package/dist/getCompositeKey.cjs +0 -86
- package/dist/getCompositeKey.d.ts +0 -11
- package/dist/getCompositeKey.js +0 -8
- package/dist/getValueStableKey.cjs +0 -89
- package/dist/getValueStableKey.d.ts +0 -15
- package/dist/getValueStableKey.js +0 -11
- package/dist/hash.cjs +0 -57
- package/dist/hash.d.ts +0 -7
- package/dist/hash.js +0 -32
- package/dist/interpolate.cjs +0 -88
- package/dist/interpolate.d.cts +0 -11
- package/dist/interpolate.d.ts +0 -11
- package/dist/interpolate.js +0 -46
- package/dist/iteratorUtils.cjs +0 -73
- package/dist/iteratorUtils.d.ts +0 -10
- package/dist/iteratorUtils.js +0 -44
- package/dist/keepPrevIfUnchanged.cjs +0 -102
- package/dist/keepPrevIfUnchanged.d.cts +0 -7
- package/dist/keepPrevIfUnchanged.d.ts +0 -7
- package/dist/keepPrevIfUnchanged.js +0 -7
- package/dist/keyedMap.cjs +0 -224
- package/dist/keyedMap.d.cts +0 -75
- package/dist/keyedMap.d.ts +0 -75
- package/dist/keyedMap.js +0 -145
- package/dist/keyedSet.cjs +0 -205
- package/dist/keyedSet.d.cts +0 -76
- package/dist/keyedSet.d.ts +0 -76
- package/dist/keyedSet.js +0 -126
- package/dist/levenshtein.cjs +0 -180
- package/dist/levenshtein.d.ts +0 -5
- package/dist/levenshtein.js +0 -153
- package/dist/main.cjs +0 -32
- package/dist/main.d.cts +0 -3
- package/dist/main.d.ts +0 -3
- package/dist/main.js +0 -7
- package/dist/matchPath.cjs +0 -155
- package/dist/matchPath.d.cts +0 -53
- package/dist/matchPath.d.ts +0 -53
- package/dist/matchPath.js +0 -108
- package/dist/mathUtils.cjs +0 -81
- package/dist/mathUtils.d.ts +0 -54
- package/dist/mathUtils.js +0 -22
- package/dist/mutationUtils.cjs +0 -153
- package/dist/mutationUtils.d.ts +0 -15
- package/dist/mutationUtils.js +0 -55
- package/dist/objUtils.cjs +0 -242
- package/dist/objUtils.d.cts +0 -28
- package/dist/objUtils.js +0 -38
- package/dist/parallelAsyncCalls.cjs +0 -162
- package/dist/parallelAsyncCalls.d.cts +0 -82
- package/dist/parallelAsyncCalls.d.ts +0 -82
- package/dist/parallelAsyncCalls.js +0 -126
- package/dist/partialEqual.cjs +0 -1196
- package/dist/partialEqual.d.cts +0 -141
- package/dist/partialEqual.d.ts +0 -141
- package/dist/partialEqual.js +0 -1168
- package/dist/promiseUtils.cjs +0 -38
- package/dist/promiseUtils.d.cts +0 -8
- package/dist/promiseUtils.d.ts +0 -8
- package/dist/promiseUtils.js +0 -6
- package/dist/regexUtils.cjs +0 -60
- package/dist/regexUtils.d.cts +0 -17
- package/dist/regexUtils.d.ts +0 -17
- package/dist/regexUtils.js +0 -33
- package/dist/retryOnError.cjs +0 -130
- package/dist/retryOnError.d.ts +0 -83
- package/dist/retryOnError.js +0 -101
- package/dist/runShellCmd.cjs +0 -127
- package/dist/runShellCmd.d.cts +0 -90
- package/dist/runShellCmd.js +0 -98
- package/dist/safeJson.cjs +0 -45
- package/dist/safeJson.d.ts +0 -16
- package/dist/safeJson.js +0 -8
- package/dist/saferTyping.cjs +0 -52
- package/dist/saferTyping.d.ts +0 -47
- package/dist/saferTyping.js +0 -23
- package/dist/serializeXML.cjs +0 -154
- package/dist/serializeXML.d.cts +0 -22
- package/dist/serializeXML.d.ts +0 -22
- package/dist/serializeXML.js +0 -116
- package/dist/shallowEqual.cjs +0 -88
- package/dist/shallowEqual.d.ts +0 -4
- package/dist/shallowEqual.js +0 -63
- package/dist/sleep.cjs +0 -32
- package/dist/sleep.d.cts +0 -3
- package/dist/sleep.d.ts +0 -3
- package/dist/sleep.js +0 -6
- package/dist/stringUtils.cjs +0 -155
- package/dist/stringUtils.d.ts +0 -55
- package/dist/stringUtils.js +0 -50
- package/dist/testUtils.cjs +0 -1490
- package/dist/testUtils.d.cts +0 -133
- package/dist/testUtils.js +0 -359
- package/dist/throttle.cjs +0 -282
- package/dist/throttle.d.cts +0 -98
- package/dist/throttle.js +0 -38
- package/dist/time.cjs +0 -152
- package/dist/time.d.cts +0 -25
- package/dist/time.js +0 -38
- package/dist/timers.cjs +0 -194
- package/dist/timers.d.ts +0 -121
- package/dist/timers.js +0 -156
- package/dist/tsResult.cjs +0 -226
- package/dist/tsResult.d.ts +0 -114
- package/dist/tsResult.js +0 -180
- package/dist/typeGuards.cjs +0 -70
- package/dist/typeGuards.d.ts +0 -111
- package/dist/typeGuards.js +0 -18
- package/dist/typeUtils.cjs +0 -18
- package/dist/typeUtils.d.cts +0 -61
- package/dist/typeUtils.js +0 -0
- package/dist/typedStrings.cjs +0 -90
- package/dist/typedStrings.d.ts +0 -163
- package/dist/typedStrings.js +0 -57
- package/dist/typingFnUtils.cjs +0 -96
- package/dist/typingFnUtils.d.ts +0 -100
- package/dist/typingFnUtils.js +0 -30
- package/dist/typingTestUtils.cjs +0 -52
- package/dist/typingTestUtils.d.ts +0 -79
- package/dist/typingTestUtils.js +0 -27
- package/dist/typingUtils.cjs +0 -18
- package/dist/typingUtils.d.cts +0 -35
- package/dist/typingUtils.d.ts +0 -35
- package/dist/typingUtils.js +0 -0
- package/dist/yamlStringify.cjs +0 -423
- package/dist/yamlStringify.d.cts +0 -10
- package/dist/yamlStringify.d.ts +0 -10
- package/dist/yamlStringify.js +0 -9
package/dist/testUtils.cjs
DELETED
|
@@ -1,1490 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/testUtils.ts
|
|
21
|
-
var testUtils_exports = {};
|
|
22
|
-
__export(testUtils_exports, {
|
|
23
|
-
compactSnapshot: () => compactSnapshot,
|
|
24
|
-
createLoggerStore: () => createLoggerStore,
|
|
25
|
-
getResultFn: () => getResultFn,
|
|
26
|
-
waitController: () => waitController
|
|
27
|
-
});
|
|
28
|
-
module.exports = __toCommonJS(testUtils_exports);
|
|
29
|
-
|
|
30
|
-
// src/typeGuards.ts
|
|
31
|
-
function isObject(value) {
|
|
32
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
33
|
-
}
|
|
34
|
-
function isPlainObject(value) {
|
|
35
|
-
if (!value || typeof value !== "object") return false;
|
|
36
|
-
const proto = Object.getPrototypeOf(value);
|
|
37
|
-
if (proto === null) {
|
|
38
|
-
return true;
|
|
39
|
-
}
|
|
40
|
-
const Ctor = Object.hasOwnProperty.call(proto, "constructor") && proto.constructor;
|
|
41
|
-
if (Ctor === Object) return true;
|
|
42
|
-
const objectCtorString = Object.prototype.constructor.toString();
|
|
43
|
-
return typeof Ctor == "function" && Function.toString.call(Ctor) === objectCtorString;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// src/assertions.ts
|
|
47
|
-
var isObject2 = isObject;
|
|
48
|
-
|
|
49
|
-
// src/arrayUtils.ts
|
|
50
|
-
function filterAndMap(array, mapFilter) {
|
|
51
|
-
const result = [];
|
|
52
|
-
let i = -1;
|
|
53
|
-
for (const item of array) {
|
|
54
|
-
i += 1;
|
|
55
|
-
const filterResult = mapFilter(item, i);
|
|
56
|
-
if (filterResult !== false) {
|
|
57
|
-
result.push(filterResult);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
return result;
|
|
61
|
-
}
|
|
62
|
-
function sortBy(arr, sortByValue, props = "asc") {
|
|
63
|
-
const order = Array.isArray(props) || typeof props === "string" ? props : props.order ?? "asc";
|
|
64
|
-
return [...arr].sort((a, b) => {
|
|
65
|
-
const _aPriority = sortByValue(a);
|
|
66
|
-
const _bPriority = sortByValue(b);
|
|
67
|
-
const aPriority = Array.isArray(_aPriority) ? _aPriority : [_aPriority];
|
|
68
|
-
const bPriority = Array.isArray(_bPriority) ? _bPriority : [_bPriority];
|
|
69
|
-
for (let i = 0; i < aPriority.length; i++) {
|
|
70
|
-
const levelOrder = typeof order === "string" ? order : order[i] ?? "asc";
|
|
71
|
-
const aP = aPriority[i] ?? 0;
|
|
72
|
-
const bP = bPriority[i] ?? 0;
|
|
73
|
-
if (aP === bP) {
|
|
74
|
-
continue;
|
|
75
|
-
}
|
|
76
|
-
if (bP === Infinity || aP === -Infinity || aP < bP) {
|
|
77
|
-
return levelOrder === "asc" ? -1 : 1;
|
|
78
|
-
}
|
|
79
|
-
if (aP === Infinity || bP === -Infinity || aP > bP) {
|
|
80
|
-
return levelOrder === "asc" ? 1 : -1;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
return 0;
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
function arrayWithPrevAndIndex(array) {
|
|
87
|
-
return array.map((item, i) => ({
|
|
88
|
-
item,
|
|
89
|
-
prev: array[i - 1] ?? null,
|
|
90
|
-
index: i
|
|
91
|
-
}));
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
// src/deepEqual.ts
|
|
95
|
-
var has = Object.prototype.hasOwnProperty;
|
|
96
|
-
function find(iter, tar, maxDepth) {
|
|
97
|
-
for (const key of iter.keys()) {
|
|
98
|
-
if (deepEqual(key, tar, maxDepth)) return key;
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
function deepEqual(foo, bar, maxDepth = 20) {
|
|
102
|
-
let ctor, len, tmp;
|
|
103
|
-
if (foo === bar) return true;
|
|
104
|
-
if (maxDepth && maxDepth <= 0) return false;
|
|
105
|
-
if (foo && bar && (ctor = foo.constructor) === bar.constructor) {
|
|
106
|
-
if (ctor === Date)
|
|
107
|
-
return deepEqual(foo.getTime(), bar.getTime(), maxDepth - 1);
|
|
108
|
-
if (ctor === RegExp) return foo.toString() === bar.toString();
|
|
109
|
-
if (ctor === Array) {
|
|
110
|
-
if ((len = foo.length) === bar.length) {
|
|
111
|
-
while (len-- && deepEqual(foo[len], bar[len], maxDepth - 1)) ;
|
|
112
|
-
}
|
|
113
|
-
return len === -1;
|
|
114
|
-
}
|
|
115
|
-
if (ctor === Set) {
|
|
116
|
-
if (foo.size !== bar.size) {
|
|
117
|
-
return false;
|
|
118
|
-
}
|
|
119
|
-
for (len of foo) {
|
|
120
|
-
tmp = len;
|
|
121
|
-
if (tmp && typeof tmp === "object") {
|
|
122
|
-
tmp = find(bar, tmp, maxDepth - 1);
|
|
123
|
-
if (!tmp) return false;
|
|
124
|
-
}
|
|
125
|
-
if (!bar.has(tmp)) return false;
|
|
126
|
-
}
|
|
127
|
-
return true;
|
|
128
|
-
}
|
|
129
|
-
if (ctor === Map) {
|
|
130
|
-
if (foo.size !== bar.size) {
|
|
131
|
-
return false;
|
|
132
|
-
}
|
|
133
|
-
for (len of foo) {
|
|
134
|
-
tmp = len[0];
|
|
135
|
-
if (tmp && typeof tmp === "object") {
|
|
136
|
-
tmp = find(bar, tmp, maxDepth - 1);
|
|
137
|
-
if (!tmp) return false;
|
|
138
|
-
}
|
|
139
|
-
if (!deepEqual(len[1], bar.get(tmp), maxDepth - 1)) {
|
|
140
|
-
return false;
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
return true;
|
|
144
|
-
}
|
|
145
|
-
if (!ctor || typeof foo === "object") {
|
|
146
|
-
len = 0;
|
|
147
|
-
for (ctor in foo) {
|
|
148
|
-
if (has.call(foo, ctor) && ++len && !has.call(bar, ctor)) return false;
|
|
149
|
-
if (!(ctor in bar) || !deepEqual(foo[ctor], bar[ctor], maxDepth - 1))
|
|
150
|
-
return false;
|
|
151
|
-
}
|
|
152
|
-
return Object.keys(bar).length === len;
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
return foo !== foo && bar !== bar;
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
// src/deepReplaceValues.ts
|
|
159
|
-
function applyValueReplacements(value, replaceValues, visited, currentPath) {
|
|
160
|
-
function processValue(val, path) {
|
|
161
|
-
const replacement = replaceValues(val, path);
|
|
162
|
-
if (replacement !== false) {
|
|
163
|
-
return replacement.newValue;
|
|
164
|
-
}
|
|
165
|
-
if (Array.isArray(val)) {
|
|
166
|
-
if (visited.has(val)) {
|
|
167
|
-
throw new Error("Circular reference detected in array");
|
|
168
|
-
}
|
|
169
|
-
visited.add(val);
|
|
170
|
-
try {
|
|
171
|
-
return val.map((item, index) => {
|
|
172
|
-
const itemPath = path ? `${path}[${index}]` : `[${index}]`;
|
|
173
|
-
return processValue(item, itemPath);
|
|
174
|
-
});
|
|
175
|
-
} finally {
|
|
176
|
-
visited.delete(val);
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
if (isPlainObject(val)) {
|
|
180
|
-
if (visited.has(val)) {
|
|
181
|
-
throw new Error("Circular reference detected in object");
|
|
182
|
-
}
|
|
183
|
-
visited.add(val);
|
|
184
|
-
try {
|
|
185
|
-
const result = {};
|
|
186
|
-
for (const [key, itemValue] of Object.entries(val)) {
|
|
187
|
-
const itemPath = path ? `${path}.${key}` : key;
|
|
188
|
-
result[key] = processValue(itemValue, itemPath);
|
|
189
|
-
}
|
|
190
|
-
return result;
|
|
191
|
-
} finally {
|
|
192
|
-
visited.delete(val);
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
return val;
|
|
196
|
-
}
|
|
197
|
-
return processValue(value, currentPath);
|
|
198
|
-
}
|
|
199
|
-
function deepReplaceValues(value, replaceValues) {
|
|
200
|
-
return applyValueReplacements(value, replaceValues, /* @__PURE__ */ new Set(), "");
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
// src/filterObjectOrArrayKeys.ts
|
|
204
|
-
var ID_PROP_REGEXP = /^(id_|key_|id-|key-)|(_id|_key|-id|-key)$/i;
|
|
205
|
-
function filterObjectOrArrayKeys(objOrArray, {
|
|
206
|
-
filterKeys,
|
|
207
|
-
rejectKeys,
|
|
208
|
-
rejectEmptyObjectsInArray = true,
|
|
209
|
-
sortKeys = "simpleValuesFirst",
|
|
210
|
-
sortPatterns
|
|
211
|
-
}) {
|
|
212
|
-
function getNestedValue(obj, path) {
|
|
213
|
-
const parts = path.split(".");
|
|
214
|
-
let current = obj;
|
|
215
|
-
for (const part of parts) {
|
|
216
|
-
if (current == null || typeof current !== "object") {
|
|
217
|
-
return void 0;
|
|
218
|
-
}
|
|
219
|
-
current = current[part];
|
|
220
|
-
}
|
|
221
|
-
return current;
|
|
222
|
-
}
|
|
223
|
-
function evaluateCondition(item, condition) {
|
|
224
|
-
const value = getNestedValue(item, condition.property);
|
|
225
|
-
let valueStr = String(value);
|
|
226
|
-
if (condition.caseInsensitive) {
|
|
227
|
-
valueStr = valueStr.toLowerCase();
|
|
228
|
-
}
|
|
229
|
-
const processValue = (v) => condition.caseInsensitive ? v.toLowerCase() : v;
|
|
230
|
-
switch (condition.operator) {
|
|
231
|
-
case "=":
|
|
232
|
-
return condition.values.some((v) => valueStr === processValue(v));
|
|
233
|
-
case "!=":
|
|
234
|
-
return condition.values.every((v) => valueStr !== processValue(v));
|
|
235
|
-
case "*=":
|
|
236
|
-
return condition.values.some((v) => valueStr.includes(processValue(v)));
|
|
237
|
-
case "!*=":
|
|
238
|
-
return condition.values.every(
|
|
239
|
-
(v) => !valueStr.includes(processValue(v))
|
|
240
|
-
);
|
|
241
|
-
case "^=":
|
|
242
|
-
return condition.values.some(
|
|
243
|
-
(v) => valueStr.startsWith(processValue(v))
|
|
244
|
-
);
|
|
245
|
-
case "!^=":
|
|
246
|
-
return condition.values.every(
|
|
247
|
-
(v) => !valueStr.startsWith(processValue(v))
|
|
248
|
-
);
|
|
249
|
-
case "$=":
|
|
250
|
-
return condition.values.some((v) => valueStr.endsWith(processValue(v)));
|
|
251
|
-
case "!$=":
|
|
252
|
-
return condition.values.every(
|
|
253
|
-
(v) => !valueStr.endsWith(processValue(v))
|
|
254
|
-
);
|
|
255
|
-
default:
|
|
256
|
-
return false;
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
const toArray = (v) => v === void 0 ? [] : Array.isArray(v) ? v : [v];
|
|
260
|
-
const filterPatternsRaw = toArray(filterKeys);
|
|
261
|
-
const rejectPatternsRaw = toArray(rejectKeys);
|
|
262
|
-
const hasFilters = filterPatternsRaw.length > 0;
|
|
263
|
-
const hasRejects = rejectPatternsRaw.length > 0;
|
|
264
|
-
const expandedFilterPatterns = filterPatternsRaw.flatMap(expandPatterns);
|
|
265
|
-
const expandedRejectPatterns = rejectPatternsRaw.flatMap(expandPatterns);
|
|
266
|
-
const { filterOnlyPatterns, combinedPatterns } = separateFilterPatterns(
|
|
267
|
-
expandedFilterPatterns
|
|
268
|
-
);
|
|
269
|
-
const filterPatterns = filterOnlyPatterns.map(parsePattern);
|
|
270
|
-
const rejectPatterns = expandedRejectPatterns.map(parsePattern);
|
|
271
|
-
const sortPatternsRaw = toArray(sortPatterns);
|
|
272
|
-
const expandedSortPatterns = sortPatternsRaw.flatMap(expandPatterns);
|
|
273
|
-
const sortPatternsParsed = expandedSortPatterns.map(parsePattern);
|
|
274
|
-
let dataToProcess = objOrArray;
|
|
275
|
-
if (combinedPatterns.length > 0) {
|
|
276
|
-
const groupedByFilter = /* @__PURE__ */ new Map();
|
|
277
|
-
for (const { filterPart, fieldPart } of combinedPatterns) {
|
|
278
|
-
if (!groupedByFilter.has(filterPart)) {
|
|
279
|
-
groupedByFilter.set(filterPart, []);
|
|
280
|
-
}
|
|
281
|
-
groupedByFilter.get(filterPart).push(fieldPart);
|
|
282
|
-
}
|
|
283
|
-
const combinedResult = Array.isArray(objOrArray) ? [] : {};
|
|
284
|
-
for (const [filterPart, fieldParts] of groupedByFilter) {
|
|
285
|
-
const filteredResult = filterObjectOrArrayKeys(objOrArray, {
|
|
286
|
-
filterKeys: [filterPart],
|
|
287
|
-
rejectKeys,
|
|
288
|
-
rejectEmptyObjectsInArray
|
|
289
|
-
});
|
|
290
|
-
const fieldSelectedResult = filterObjectOrArrayKeys(filteredResult, {
|
|
291
|
-
filterKeys: fieldParts,
|
|
292
|
-
rejectEmptyObjectsInArray
|
|
293
|
-
});
|
|
294
|
-
if (Array.isArray(combinedResult) && Array.isArray(fieldSelectedResult)) {
|
|
295
|
-
combinedResult.push(...fieldSelectedResult);
|
|
296
|
-
} else if (!Array.isArray(combinedResult) && !Array.isArray(fieldSelectedResult)) {
|
|
297
|
-
Object.assign(combinedResult, fieldSelectedResult);
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
if (filterOnlyPatterns.length === 0) {
|
|
301
|
-
return combinedResult;
|
|
302
|
-
}
|
|
303
|
-
dataToProcess = combinedResult;
|
|
304
|
-
}
|
|
305
|
-
function matchPath(path, pattern, value) {
|
|
306
|
-
function rec(pi, pti) {
|
|
307
|
-
if (pti >= pattern.length) return pi === path.length;
|
|
308
|
-
const pt = pattern[pti];
|
|
309
|
-
if (pt.type === "WILDCARD_ANY") {
|
|
310
|
-
if (rec(pi, pti + 1)) return true;
|
|
311
|
-
if (pi < path.length) return rec(pi + 1, pti);
|
|
312
|
-
return false;
|
|
313
|
-
}
|
|
314
|
-
if (pt.type === "WILDCARD_ONE") {
|
|
315
|
-
let j = pi;
|
|
316
|
-
let sawKey = false;
|
|
317
|
-
while (j < path.length) {
|
|
318
|
-
if (path[j].type === "KEY") sawKey = true;
|
|
319
|
-
if (sawKey && rec(j, pti + 1)) return true;
|
|
320
|
-
j += 1;
|
|
321
|
-
}
|
|
322
|
-
return false;
|
|
323
|
-
}
|
|
324
|
-
if (pi >= path.length) return false;
|
|
325
|
-
const ct = path[pi];
|
|
326
|
-
switch (pt.type) {
|
|
327
|
-
case "KEY":
|
|
328
|
-
if (ct.type === "KEY" && ct.name === pt.name)
|
|
329
|
-
return rec(pi + 1, pti + 1);
|
|
330
|
-
if (ct.type === "INDEX") return rec(pi + 1, pti);
|
|
331
|
-
return false;
|
|
332
|
-
case "INDEX":
|
|
333
|
-
if (ct.type === "INDEX" && ct.index === pt.index)
|
|
334
|
-
return rec(pi + 1, pti + 1);
|
|
335
|
-
return false;
|
|
336
|
-
case "INDEX_ANY":
|
|
337
|
-
if (ct.type === "INDEX") return rec(pi + 1, pti + 1);
|
|
338
|
-
return false;
|
|
339
|
-
case "INDEX_RANGE":
|
|
340
|
-
if (ct.type === "INDEX") {
|
|
341
|
-
const okLower = ct.index >= pt.start;
|
|
342
|
-
const okUpper = pt.end === null ? true : ct.index <= pt.end;
|
|
343
|
-
if (okLower && okUpper) return rec(pi + 1, pti + 1);
|
|
344
|
-
}
|
|
345
|
-
return false;
|
|
346
|
-
case "INDEX_FILTER":
|
|
347
|
-
if (ct.type === "INDEX" && value !== void 0) {
|
|
348
|
-
const results = pt.conditions.map(
|
|
349
|
-
(cond) => evaluateCondition(value, cond)
|
|
350
|
-
);
|
|
351
|
-
const matches = pt.logic === "AND" ? results.every((r) => r) : results.some((r) => r);
|
|
352
|
-
if (matches) return rec(pi + 1, pti + 1);
|
|
353
|
-
}
|
|
354
|
-
return false;
|
|
355
|
-
}
|
|
356
|
-
}
|
|
357
|
-
return rec(0, 0);
|
|
358
|
-
}
|
|
359
|
-
const matchesAnyFilter = (path, value) => filterPatterns.some((p) => matchPath(path, p, value));
|
|
360
|
-
const matchesAnyReject = (path, value) => rejectPatterns.some((p) => matchPath(path, p, value));
|
|
361
|
-
function getSortPriority(path) {
|
|
362
|
-
for (let i = 0; i < sortPatternsParsed.length; i++) {
|
|
363
|
-
if (matchPath(path, sortPatternsParsed[i])) {
|
|
364
|
-
return i;
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
return sortPatternsParsed.length;
|
|
368
|
-
}
|
|
369
|
-
function applySortKeys(keys, obj, sortOrder) {
|
|
370
|
-
if (sortOrder === "asc") {
|
|
371
|
-
return [...keys].sort();
|
|
372
|
-
}
|
|
373
|
-
if (sortOrder === "desc") {
|
|
374
|
-
return [...keys].sort().reverse();
|
|
375
|
-
}
|
|
376
|
-
return sortBy(
|
|
377
|
-
sortBy(keys, (k) => k),
|
|
378
|
-
(key) => {
|
|
379
|
-
const value = obj[key];
|
|
380
|
-
if (value !== void 0 && value !== null) {
|
|
381
|
-
if (Array.isArray(value) && value.length === 0) return 0;
|
|
382
|
-
if (isPlainObject(value)) {
|
|
383
|
-
const objLength = Object.keys(value).length;
|
|
384
|
-
return 1.99 + objLength * -1e-3;
|
|
385
|
-
}
|
|
386
|
-
if (Array.isArray(value)) {
|
|
387
|
-
const allItemsArePrimitives = value.every(
|
|
388
|
-
(item) => typeof item === "string" || typeof item === "number" || typeof item === "boolean" || item === null || item === void 0
|
|
389
|
-
);
|
|
390
|
-
if (allItemsArePrimitives) {
|
|
391
|
-
return 1.9 + value.length * -1e-3;
|
|
392
|
-
} else {
|
|
393
|
-
return 1.5 + value.length * -0.01;
|
|
394
|
-
}
|
|
395
|
-
}
|
|
396
|
-
if (key === "id" || key === "key") return 5;
|
|
397
|
-
if (ID_PROP_REGEXP.test(key)) return 4.5;
|
|
398
|
-
if (typeof value === "boolean") return 4;
|
|
399
|
-
if (typeof value === "number") return 3.5;
|
|
400
|
-
if (typeof value === "string" && value.length < 20) return 3;
|
|
401
|
-
return 2;
|
|
402
|
-
}
|
|
403
|
-
return 0;
|
|
404
|
-
},
|
|
405
|
-
"desc"
|
|
406
|
-
);
|
|
407
|
-
}
|
|
408
|
-
function sortKeysWithPatterns(keys_, obj, currentPath) {
|
|
409
|
-
if (!sortKeys && sortPatternsParsed.length === 0) {
|
|
410
|
-
return keys_;
|
|
411
|
-
}
|
|
412
|
-
let keysToSort = keys_;
|
|
413
|
-
if (sortKeys) {
|
|
414
|
-
keysToSort = applySortKeys(keysToSort, obj, sortKeys);
|
|
415
|
-
}
|
|
416
|
-
const sortedKeys = [...keysToSort].sort((a, b) => {
|
|
417
|
-
const pathA = currentPath.concat({ type: "KEY", name: a });
|
|
418
|
-
const pathB = currentPath.concat({ type: "KEY", name: b });
|
|
419
|
-
const priorityA = getSortPriority(pathA);
|
|
420
|
-
const priorityB = getSortPriority(pathB);
|
|
421
|
-
if (priorityA !== priorityB) {
|
|
422
|
-
return priorityA - priorityB;
|
|
423
|
-
}
|
|
424
|
-
if (sortKeys === "desc") {
|
|
425
|
-
return b.localeCompare(a);
|
|
426
|
-
}
|
|
427
|
-
if (sortKeys === "asc") {
|
|
428
|
-
return a.localeCompare(b);
|
|
429
|
-
}
|
|
430
|
-
return 0;
|
|
431
|
-
});
|
|
432
|
-
return sortedKeys;
|
|
433
|
-
}
|
|
434
|
-
const build = (value, path, allowedByFilter, stack2, isRoot, parentIsArray) => {
|
|
435
|
-
if (Array.isArray(value)) {
|
|
436
|
-
if (stack2.has(value)) {
|
|
437
|
-
throw new TypeError("Circular references are not supported");
|
|
438
|
-
}
|
|
439
|
-
stack2.add(value);
|
|
440
|
-
const out = [];
|
|
441
|
-
const includeAllChildren = allowedByFilter || !hasFilters;
|
|
442
|
-
for (let index = 0; index < value.length; index += 1) {
|
|
443
|
-
const childPath = path.concat({ type: "INDEX", index });
|
|
444
|
-
const child = value[index];
|
|
445
|
-
if (hasRejects && matchesAnyReject(childPath, child)) continue;
|
|
446
|
-
const directInclude = hasFilters ? matchesAnyFilter(childPath, child) : true;
|
|
447
|
-
const childAllowed = includeAllChildren || directInclude;
|
|
448
|
-
if (isPlainObject(child) || Array.isArray(child)) {
|
|
449
|
-
const builtChild = build(
|
|
450
|
-
child,
|
|
451
|
-
childPath,
|
|
452
|
-
childAllowed,
|
|
453
|
-
stack2,
|
|
454
|
-
false,
|
|
455
|
-
true
|
|
456
|
-
);
|
|
457
|
-
if (builtChild !== void 0) {
|
|
458
|
-
out.push(builtChild);
|
|
459
|
-
}
|
|
460
|
-
} else {
|
|
461
|
-
if (childAllowed) {
|
|
462
|
-
out.push(child);
|
|
463
|
-
}
|
|
464
|
-
}
|
|
465
|
-
}
|
|
466
|
-
stack2.delete(value);
|
|
467
|
-
const filteredOut = rejectEmptyObjectsInArray ? out.filter(
|
|
468
|
-
(item) => !(isPlainObject(item) && Object.keys(item).length === 0)
|
|
469
|
-
) : out;
|
|
470
|
-
if (filteredOut.length === 0 && !allowedByFilter && !isRoot)
|
|
471
|
-
return void 0;
|
|
472
|
-
return filteredOut;
|
|
473
|
-
}
|
|
474
|
-
if (isPlainObject(value)) {
|
|
475
|
-
if (stack2.has(value)) {
|
|
476
|
-
throw new TypeError("Circular references are not supported");
|
|
477
|
-
}
|
|
478
|
-
stack2.add(value);
|
|
479
|
-
const result = {};
|
|
480
|
-
const includeAllChildren = allowedByFilter || !hasFilters;
|
|
481
|
-
const sortedKeys = sortKeysWithPatterns(Object.keys(value), value, path);
|
|
482
|
-
for (const key of sortedKeys) {
|
|
483
|
-
const childPath = path.concat({ type: "KEY", name: key });
|
|
484
|
-
if (hasRejects && matchesAnyReject(childPath)) continue;
|
|
485
|
-
const val = value[key];
|
|
486
|
-
const directInclude = hasFilters ? matchesAnyFilter(childPath) : true;
|
|
487
|
-
const childAllowed = includeAllChildren || directInclude;
|
|
488
|
-
if (isPlainObject(val) || Array.isArray(val)) {
|
|
489
|
-
const builtChild = build(
|
|
490
|
-
val,
|
|
491
|
-
childPath,
|
|
492
|
-
childAllowed,
|
|
493
|
-
stack2,
|
|
494
|
-
false,
|
|
495
|
-
false
|
|
496
|
-
);
|
|
497
|
-
if (builtChild === void 0) {
|
|
498
|
-
continue;
|
|
499
|
-
}
|
|
500
|
-
if (Array.isArray(builtChild) && builtChild.length === 0 && !childAllowed) {
|
|
501
|
-
continue;
|
|
502
|
-
}
|
|
503
|
-
if (isPlainObject(builtChild) && Object.keys(builtChild).length === 0 && !childAllowed) {
|
|
504
|
-
continue;
|
|
505
|
-
}
|
|
506
|
-
result[key] = builtChild;
|
|
507
|
-
} else {
|
|
508
|
-
if (childAllowed) {
|
|
509
|
-
result[key] = val;
|
|
510
|
-
}
|
|
511
|
-
}
|
|
512
|
-
}
|
|
513
|
-
stack2.delete(value);
|
|
514
|
-
if (Object.keys(result).length === 0 && !allowedByFilter && !isRoot) {
|
|
515
|
-
if (parentIsArray && !rejectEmptyObjectsInArray) {
|
|
516
|
-
return {};
|
|
517
|
-
}
|
|
518
|
-
return void 0;
|
|
519
|
-
}
|
|
520
|
-
return result;
|
|
521
|
-
}
|
|
522
|
-
return allowedByFilter || !hasFilters ? value : void 0;
|
|
523
|
-
};
|
|
524
|
-
const startPath = [];
|
|
525
|
-
const initialAllowed = !hasFilters;
|
|
526
|
-
const stack = /* @__PURE__ */ new WeakSet();
|
|
527
|
-
const built = build(
|
|
528
|
-
dataToProcess,
|
|
529
|
-
startPath,
|
|
530
|
-
initialAllowed,
|
|
531
|
-
stack,
|
|
532
|
-
true,
|
|
533
|
-
false
|
|
534
|
-
);
|
|
535
|
-
if (built === void 0) return Array.isArray(dataToProcess) ? [] : {};
|
|
536
|
-
return built;
|
|
537
|
-
}
|
|
538
|
-
function parseFilterConditions(filterContent) {
|
|
539
|
-
const conditions = [];
|
|
540
|
-
let logic = "AND";
|
|
541
|
-
const caseInsensitive = filterContent.startsWith("i");
|
|
542
|
-
const content = caseInsensitive ? filterContent.slice(1) : filterContent;
|
|
543
|
-
const hasAnd = content.includes("&&");
|
|
544
|
-
const hasOr = content.includes(" || ");
|
|
545
|
-
if (hasAnd && hasOr) {
|
|
546
|
-
throw new Error(
|
|
547
|
-
"Mixing && and || operators in the same filter is not supported. Use separate filter patterns instead."
|
|
548
|
-
);
|
|
549
|
-
}
|
|
550
|
-
const andGroups = content.split("&&").map((s) => s.trim());
|
|
551
|
-
for (const andGroup of andGroups) {
|
|
552
|
-
if (andGroup.includes(" || ")) {
|
|
553
|
-
logic = "OR";
|
|
554
|
-
const orConditions = andGroup.split(" || ").map((s) => s.trim());
|
|
555
|
-
for (const orCondition of orConditions) {
|
|
556
|
-
const parsed = parseSingleCondition(orCondition, caseInsensitive);
|
|
557
|
-
if (parsed) {
|
|
558
|
-
conditions.push(parsed);
|
|
559
|
-
}
|
|
560
|
-
}
|
|
561
|
-
} else {
|
|
562
|
-
const parsed = parseSingleCondition(andGroup, caseInsensitive);
|
|
563
|
-
if (parsed) {
|
|
564
|
-
conditions.push(parsed);
|
|
565
|
-
}
|
|
566
|
-
}
|
|
567
|
-
}
|
|
568
|
-
if (conditions.length === 0) {
|
|
569
|
-
return null;
|
|
570
|
-
}
|
|
571
|
-
return {
|
|
572
|
-
type: "INDEX_FILTER",
|
|
573
|
-
conditions,
|
|
574
|
-
logic
|
|
575
|
-
};
|
|
576
|
-
}
|
|
577
|
-
function parseSingleCondition(condition, caseInsensitive = false) {
|
|
578
|
-
const cleanCondition = condition.startsWith("%") ? condition.slice(1) : condition;
|
|
579
|
-
let operator = null;
|
|
580
|
-
let operatorIndex = -1;
|
|
581
|
-
let operatorLength = 0;
|
|
582
|
-
const operators = [
|
|
583
|
-
["!*=", "!*="],
|
|
584
|
-
["!^=", "!^="],
|
|
585
|
-
["!$=", "!$="],
|
|
586
|
-
["!=", "!="],
|
|
587
|
-
["*=", "*="],
|
|
588
|
-
["^=", "^="],
|
|
589
|
-
["$=", "$="],
|
|
590
|
-
["=", "="]
|
|
591
|
-
];
|
|
592
|
-
for (const [op, opType] of operators) {
|
|
593
|
-
const index = cleanCondition.indexOf(op);
|
|
594
|
-
if (index !== -1) {
|
|
595
|
-
operator = opType;
|
|
596
|
-
operatorIndex = index;
|
|
597
|
-
operatorLength = op.length;
|
|
598
|
-
break;
|
|
599
|
-
}
|
|
600
|
-
}
|
|
601
|
-
if (operator === null || operatorIndex === -1) {
|
|
602
|
-
return null;
|
|
603
|
-
}
|
|
604
|
-
const property = cleanCondition.slice(0, operatorIndex).trim();
|
|
605
|
-
const valueStr = cleanCondition.slice(operatorIndex + operatorLength).trim();
|
|
606
|
-
const values = [];
|
|
607
|
-
if (valueStr.includes(" | ")) {
|
|
608
|
-
const parts = valueStr.split(" | ");
|
|
609
|
-
for (const part of parts) {
|
|
610
|
-
const trimmed = part.trim();
|
|
611
|
-
const value = trimmed.startsWith('"') && trimmed.endsWith('"') ? trimmed.slice(1, -1) : trimmed;
|
|
612
|
-
values.push(value);
|
|
613
|
-
}
|
|
614
|
-
} else {
|
|
615
|
-
const trimmed = valueStr.trim();
|
|
616
|
-
const value = trimmed.startsWith('"') && trimmed.endsWith('"') ? trimmed.slice(1, -1) : trimmed;
|
|
617
|
-
values.push(value);
|
|
618
|
-
}
|
|
619
|
-
return {
|
|
620
|
-
property,
|
|
621
|
-
operator,
|
|
622
|
-
values,
|
|
623
|
-
caseInsensitive
|
|
624
|
-
};
|
|
625
|
-
}
|
|
626
|
-
function separateFilterPatterns(patterns) {
|
|
627
|
-
const filterOnlyPatterns = [];
|
|
628
|
-
const combinedPatterns = [];
|
|
629
|
-
for (const pattern of patterns) {
|
|
630
|
-
const filterMatch = pattern.match(/^(.+\[[i%][^[\]]*\])\.(.+)$/);
|
|
631
|
-
if (filterMatch?.[1] && filterMatch[2]) {
|
|
632
|
-
const filterPart = filterMatch[1];
|
|
633
|
-
const fieldPart = filterMatch[2];
|
|
634
|
-
const baseArrayPath = filterPart.replace(/\[[i%][^[\]]*\]/, "[*]");
|
|
635
|
-
combinedPatterns.push({
|
|
636
|
-
filterPart,
|
|
637
|
-
fieldPart: `${baseArrayPath}.${fieldPart}`
|
|
638
|
-
});
|
|
639
|
-
} else {
|
|
640
|
-
filterOnlyPatterns.push(pattern);
|
|
641
|
-
}
|
|
642
|
-
}
|
|
643
|
-
return { filterOnlyPatterns, combinedPatterns };
|
|
644
|
-
}
|
|
645
|
-
function expandPatterns(pattern) {
|
|
646
|
-
function expandSingle(str) {
|
|
647
|
-
const start = str.indexOf("(");
|
|
648
|
-
if (start === -1) {
|
|
649
|
-
return [str];
|
|
650
|
-
}
|
|
651
|
-
const end = str.indexOf(")", start);
|
|
652
|
-
if (end === -1) {
|
|
653
|
-
return [str];
|
|
654
|
-
}
|
|
655
|
-
const before = str.slice(0, start);
|
|
656
|
-
const inside = str.slice(start + 1, end);
|
|
657
|
-
const after = str.slice(end + 1);
|
|
658
|
-
if (!inside.includes("|")) {
|
|
659
|
-
return expandSingle(before + inside + after);
|
|
660
|
-
}
|
|
661
|
-
const options = inside.split("|").filter((option) => option.trim().length > 0);
|
|
662
|
-
const results = [];
|
|
663
|
-
for (const option of options) {
|
|
664
|
-
const newStr = before + option + after;
|
|
665
|
-
results.push(...expandSingle(newStr));
|
|
666
|
-
}
|
|
667
|
-
return results;
|
|
668
|
-
}
|
|
669
|
-
return expandSingle(pattern);
|
|
670
|
-
}
|
|
671
|
-
function parsePattern(pattern) {
|
|
672
|
-
const tokens = [];
|
|
673
|
-
let i = 0;
|
|
674
|
-
const n = pattern.length;
|
|
675
|
-
const pushKey = (name) => {
|
|
676
|
-
if (name.length === 0) return;
|
|
677
|
-
tokens.push({ type: "KEY", name });
|
|
678
|
-
};
|
|
679
|
-
while (i < n) {
|
|
680
|
-
const ch = pattern[i];
|
|
681
|
-
if (ch === ".") {
|
|
682
|
-
i += 1;
|
|
683
|
-
continue;
|
|
684
|
-
}
|
|
685
|
-
if (ch === "[") {
|
|
686
|
-
const end = pattern.indexOf("]", i + 1);
|
|
687
|
-
const inside = end === -1 ? pattern.slice(i + 1) : pattern.slice(i + 1, end);
|
|
688
|
-
if (inside.startsWith("%") || inside.startsWith("i%")) {
|
|
689
|
-
let filterContent;
|
|
690
|
-
if (inside.startsWith("i%")) {
|
|
691
|
-
filterContent = `i${inside.slice(2)}`;
|
|
692
|
-
} else if (inside.startsWith("%")) {
|
|
693
|
-
filterContent = inside.slice(1);
|
|
694
|
-
} else {
|
|
695
|
-
filterContent = inside;
|
|
696
|
-
}
|
|
697
|
-
const filterToken = parseFilterConditions(filterContent);
|
|
698
|
-
if (filterToken) {
|
|
699
|
-
tokens.push(filterToken);
|
|
700
|
-
}
|
|
701
|
-
} else if (inside === "*") {
|
|
702
|
-
tokens.push({ type: "INDEX_ANY" });
|
|
703
|
-
} else if (inside.includes("-")) {
|
|
704
|
-
const parts = inside.split("-");
|
|
705
|
-
const startStr = parts[0] ?? "";
|
|
706
|
-
const endStr = parts[1] ?? "";
|
|
707
|
-
const start = parseInt(startStr, 10);
|
|
708
|
-
const endNum = endStr === "*" ? null : parseInt(endStr, 10);
|
|
709
|
-
tokens.push({
|
|
710
|
-
type: "INDEX_RANGE",
|
|
711
|
-
start,
|
|
712
|
-
end: endNum === null || Number.isFinite(endNum) ? endNum : null
|
|
713
|
-
});
|
|
714
|
-
} else if (inside.length > 0) {
|
|
715
|
-
const idx = parseInt(inside, 10);
|
|
716
|
-
tokens.push({ type: "INDEX", index: idx });
|
|
717
|
-
}
|
|
718
|
-
i = end === -1 ? n : end + 1;
|
|
719
|
-
continue;
|
|
720
|
-
}
|
|
721
|
-
if (ch === "*") {
|
|
722
|
-
if (pattern[i + 1] === "*") {
|
|
723
|
-
tokens.push({ type: "WILDCARD_ANY" });
|
|
724
|
-
i += 2;
|
|
725
|
-
let j2 = i;
|
|
726
|
-
while (j2 < n) {
|
|
727
|
-
const c = pattern[j2];
|
|
728
|
-
if (c === "." || c === "[") break;
|
|
729
|
-
j2 += 1;
|
|
730
|
-
}
|
|
731
|
-
if (j2 > i) {
|
|
732
|
-
pushKey(pattern.slice(i, j2));
|
|
733
|
-
i = j2;
|
|
734
|
-
}
|
|
735
|
-
continue;
|
|
736
|
-
} else {
|
|
737
|
-
tokens.push({ type: "WILDCARD_ONE" });
|
|
738
|
-
i += 1;
|
|
739
|
-
continue;
|
|
740
|
-
}
|
|
741
|
-
}
|
|
742
|
-
let j = i;
|
|
743
|
-
while (j < n) {
|
|
744
|
-
const c = pattern[j];
|
|
745
|
-
if (c === "." || c === "[") break;
|
|
746
|
-
j += 1;
|
|
747
|
-
}
|
|
748
|
-
pushKey(pattern.slice(i, j));
|
|
749
|
-
i = j;
|
|
750
|
-
}
|
|
751
|
-
return tokens;
|
|
752
|
-
}
|
|
753
|
-
|
|
754
|
-
// src/mathUtils.ts
|
|
755
|
-
function clampMin(value, min) {
|
|
756
|
-
return value < min ? min : value;
|
|
757
|
-
}
|
|
758
|
-
|
|
759
|
-
// src/objUtils.ts
|
|
760
|
-
var import_t_result = require("t-result");
|
|
761
|
-
function pick(obj, keys) {
|
|
762
|
-
const result = {};
|
|
763
|
-
for (const key of keys) {
|
|
764
|
-
result[key] = obj[key];
|
|
765
|
-
}
|
|
766
|
-
return result;
|
|
767
|
-
}
|
|
768
|
-
function omit(obj, keys) {
|
|
769
|
-
const result = {};
|
|
770
|
-
for (const key of Object.keys(obj)) {
|
|
771
|
-
if (!keys.includes(key)) {
|
|
772
|
-
result[key] = obj[key];
|
|
773
|
-
}
|
|
774
|
-
}
|
|
775
|
-
return result;
|
|
776
|
-
}
|
|
777
|
-
|
|
778
|
-
// src/promiseUtils.ts
|
|
779
|
-
function defer() {
|
|
780
|
-
let resolve;
|
|
781
|
-
let reject;
|
|
782
|
-
const promise = new Promise((_resolve, _reject) => {
|
|
783
|
-
resolve = _resolve;
|
|
784
|
-
reject = _reject;
|
|
785
|
-
});
|
|
786
|
-
return { resolve, reject, promise };
|
|
787
|
-
}
|
|
788
|
-
|
|
789
|
-
// src/conversions.ts
|
|
790
|
-
function bytesToHumanReadable(bytes) {
|
|
791
|
-
if (bytes < 1024) {
|
|
792
|
-
return `${bytes} B`;
|
|
793
|
-
}
|
|
794
|
-
const kb = bytes / 1024;
|
|
795
|
-
if (kb < 1024) {
|
|
796
|
-
return `${kb.toFixed(2)} KB`;
|
|
797
|
-
}
|
|
798
|
-
const mb = kb / 1024;
|
|
799
|
-
if (mb < 1024) {
|
|
800
|
-
return `${mb.toFixed(2)} MB`;
|
|
801
|
-
}
|
|
802
|
-
const gb = mb / 1024;
|
|
803
|
-
return `${gb.toFixed(2)} GB`;
|
|
804
|
-
}
|
|
805
|
-
|
|
806
|
-
// src/stringUtils.ts
|
|
807
|
-
function truncateString(str, length, ellipsis = "\u2026") {
|
|
808
|
-
if (str.length <= length) return str;
|
|
809
|
-
return str.slice(0, length - 1) + ellipsis;
|
|
810
|
-
}
|
|
811
|
-
|
|
812
|
-
// src/yamlStringify.ts
|
|
813
|
-
function yamlStringify(obj, {
|
|
814
|
-
maxLineLength = 100,
|
|
815
|
-
showUndefined,
|
|
816
|
-
maxDepth = 50,
|
|
817
|
-
collapseObjects = false,
|
|
818
|
-
addRootObjSpaces = "beforeAndAfter"
|
|
819
|
-
} = {}) {
|
|
820
|
-
if (isObject(obj) || Array.isArray(obj) || typeof obj === "function") {
|
|
821
|
-
return `${stringifyValue(obj, "", maxLineLength, !!showUndefined, maxDepth, 0, collapseObjects, addRootObjSpaces, false)}
|
|
822
|
-
`;
|
|
823
|
-
}
|
|
824
|
-
return JSON.stringify(obj) || "undefined";
|
|
825
|
-
}
|
|
826
|
-
function stringifyValue(value, indent, maxLineLength, showUndefined, maxDepth, depth, collapseObjects, addObjSpaces, isArrayItem) {
|
|
827
|
-
let result = "";
|
|
828
|
-
const childIndent = `${indent} `;
|
|
829
|
-
if (isPlainObject(value)) {
|
|
830
|
-
if (Object.keys(value).length === 0) {
|
|
831
|
-
return "{}";
|
|
832
|
-
}
|
|
833
|
-
if (collapseObjects && depth > 0) {
|
|
834
|
-
const entries = Object.entries(value).filter(
|
|
835
|
-
([, val]) => val !== void 0 || showUndefined
|
|
836
|
-
);
|
|
837
|
-
const isSimpleObject = entries.every(([, val]) => {
|
|
838
|
-
if (typeof val === "string") {
|
|
839
|
-
return !val.includes("'") && !val.includes('"') && !val.includes("\\");
|
|
840
|
-
}
|
|
841
|
-
return typeof val === "number" || typeof val === "boolean" || val === null || val === void 0;
|
|
842
|
-
});
|
|
843
|
-
const shouldCollapse = isArrayItem ? entries.length > 1 : entries.length > 0;
|
|
844
|
-
if (isSimpleObject && shouldCollapse) {
|
|
845
|
-
let line = "{ ";
|
|
846
|
-
line += entries.map(([key, val]) => {
|
|
847
|
-
let valueStr;
|
|
848
|
-
if (typeof val === "string") {
|
|
849
|
-
if (val.includes("'") && !val.includes('"')) {
|
|
850
|
-
valueStr = `"${val}"`;
|
|
851
|
-
} else if (val.includes('"') && !val.includes("'")) {
|
|
852
|
-
valueStr = `'${val}'`;
|
|
853
|
-
} else if (val.includes("'") && val.includes('"')) {
|
|
854
|
-
valueStr = `"${val.replace(/"/g, '\\"')}"`;
|
|
855
|
-
} else {
|
|
856
|
-
valueStr = `'${val}'`;
|
|
857
|
-
}
|
|
858
|
-
} else {
|
|
859
|
-
valueStr = String(val);
|
|
860
|
-
}
|
|
861
|
-
return `${key}: ${valueStr}`;
|
|
862
|
-
}).join(", ");
|
|
863
|
-
line += " }";
|
|
864
|
-
if (line.length <= maxLineLength) {
|
|
865
|
-
return line;
|
|
866
|
-
}
|
|
867
|
-
}
|
|
868
|
-
}
|
|
869
|
-
let prevValue;
|
|
870
|
-
let afterSpaceWasAdded = false;
|
|
871
|
-
for (let [key, objVal] of Object.entries(value)) {
|
|
872
|
-
if (objVal === void 0 && !showUndefined) {
|
|
873
|
-
continue;
|
|
874
|
-
}
|
|
875
|
-
if (depth > maxDepth) {
|
|
876
|
-
objVal = `{max depth reached}`;
|
|
877
|
-
}
|
|
878
|
-
const normalizedValue2 = normalizeValue(objVal);
|
|
879
|
-
if (normalizedValue2 !== null) {
|
|
880
|
-
objVal = normalizedValue2[1];
|
|
881
|
-
key = `${key}{${normalizedValue2[0]}}`;
|
|
882
|
-
}
|
|
883
|
-
const valueString = stringifyValue(
|
|
884
|
-
objVal,
|
|
885
|
-
childIndent,
|
|
886
|
-
maxLineLength,
|
|
887
|
-
showUndefined,
|
|
888
|
-
maxDepth,
|
|
889
|
-
depth + 1,
|
|
890
|
-
collapseObjects,
|
|
891
|
-
addObjSpaces,
|
|
892
|
-
false
|
|
893
|
-
);
|
|
894
|
-
const willBeCollapsed = isObject(objVal) && (Object.keys(objVal).length === 0 || collapseObjects && depth + 1 > 0 && (() => {
|
|
895
|
-
const filteredEntries = Object.entries(objVal).filter(
|
|
896
|
-
([, val]) => val !== void 0 || showUndefined
|
|
897
|
-
);
|
|
898
|
-
const shouldCollapseThis = isArrayItem ? filteredEntries.length > 1 : filteredEntries.length > 0;
|
|
899
|
-
return shouldCollapseThis && filteredEntries.every(([, val]) => {
|
|
900
|
-
if (typeof val === "string") {
|
|
901
|
-
return !val.includes("'") && !val.includes('"') && !val.includes("\\");
|
|
902
|
-
}
|
|
903
|
-
return typeof val === "number" || typeof val === "boolean" || val === null || val === void 0;
|
|
904
|
-
});
|
|
905
|
-
})());
|
|
906
|
-
const prevWasCollapsed = prevValue && isObject(prevValue) && (Object.keys(prevValue).length === 0 || collapseObjects && depth + 1 > 0 && (() => {
|
|
907
|
-
const filteredEntries = Object.entries(prevValue).filter(
|
|
908
|
-
([, val]) => val !== void 0 || showUndefined
|
|
909
|
-
);
|
|
910
|
-
const shouldCollapseThis = isArrayItem ? filteredEntries.length > 1 : filteredEntries.length > 0;
|
|
911
|
-
return shouldCollapseThis && filteredEntries.every(([, val]) => {
|
|
912
|
-
if (typeof val === "string") {
|
|
913
|
-
return !val.includes("'") && !val.includes('"') && !val.includes("\\");
|
|
914
|
-
}
|
|
915
|
-
return typeof val === "number" || typeof val === "boolean" || val === null || val === void 0;
|
|
916
|
-
});
|
|
917
|
-
})());
|
|
918
|
-
if (!afterSpaceWasAdded && indent === "" && isObject(objVal) && !willBeCollapsed && prevValue && !prevWasCollapsed && (addObjSpaces === "before" || addObjSpaces === "beforeAndAfter")) {
|
|
919
|
-
result += "\n";
|
|
920
|
-
}
|
|
921
|
-
if (Array.isArray(objVal)) {
|
|
922
|
-
const arrayIsSingleLine = valueString.split("\n").length === 1;
|
|
923
|
-
if (arrayIsSingleLine && !valueString.trim().startsWith("-")) {
|
|
924
|
-
result += `${indent}${key}: `;
|
|
925
|
-
} else {
|
|
926
|
-
result += `${indent}${key}:
|
|
927
|
-
`;
|
|
928
|
-
}
|
|
929
|
-
} else if (isObject(objVal)) {
|
|
930
|
-
const isCollapsedObject = valueString.startsWith("{") && !valueString.includes("\n");
|
|
931
|
-
if (Object.keys(objVal).length === 0 || isCollapsedObject) {
|
|
932
|
-
result += `${indent}${key}: `;
|
|
933
|
-
} else {
|
|
934
|
-
result += `${indent}${key}:
|
|
935
|
-
`;
|
|
936
|
-
}
|
|
937
|
-
} else {
|
|
938
|
-
result += `${indent}${key}: `;
|
|
939
|
-
}
|
|
940
|
-
result += valueString;
|
|
941
|
-
result += "\n";
|
|
942
|
-
if (indent === "") {
|
|
943
|
-
const isCollapsedObject = valueString.startsWith("{") && !valueString.includes("\n") && valueString.length > 2;
|
|
944
|
-
if (isObject(objVal) && !isCollapsedObject) {
|
|
945
|
-
if (addObjSpaces === "after" || addObjSpaces === "beforeAndAfter") {
|
|
946
|
-
result += "\n";
|
|
947
|
-
afterSpaceWasAdded = true;
|
|
948
|
-
} else {
|
|
949
|
-
afterSpaceWasAdded = false;
|
|
950
|
-
}
|
|
951
|
-
}
|
|
952
|
-
}
|
|
953
|
-
prevValue = objVal;
|
|
954
|
-
}
|
|
955
|
-
return result.trimEnd();
|
|
956
|
-
}
|
|
957
|
-
if (Array.isArray(value)) {
|
|
958
|
-
let arrayWasAdded = false;
|
|
959
|
-
if (value.length === 0 || value.every(
|
|
960
|
-
(item) => typeof item === "string" || typeof item === "number" || typeof item === "boolean" || item === null || item === void 0
|
|
961
|
-
)) {
|
|
962
|
-
let line = "";
|
|
963
|
-
line += `[`;
|
|
964
|
-
line += value.map((item) => {
|
|
965
|
-
let valueToUse = item;
|
|
966
|
-
if (depth > maxDepth) {
|
|
967
|
-
valueToUse = `{max depth reached}`;
|
|
968
|
-
}
|
|
969
|
-
if (typeof valueToUse === "string" && valueToUse.includes("\n")) {
|
|
970
|
-
valueToUse = valueToUse.replace(/\n/g, "\\n");
|
|
971
|
-
}
|
|
972
|
-
return stringifyValue(
|
|
973
|
-
valueToUse,
|
|
974
|
-
"",
|
|
975
|
-
maxLineLength,
|
|
976
|
-
showUndefined,
|
|
977
|
-
maxDepth,
|
|
978
|
-
depth + 1,
|
|
979
|
-
collapseObjects,
|
|
980
|
-
addObjSpaces,
|
|
981
|
-
true
|
|
982
|
-
);
|
|
983
|
-
}).join(", ");
|
|
984
|
-
line += "]";
|
|
985
|
-
if (line.length <= maxLineLength) {
|
|
986
|
-
result += line;
|
|
987
|
-
arrayWasAdded = true;
|
|
988
|
-
}
|
|
989
|
-
}
|
|
990
|
-
if (!arrayWasAdded) {
|
|
991
|
-
for (let item of value) {
|
|
992
|
-
if (depth > maxDepth) {
|
|
993
|
-
item = `{max depth reached}`;
|
|
994
|
-
}
|
|
995
|
-
result += `${indent}- `;
|
|
996
|
-
if (Array.isArray(item) || isObject(item)) {
|
|
997
|
-
let arrayString = stringifyValue(
|
|
998
|
-
item,
|
|
999
|
-
childIndent,
|
|
1000
|
-
maxLineLength,
|
|
1001
|
-
showUndefined,
|
|
1002
|
-
maxDepth,
|
|
1003
|
-
depth + 1,
|
|
1004
|
-
collapseObjects,
|
|
1005
|
-
addObjSpaces,
|
|
1006
|
-
true
|
|
1007
|
-
);
|
|
1008
|
-
arrayString = arrayString.trimStart();
|
|
1009
|
-
result += arrayString;
|
|
1010
|
-
} else {
|
|
1011
|
-
result += stringifyValue(
|
|
1012
|
-
item,
|
|
1013
|
-
childIndent,
|
|
1014
|
-
maxLineLength,
|
|
1015
|
-
showUndefined,
|
|
1016
|
-
maxDepth,
|
|
1017
|
-
depth + 1,
|
|
1018
|
-
collapseObjects,
|
|
1019
|
-
addObjSpaces,
|
|
1020
|
-
true
|
|
1021
|
-
);
|
|
1022
|
-
}
|
|
1023
|
-
result += "\n";
|
|
1024
|
-
}
|
|
1025
|
-
}
|
|
1026
|
-
return result.trimEnd();
|
|
1027
|
-
}
|
|
1028
|
-
if (typeof value === "string") {
|
|
1029
|
-
if (value.includes("\n")) {
|
|
1030
|
-
const lines = value.split("\n");
|
|
1031
|
-
for (const [i, line] of lines.entries()) {
|
|
1032
|
-
if (i === 0) {
|
|
1033
|
-
if (value.endsWith("\n")) {
|
|
1034
|
-
result += `|`;
|
|
1035
|
-
} else {
|
|
1036
|
-
result += `|-`;
|
|
1037
|
-
}
|
|
1038
|
-
result += `
|
|
1039
|
-
${indent}${line}
|
|
1040
|
-
`;
|
|
1041
|
-
} else {
|
|
1042
|
-
result += `${indent}${line}
|
|
1043
|
-
`;
|
|
1044
|
-
}
|
|
1045
|
-
}
|
|
1046
|
-
} else {
|
|
1047
|
-
if (value.includes("'") && !value.includes('"')) {
|
|
1048
|
-
result += `"${value}"`;
|
|
1049
|
-
} else if (value.includes('"') && !value.includes("'")) {
|
|
1050
|
-
result += `'${value}'`;
|
|
1051
|
-
} else if (value.includes("'") && value.includes('"')) {
|
|
1052
|
-
result += `"${value.replace(/"/g, '\\"')}"`;
|
|
1053
|
-
} else {
|
|
1054
|
-
result += `'${value}'`;
|
|
1055
|
-
}
|
|
1056
|
-
}
|
|
1057
|
-
return result.trimEnd();
|
|
1058
|
-
}
|
|
1059
|
-
if (typeof value === "number" || typeof value === "boolean" || value === null || value === void 0) {
|
|
1060
|
-
return String(value).trimEnd();
|
|
1061
|
-
}
|
|
1062
|
-
const normalizedValue = normalizeValue(value);
|
|
1063
|
-
if (normalizedValue !== null) {
|
|
1064
|
-
return stringifyValue(
|
|
1065
|
-
{
|
|
1066
|
-
[`${normalizedValue[0]}#`]: normalizedValue[1]
|
|
1067
|
-
},
|
|
1068
|
-
indent,
|
|
1069
|
-
maxLineLength,
|
|
1070
|
-
showUndefined,
|
|
1071
|
-
maxDepth,
|
|
1072
|
-
depth + 1,
|
|
1073
|
-
collapseObjects,
|
|
1074
|
-
addObjSpaces,
|
|
1075
|
-
false
|
|
1076
|
-
);
|
|
1077
|
-
}
|
|
1078
|
-
return JSON.stringify(value);
|
|
1079
|
-
}
|
|
1080
|
-
function normalizeValue(value) {
|
|
1081
|
-
if (value === null || isPlainObject(value) || Array.isArray(value)) {
|
|
1082
|
-
return null;
|
|
1083
|
-
}
|
|
1084
|
-
if (value instanceof Map) {
|
|
1085
|
-
const mapEntries = Array.from(value.entries());
|
|
1086
|
-
let mapValue;
|
|
1087
|
-
if (mapEntries.every(([key]) => typeof key === "string")) {
|
|
1088
|
-
const mapObjValue = {};
|
|
1089
|
-
for (const [key, val] of mapEntries) {
|
|
1090
|
-
mapObjValue[key] = val;
|
|
1091
|
-
}
|
|
1092
|
-
mapValue = mapObjValue;
|
|
1093
|
-
} else {
|
|
1094
|
-
mapValue = mapEntries.map(([key, val]) => ({
|
|
1095
|
-
key,
|
|
1096
|
-
value: val
|
|
1097
|
-
}));
|
|
1098
|
-
}
|
|
1099
|
-
return ["Map", mapValue];
|
|
1100
|
-
}
|
|
1101
|
-
if (value instanceof Set) {
|
|
1102
|
-
const setValue = Array.from(value);
|
|
1103
|
-
return ["Set", setValue];
|
|
1104
|
-
}
|
|
1105
|
-
if (value instanceof Date) {
|
|
1106
|
-
return ["Date", value.toISOString()];
|
|
1107
|
-
}
|
|
1108
|
-
if (value instanceof RegExp) {
|
|
1109
|
-
return ["RegExp", value.toString()];
|
|
1110
|
-
}
|
|
1111
|
-
if (value instanceof Error) {
|
|
1112
|
-
return [
|
|
1113
|
-
"Error",
|
|
1114
|
-
{
|
|
1115
|
-
message: value.message,
|
|
1116
|
-
name: value.name,
|
|
1117
|
-
stack: value.stack
|
|
1118
|
-
}
|
|
1119
|
-
];
|
|
1120
|
-
}
|
|
1121
|
-
if (value instanceof File) {
|
|
1122
|
-
return [
|
|
1123
|
-
"File",
|
|
1124
|
-
{
|
|
1125
|
-
name: value.name,
|
|
1126
|
-
type: value.type,
|
|
1127
|
-
lastModified: new Date(value.lastModified).toISOString(),
|
|
1128
|
-
size: bytesToHumanReadable(value.size)
|
|
1129
|
-
}
|
|
1130
|
-
];
|
|
1131
|
-
}
|
|
1132
|
-
if (typeof value === "object") {
|
|
1133
|
-
if ("toJSON" in value && typeof value.toJSON === "function") {
|
|
1134
|
-
return [value.constructor.name, value.toJSON()];
|
|
1135
|
-
}
|
|
1136
|
-
if ("toString" in value && typeof value.toString === "function") {
|
|
1137
|
-
const stringValue = value.toString();
|
|
1138
|
-
if (stringValue.toString() !== "[object Object]") {
|
|
1139
|
-
return [value.constructor.name, stringValue];
|
|
1140
|
-
}
|
|
1141
|
-
}
|
|
1142
|
-
const objectValue = { ...value };
|
|
1143
|
-
const displayValue = {};
|
|
1144
|
-
let addedKeys = 0;
|
|
1145
|
-
for (const [key, item] of Object.entries(objectValue)) {
|
|
1146
|
-
if (addedKeys > 4) {
|
|
1147
|
-
displayValue["...and more properties"] = Object.keys(objectValue).length - 4;
|
|
1148
|
-
break;
|
|
1149
|
-
}
|
|
1150
|
-
if (typeof item === "string" || typeof item === "number" || typeof item === "boolean" || item === null || item === void 0) {
|
|
1151
|
-
displayValue[key] = item;
|
|
1152
|
-
addedKeys++;
|
|
1153
|
-
}
|
|
1154
|
-
}
|
|
1155
|
-
return [String(value.constructor.name), displayValue];
|
|
1156
|
-
}
|
|
1157
|
-
if (typeof value === "function") {
|
|
1158
|
-
const functionString = value.toString();
|
|
1159
|
-
return [
|
|
1160
|
-
`Function`,
|
|
1161
|
-
functionString.includes("\n") ? truncateString(functionString.split("\n").join(""), 40) : functionString
|
|
1162
|
-
];
|
|
1163
|
-
}
|
|
1164
|
-
return null;
|
|
1165
|
-
}
|
|
1166
|
-
|
|
1167
|
-
// src/testUtils.ts
|
|
1168
|
-
function createLoggerStore({
|
|
1169
|
-
filterKeys: defaultFilterKeys,
|
|
1170
|
-
rejectKeys: defaultRejectKeys,
|
|
1171
|
-
splitLongLines: defaultSplitLongLines = true,
|
|
1172
|
-
maxLineLengthBeforeSplit: defaultMaxLineLengthBeforeSplit = 80,
|
|
1173
|
-
fromLastSnapshot: defaultFromLastSnapshot = false,
|
|
1174
|
-
arrays: defaultArrays = { firstNItems: 1 },
|
|
1175
|
-
changesOnly: defaultChangesOnly = false,
|
|
1176
|
-
useEmojiForBooleans: defaultUseEmojiForBooleans = true
|
|
1177
|
-
} = {}) {
|
|
1178
|
-
let logs = [];
|
|
1179
|
-
let logsTime = [];
|
|
1180
|
-
let startTime = Date.now();
|
|
1181
|
-
let onNextLog = () => {
|
|
1182
|
-
};
|
|
1183
|
-
function reset(keepLastRender = false) {
|
|
1184
|
-
logs = keepLastRender ? [logs.at(-1)] : [];
|
|
1185
|
-
logsTime = [];
|
|
1186
|
-
startTime = Date.now();
|
|
1187
|
-
}
|
|
1188
|
-
function add(render) {
|
|
1189
|
-
if (!isObject2(render)) {
|
|
1190
|
-
for (const [i, r] of render.entries()) {
|
|
1191
|
-
logs.push({
|
|
1192
|
-
i: i + 1,
|
|
1193
|
-
...r
|
|
1194
|
-
});
|
|
1195
|
-
logsTime.push(Date.now() - startTime);
|
|
1196
|
-
}
|
|
1197
|
-
} else {
|
|
1198
|
-
logs.push(render);
|
|
1199
|
-
logsTime.push(Date.now() - startTime);
|
|
1200
|
-
}
|
|
1201
|
-
onNextLog();
|
|
1202
|
-
if (logs.length > 100) {
|
|
1203
|
-
throw new Error("Too many logs");
|
|
1204
|
-
}
|
|
1205
|
-
}
|
|
1206
|
-
function logsCount() {
|
|
1207
|
-
return logs.filter((item) => !item._lastSnapshotMark).length;
|
|
1208
|
-
}
|
|
1209
|
-
async function waitNextLog(timeout = 50) {
|
|
1210
|
-
return new Promise((resolve) => {
|
|
1211
|
-
const timeoutId = setTimeout(() => {
|
|
1212
|
-
throw new Error("Timeout");
|
|
1213
|
-
}, timeout);
|
|
1214
|
-
onNextLog = () => {
|
|
1215
|
-
clearTimeout(timeoutId);
|
|
1216
|
-
resolve();
|
|
1217
|
-
};
|
|
1218
|
-
});
|
|
1219
|
-
}
|
|
1220
|
-
function getSnapshot({
|
|
1221
|
-
arrays = defaultArrays,
|
|
1222
|
-
changesOnly = defaultChangesOnly,
|
|
1223
|
-
filterKeys = defaultFilterKeys,
|
|
1224
|
-
rejectKeys = defaultRejectKeys,
|
|
1225
|
-
includeLastSnapshotEndMark = true,
|
|
1226
|
-
splitLongLines = defaultSplitLongLines,
|
|
1227
|
-
maxLineLengthBeforeSplit = defaultMaxLineLengthBeforeSplit,
|
|
1228
|
-
fromLastSnapshot = defaultFromLastSnapshot,
|
|
1229
|
-
useEmojiForBooleans = defaultUseEmojiForBooleans
|
|
1230
|
-
} = {}) {
|
|
1231
|
-
let rendersToUse = logs;
|
|
1232
|
-
if (changesOnly || filterKeys || rejectKeys) {
|
|
1233
|
-
rendersToUse = [];
|
|
1234
|
-
for (let { item, prev } of arrayWithPrevAndIndex(logs)) {
|
|
1235
|
-
if (item._lastSnapshotMark || item._mark) {
|
|
1236
|
-
rendersToUse.push(item);
|
|
1237
|
-
continue;
|
|
1238
|
-
}
|
|
1239
|
-
if (filterKeys) {
|
|
1240
|
-
prev = prev && pick(prev, filterKeys);
|
|
1241
|
-
item = pick(item, filterKeys);
|
|
1242
|
-
}
|
|
1243
|
-
if (rejectKeys) {
|
|
1244
|
-
prev = prev && omit(prev, rejectKeys);
|
|
1245
|
-
item = omit(item, rejectKeys);
|
|
1246
|
-
}
|
|
1247
|
-
if (!deepEqual(prev, item)) {
|
|
1248
|
-
rendersToUse.push(item);
|
|
1249
|
-
}
|
|
1250
|
-
}
|
|
1251
|
-
}
|
|
1252
|
-
if (fromLastSnapshot) {
|
|
1253
|
-
const lastSnapshotMark = rendersToUse.findLastIndex(
|
|
1254
|
-
(item) => item._lastSnapshotMark === true
|
|
1255
|
-
);
|
|
1256
|
-
rendersToUse = rendersToUse.slice(clampMin(lastSnapshotMark, 0));
|
|
1257
|
-
}
|
|
1258
|
-
logs.push({ _lastSnapshotMark: true });
|
|
1259
|
-
const propDivider = "\u22C5";
|
|
1260
|
-
const snapShot = `
|
|
1261
|
-
${filterAndMap(rendersToUse, (render, i) => {
|
|
1262
|
-
if (render._lastSnapshotMark) {
|
|
1263
|
-
if (includeLastSnapshotEndMark) {
|
|
1264
|
-
if (rendersToUse.length === 1) {
|
|
1265
|
-
return "\u22C5\u22C5\u22C5";
|
|
1266
|
-
}
|
|
1267
|
-
if (i !== rendersToUse.length - 1) {
|
|
1268
|
-
return "\u22C5\u22C5\u22C5";
|
|
1269
|
-
}
|
|
1270
|
-
return false;
|
|
1271
|
-
} else {
|
|
1272
|
-
return false;
|
|
1273
|
-
}
|
|
1274
|
-
}
|
|
1275
|
-
if (render._mark) {
|
|
1276
|
-
const prevIsLastSnapshotMark = rendersToUse[i - 1]?._lastSnapshotMark;
|
|
1277
|
-
let mark = `${prevIsLastSnapshotMark ? "" : "\n"}>>> ${String(render._mark)}`;
|
|
1278
|
-
const nextRender = rendersToUse[i + 1];
|
|
1279
|
-
if (nextRender && !nextRender._mark && !nextRender._lastSnapshotMark) {
|
|
1280
|
-
mark = `${mark}
|
|
1281
|
-
`;
|
|
1282
|
-
}
|
|
1283
|
-
return mark;
|
|
1284
|
-
}
|
|
1285
|
-
let line = "";
|
|
1286
|
-
for (const [key, _value] of Object.entries(render)) {
|
|
1287
|
-
let value = _value;
|
|
1288
|
-
if (Array.isArray(value)) {
|
|
1289
|
-
if (arrays === "length") {
|
|
1290
|
-
value = `Array(${value.length})`;
|
|
1291
|
-
} else if (arrays === "firstAndLast" && value.length > 2) {
|
|
1292
|
-
const intermediateSize = clampMin(value.length - 2, 0);
|
|
1293
|
-
value = [value[0], `\u2026(${intermediateSize} between)`, value.at(-1)];
|
|
1294
|
-
} else if (typeof arrays === "object" && value.length > 2) {
|
|
1295
|
-
value = [
|
|
1296
|
-
...value.slice(0, arrays.firstNItems),
|
|
1297
|
-
`\u2026(${value.length - arrays.firstNItems} more)`
|
|
1298
|
-
];
|
|
1299
|
-
}
|
|
1300
|
-
}
|
|
1301
|
-
if (typeof value === "boolean" && useEmojiForBooleans) {
|
|
1302
|
-
value = value ? "\u2705" : "\u274C";
|
|
1303
|
-
}
|
|
1304
|
-
if (value === "") {
|
|
1305
|
-
value = `''`;
|
|
1306
|
-
}
|
|
1307
|
-
if (typeof value === "object" && value !== null) {
|
|
1308
|
-
value = JSON.stringify(value).replace(/:true/g, ":\u2705").replace(/:false/g, ":\u274C").replace(/:""/g, ":''").replace(/"/g, "").replace(/,/g, ", ");
|
|
1309
|
-
}
|
|
1310
|
-
line += `${key}: ${value} ${propDivider} `;
|
|
1311
|
-
}
|
|
1312
|
-
line = line.slice(0, (propDivider.length + 2) * -1);
|
|
1313
|
-
if (splitLongLines && line.length > maxLineLengthBeforeSplit) {
|
|
1314
|
-
const parts = line.split(` ${propDivider} `);
|
|
1315
|
-
if (parts.length === 1) {
|
|
1316
|
-
return line;
|
|
1317
|
-
}
|
|
1318
|
-
line = "";
|
|
1319
|
-
const propDividerML = "\u22C5";
|
|
1320
|
-
for (const { item, index } of arrayWithPrevAndIndex(parts)) {
|
|
1321
|
-
if (index === 0) {
|
|
1322
|
-
line += `\u250C\u2500
|
|
1323
|
-
${propDividerML} `;
|
|
1324
|
-
} else if (index === parts.length - 1) {
|
|
1325
|
-
line += `${propDividerML} `;
|
|
1326
|
-
} else {
|
|
1327
|
-
line += `${propDividerML} `;
|
|
1328
|
-
}
|
|
1329
|
-
line += `${item}
|
|
1330
|
-
`;
|
|
1331
|
-
if (index === parts.length - 1) {
|
|
1332
|
-
line += "\u2514\u2500";
|
|
1333
|
-
}
|
|
1334
|
-
}
|
|
1335
|
-
} else {
|
|
1336
|
-
line = `-> ${line}`;
|
|
1337
|
-
}
|
|
1338
|
-
return line;
|
|
1339
|
-
}).join("\n")}
|
|
1340
|
-
`;
|
|
1341
|
-
return snapShot === `
|
|
1342
|
-
\u22C5\u22C5\u22C5
|
|
1343
|
-
` ? "\u22C5\u22C5\u22C5empty\u22C5\u22C5\u22C5" : snapShot;
|
|
1344
|
-
}
|
|
1345
|
-
function addMark(label) {
|
|
1346
|
-
add({ _mark: label });
|
|
1347
|
-
}
|
|
1348
|
-
return {
|
|
1349
|
-
add,
|
|
1350
|
-
reset,
|
|
1351
|
-
getSnapshot,
|
|
1352
|
-
waitNextLog,
|
|
1353
|
-
get changesSnapshot() {
|
|
1354
|
-
return getSnapshot({ changesOnly: true });
|
|
1355
|
-
},
|
|
1356
|
-
get snapshot() {
|
|
1357
|
-
return getSnapshot();
|
|
1358
|
-
},
|
|
1359
|
-
get snapshotFromLast() {
|
|
1360
|
-
return getSnapshot({ fromLastSnapshot: true });
|
|
1361
|
-
},
|
|
1362
|
-
logsCount,
|
|
1363
|
-
get rendersTime() {
|
|
1364
|
-
return logsTime;
|
|
1365
|
-
},
|
|
1366
|
-
addMark
|
|
1367
|
-
};
|
|
1368
|
-
}
|
|
1369
|
-
function getResultFn(fnGetter, wrapper) {
|
|
1370
|
-
return (...args) => {
|
|
1371
|
-
const fn = fnGetter();
|
|
1372
|
-
if (wrapper) {
|
|
1373
|
-
return wrapper(fn(...args));
|
|
1374
|
-
} else {
|
|
1375
|
-
return fn(...args);
|
|
1376
|
-
}
|
|
1377
|
-
};
|
|
1378
|
-
}
|
|
1379
|
-
function waitController() {
|
|
1380
|
-
const { promise, resolve } = defer();
|
|
1381
|
-
return {
|
|
1382
|
-
wait: promise,
|
|
1383
|
-
stopWaiting: () => {
|
|
1384
|
-
resolve();
|
|
1385
|
-
},
|
|
1386
|
-
stopWaitingAfter: (ms) => {
|
|
1387
|
-
setTimeout(() => {
|
|
1388
|
-
resolve();
|
|
1389
|
-
}, ms);
|
|
1390
|
-
}
|
|
1391
|
-
};
|
|
1392
|
-
}
|
|
1393
|
-
function compactSnapshot(value, {
|
|
1394
|
-
collapseObjects = true,
|
|
1395
|
-
maxLineLength = 100,
|
|
1396
|
-
showUndefined = false,
|
|
1397
|
-
showBooleansAs = true,
|
|
1398
|
-
replaceValues,
|
|
1399
|
-
rejectKeys,
|
|
1400
|
-
filterKeys,
|
|
1401
|
-
sortKeys,
|
|
1402
|
-
sortPatterns,
|
|
1403
|
-
...options
|
|
1404
|
-
} = {}) {
|
|
1405
|
-
let processedValue = value;
|
|
1406
|
-
if (rejectKeys || filterKeys) {
|
|
1407
|
-
if (isPlainObject(processedValue) || Array.isArray(processedValue)) {
|
|
1408
|
-
processedValue = filterObjectOrArrayKeys(processedValue, {
|
|
1409
|
-
rejectKeys,
|
|
1410
|
-
filterKeys,
|
|
1411
|
-
sortKeys,
|
|
1412
|
-
sortPatterns
|
|
1413
|
-
});
|
|
1414
|
-
}
|
|
1415
|
-
}
|
|
1416
|
-
if (replaceValues) {
|
|
1417
|
-
processedValue = deepReplaceValues(processedValue, replaceValues);
|
|
1418
|
-
}
|
|
1419
|
-
processedValue = showBooleansAs ? replaceBooleansWithEmoji(processedValue, showBooleansAs) : processedValue;
|
|
1420
|
-
return `
|
|
1421
|
-
${yamlStringify(processedValue, {
|
|
1422
|
-
collapseObjects,
|
|
1423
|
-
maxLineLength,
|
|
1424
|
-
showUndefined,
|
|
1425
|
-
...options
|
|
1426
|
-
})}`;
|
|
1427
|
-
}
|
|
1428
|
-
function replaceBooleansWithEmoji(value, showBooleansAs, visited = /* @__PURE__ */ new Set()) {
|
|
1429
|
-
if (showBooleansAs === false) {
|
|
1430
|
-
return value;
|
|
1431
|
-
}
|
|
1432
|
-
const defaultTrueText = "\u2705";
|
|
1433
|
-
const defaultFalseText = "\u274C";
|
|
1434
|
-
const config = typeof showBooleansAs === "boolean" ? { trueText: defaultTrueText, falseText: defaultFalseText } : {
|
|
1435
|
-
trueText: showBooleansAs.trueText ?? defaultTrueText,
|
|
1436
|
-
falseText: showBooleansAs.falseText ?? defaultFalseText,
|
|
1437
|
-
props: showBooleansAs.props ?? {},
|
|
1438
|
-
ignoreProps: showBooleansAs.ignoreProps ?? []
|
|
1439
|
-
};
|
|
1440
|
-
function processValue(val, propName) {
|
|
1441
|
-
if (typeof val === "boolean") {
|
|
1442
|
-
if (propName && config.ignoreProps?.includes(propName)) {
|
|
1443
|
-
return val;
|
|
1444
|
-
}
|
|
1445
|
-
if (propName && config.props?.[propName]) {
|
|
1446
|
-
const propConfig = config.props[propName];
|
|
1447
|
-
if (propConfig === true) {
|
|
1448
|
-
return val ? config.trueText : config.falseText;
|
|
1449
|
-
}
|
|
1450
|
-
return val ? propConfig.trueText ?? config.trueText : propConfig.falseText ?? config.falseText;
|
|
1451
|
-
}
|
|
1452
|
-
return val ? config.trueText : config.falseText;
|
|
1453
|
-
}
|
|
1454
|
-
if (Array.isArray(val)) {
|
|
1455
|
-
if (visited.has(val)) {
|
|
1456
|
-
throw new Error("Circular reference detected in array");
|
|
1457
|
-
}
|
|
1458
|
-
visited.add(val);
|
|
1459
|
-
try {
|
|
1460
|
-
return val.map((item) => processValue(item));
|
|
1461
|
-
} finally {
|
|
1462
|
-
visited.delete(val);
|
|
1463
|
-
}
|
|
1464
|
-
}
|
|
1465
|
-
if (isPlainObject(val)) {
|
|
1466
|
-
if (visited.has(val)) {
|
|
1467
|
-
throw new Error("Circular reference detected in object");
|
|
1468
|
-
}
|
|
1469
|
-
visited.add(val);
|
|
1470
|
-
try {
|
|
1471
|
-
const result = {};
|
|
1472
|
-
for (const [key, itemValue] of Object.entries(val)) {
|
|
1473
|
-
result[key] = processValue(itemValue, key);
|
|
1474
|
-
}
|
|
1475
|
-
return result;
|
|
1476
|
-
} finally {
|
|
1477
|
-
visited.delete(val);
|
|
1478
|
-
}
|
|
1479
|
-
}
|
|
1480
|
-
return val;
|
|
1481
|
-
}
|
|
1482
|
-
return processValue(value);
|
|
1483
|
-
}
|
|
1484
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
1485
|
-
0 && (module.exports = {
|
|
1486
|
-
compactSnapshot,
|
|
1487
|
-
createLoggerStore,
|
|
1488
|
-
getResultFn,
|
|
1489
|
-
waitController
|
|
1490
|
-
});
|