@ls-stack/utils 3.63.0 → 3.66.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 +63 -0
- package/dist/diffParser.mjs +410 -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 -234
- 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/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
|
@@ -0,0 +1,497 @@
|
|
|
1
|
+
import { a as isPlainObject } from "./typeGuards-B1mzA-Rz.mjs";
|
|
2
|
+
import { sortBy } from "./arrayUtils.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/filterObjectOrArrayKeys.ts
|
|
5
|
+
const ID_PROP_REGEXP = /^(id_|key_|id-|key-)|(_id|_key|-id|-key)$/i;
|
|
6
|
+
/**
|
|
7
|
+
* Filters the keys of an object based on the provided patterns.
|
|
8
|
+
*
|
|
9
|
+
* Filtering patterns in `rejectKeys` and `filterKeys`:
|
|
10
|
+
*
|
|
11
|
+
* - `'prop'` - Only root-level properties named 'prop'
|
|
12
|
+
* - `'**prop'` - Any property named exactly 'prop' at any level (root or nested)
|
|
13
|
+
* - `'*.prop'` - Any nested property named 'prop' at second level (excludes
|
|
14
|
+
* root-level matches)
|
|
15
|
+
* - `'test.*.prop'` - Any property named 'prop' at second level of 'test'
|
|
16
|
+
* - `'test.*.test.**prop'` - Any property named 'prop' inside of 'test.*.test'
|
|
17
|
+
* - `'prop.nested'` - Exact nested property paths like `obj.prop.nested`
|
|
18
|
+
* - `'prop.**nested'` - All nested properties inside root `prop` with name
|
|
19
|
+
* `nested`
|
|
20
|
+
* - `'prop[0]'` - The first item of the `prop` array
|
|
21
|
+
* - `'prop[*]'` - All items of the `prop` array
|
|
22
|
+
* - `'prop[0].nested'` - `nested` prop of the first item of the `prop` array
|
|
23
|
+
* - `'prop[*].nested'` - `nested` prop of all items of the `prop` array
|
|
24
|
+
* - `'prop[*]**nested'` - all `nested` props of all items of the `prop` array
|
|
25
|
+
* - `'prop[0-2]'` - The first three items of the `prop` array
|
|
26
|
+
* - `'prop[4-*]'` - All items of the `prop` array from the fourth index to the
|
|
27
|
+
* end
|
|
28
|
+
* - `'prop[0-2].nested.**prop'` - Combining multiple nested patterns is supported
|
|
29
|
+
* - Root array:
|
|
30
|
+
*
|
|
31
|
+
* - `'[0]'` - The first item of the root array
|
|
32
|
+
* - `'[*]'` - All items of the array
|
|
33
|
+
* - `'[0].nested'` - `nested` prop of the first item of the array
|
|
34
|
+
* - `'[*].nested'` - `nested` prop of all items of the array
|
|
35
|
+
* - `'[*]**nested'` - all `nested` props of all items of the array
|
|
36
|
+
* - `'[0-2]'` - The first three items of the array
|
|
37
|
+
* - `'[4-*]'` - All items of the array from the fourth index to the end
|
|
38
|
+
* - Pattern expansion with parentheses:
|
|
39
|
+
*
|
|
40
|
+
* - `'prop.test.(prop1|prop2|prop3)'` - Expands to `prop.test.prop1`,
|
|
41
|
+
* `prop.test.prop2`, and `prop.test.prop3`
|
|
42
|
+
* - `'components[*].(table_id|columns|filters[*].value)'` - Expands to
|
|
43
|
+
* `components[*].table_id`, `components[*].columns`, and
|
|
44
|
+
* `components[*].filters[*].value`
|
|
45
|
+
* - `'(users|admins)[*].name'` - Expands to `users[*].name` and `admins[*].name`
|
|
46
|
+
* - Array filtering by value:
|
|
47
|
+
*
|
|
48
|
+
* - `'users[%name="John"]'` - Filters the `users` with the `name` property equal
|
|
49
|
+
* to `John`
|
|
50
|
+
* - `'users[%name="John" | "Jane"]'` - Value-level OR using `|` for multiple
|
|
51
|
+
* values of same property
|
|
52
|
+
* - `'users[%name="Alice" || %age=35]'` - Property-level OR using `||` for
|
|
53
|
+
* different properties
|
|
54
|
+
* - `'users[%age=30 && %role="admin"]'` - Property-level AND using `&&` for
|
|
55
|
+
* different properties
|
|
56
|
+
* - Note: Mixing `&&` and `||` in the same filter is not supported - use separate
|
|
57
|
+
* filter patterns instead
|
|
58
|
+
* - `'users[%config.name="John" | "Jane"]'` - Dot notation is supported
|
|
59
|
+
* - `'users[%name*="oh"]'` - Contains operator (*=) - filters users where name
|
|
60
|
+
* contains "oh"
|
|
61
|
+
* - `'users[%name^="Jo"]'` - Starts with operator (^=) - filters users where name
|
|
62
|
+
* starts with "Jo"
|
|
63
|
+
* - `'users[%name$="hn"]'` - Ends with operator ($=) - filters users where name
|
|
64
|
+
* ends with "hn"
|
|
65
|
+
* - `'users[%name!="John"]'` - Not equal operator (!=) - filters users where name
|
|
66
|
+
* is not "John"
|
|
67
|
+
* - `'users[%name!*="admin"]'` - Not contains operator (!*=) - filters users
|
|
68
|
+
* where name doesn't contain "admin"
|
|
69
|
+
* - `'users[i%name="john"]'` - Case-insensitive matching (i% prefix) - matches
|
|
70
|
+
* "John", "JOHN", "john", etc.
|
|
71
|
+
*
|
|
72
|
+
* @param objOrArray - The object or array to filter.
|
|
73
|
+
* @param options - The options for the filter.
|
|
74
|
+
* @param options.filterKeys - The keys to filter.
|
|
75
|
+
* @param options.rejectKeys - The keys to reject.
|
|
76
|
+
* @param options.rejectEmptyObjectsInArray - Whether to reject empty objects in
|
|
77
|
+
* arrays (default: true).
|
|
78
|
+
* @param options.sortKeys - Sort all keys by a specific order (optional,
|
|
79
|
+
* preserves original order when not specified).
|
|
80
|
+
* @param options.sortPatterns - Sort specific keys by pattern. Use to control
|
|
81
|
+
* the order of specific properties. The same patterns as `filterKeys` are
|
|
82
|
+
* supported.
|
|
83
|
+
* @returns The filtered object or array.
|
|
84
|
+
*/
|
|
85
|
+
function filterObjectOrArrayKeys(objOrArray, { filterKeys, rejectKeys, rejectEmptyObjectsInArray = true, sortKeys = "simpleValuesFirst", sortPatterns }) {
|
|
86
|
+
function getNestedValue(obj, path) {
|
|
87
|
+
const parts = path.split(".");
|
|
88
|
+
let current = obj;
|
|
89
|
+
for (const part of parts) {
|
|
90
|
+
if (current == null || typeof current !== "object") return;
|
|
91
|
+
current = current[part];
|
|
92
|
+
}
|
|
93
|
+
return current;
|
|
94
|
+
}
|
|
95
|
+
function evaluateCondition(item, condition) {
|
|
96
|
+
const value = getNestedValue(item, condition.property);
|
|
97
|
+
let valueStr = String(value);
|
|
98
|
+
if (condition.caseInsensitive) valueStr = valueStr.toLowerCase();
|
|
99
|
+
const processValue = (v) => condition.caseInsensitive ? v.toLowerCase() : v;
|
|
100
|
+
switch (condition.operator) {
|
|
101
|
+
case "=": return condition.values.some((v) => valueStr === processValue(v));
|
|
102
|
+
case "!=": return condition.values.every((v) => valueStr !== processValue(v));
|
|
103
|
+
case "*=": return condition.values.some((v) => valueStr.includes(processValue(v)));
|
|
104
|
+
case "!*=": return condition.values.every((v) => !valueStr.includes(processValue(v)));
|
|
105
|
+
case "^=": return condition.values.some((v) => valueStr.startsWith(processValue(v)));
|
|
106
|
+
case "!^=": return condition.values.every((v) => !valueStr.startsWith(processValue(v)));
|
|
107
|
+
case "$=": return condition.values.some((v) => valueStr.endsWith(processValue(v)));
|
|
108
|
+
case "!$=": return condition.values.every((v) => !valueStr.endsWith(processValue(v)));
|
|
109
|
+
default: return false;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
const toArray = (v) => v === void 0 ? [] : Array.isArray(v) ? v : [v];
|
|
113
|
+
const filterPatternsRaw = toArray(filterKeys);
|
|
114
|
+
const rejectPatternsRaw = toArray(rejectKeys);
|
|
115
|
+
const hasFilters = filterPatternsRaw.length > 0;
|
|
116
|
+
const hasRejects = rejectPatternsRaw.length > 0;
|
|
117
|
+
const expandedFilterPatterns = filterPatternsRaw.flatMap(expandPatterns);
|
|
118
|
+
const expandedRejectPatterns = rejectPatternsRaw.flatMap(expandPatterns);
|
|
119
|
+
const { filterOnlyPatterns, combinedPatterns } = separateFilterPatterns(expandedFilterPatterns);
|
|
120
|
+
const filterPatterns = filterOnlyPatterns.map(parsePattern);
|
|
121
|
+
const rejectPatterns = expandedRejectPatterns.map(parsePattern);
|
|
122
|
+
const sortPatternsParsed = toArray(sortPatterns).flatMap(expandPatterns).map(parsePattern);
|
|
123
|
+
let dataToProcess = objOrArray;
|
|
124
|
+
if (combinedPatterns.length > 0) {
|
|
125
|
+
const groupedByFilter = /* @__PURE__ */ new Map();
|
|
126
|
+
for (const { filterPart, fieldPart } of combinedPatterns) {
|
|
127
|
+
if (!groupedByFilter.has(filterPart)) groupedByFilter.set(filterPart, []);
|
|
128
|
+
groupedByFilter.get(filterPart).push(fieldPart);
|
|
129
|
+
}
|
|
130
|
+
const combinedResult = Array.isArray(objOrArray) ? [] : {};
|
|
131
|
+
for (const [filterPart, fieldParts] of groupedByFilter) {
|
|
132
|
+
const fieldSelectedResult = filterObjectOrArrayKeys(filterObjectOrArrayKeys(objOrArray, {
|
|
133
|
+
filterKeys: [filterPart],
|
|
134
|
+
rejectKeys,
|
|
135
|
+
rejectEmptyObjectsInArray
|
|
136
|
+
}), {
|
|
137
|
+
filterKeys: fieldParts,
|
|
138
|
+
rejectEmptyObjectsInArray
|
|
139
|
+
});
|
|
140
|
+
if (Array.isArray(combinedResult) && Array.isArray(fieldSelectedResult)) combinedResult.push(...fieldSelectedResult);
|
|
141
|
+
else if (!Array.isArray(combinedResult) && !Array.isArray(fieldSelectedResult)) Object.assign(combinedResult, fieldSelectedResult);
|
|
142
|
+
}
|
|
143
|
+
if (filterOnlyPatterns.length === 0) return combinedResult;
|
|
144
|
+
dataToProcess = combinedResult;
|
|
145
|
+
}
|
|
146
|
+
function matchPath(path, pattern, value) {
|
|
147
|
+
function rec(pi, pti) {
|
|
148
|
+
if (pti >= pattern.length) return pi === path.length;
|
|
149
|
+
const pt = pattern[pti];
|
|
150
|
+
if (pt.type === "WILDCARD_ANY") {
|
|
151
|
+
if (rec(pi, pti + 1)) return true;
|
|
152
|
+
if (pi < path.length) return rec(pi + 1, pti);
|
|
153
|
+
return false;
|
|
154
|
+
}
|
|
155
|
+
if (pt.type === "WILDCARD_ONE") {
|
|
156
|
+
let j = pi;
|
|
157
|
+
let sawKey = false;
|
|
158
|
+
while (j < path.length) {
|
|
159
|
+
if (path[j].type === "KEY") sawKey = true;
|
|
160
|
+
if (sawKey && rec(j, pti + 1)) return true;
|
|
161
|
+
j += 1;
|
|
162
|
+
}
|
|
163
|
+
return false;
|
|
164
|
+
}
|
|
165
|
+
if (pi >= path.length) return false;
|
|
166
|
+
const ct = path[pi];
|
|
167
|
+
switch (pt.type) {
|
|
168
|
+
case "KEY":
|
|
169
|
+
if (ct.type === "KEY" && ct.name === pt.name) return rec(pi + 1, pti + 1);
|
|
170
|
+
if (ct.type === "INDEX") return rec(pi + 1, pti);
|
|
171
|
+
return false;
|
|
172
|
+
case "INDEX":
|
|
173
|
+
if (ct.type === "INDEX" && ct.index === pt.index) return rec(pi + 1, pti + 1);
|
|
174
|
+
return false;
|
|
175
|
+
case "INDEX_ANY":
|
|
176
|
+
if (ct.type === "INDEX") return rec(pi + 1, pti + 1);
|
|
177
|
+
return false;
|
|
178
|
+
case "INDEX_RANGE":
|
|
179
|
+
if (ct.type === "INDEX") {
|
|
180
|
+
const okLower = ct.index >= pt.start;
|
|
181
|
+
const okUpper = pt.end === null ? true : ct.index <= pt.end;
|
|
182
|
+
if (okLower && okUpper) return rec(pi + 1, pti + 1);
|
|
183
|
+
}
|
|
184
|
+
return false;
|
|
185
|
+
case "INDEX_FILTER":
|
|
186
|
+
if (ct.type === "INDEX" && value !== void 0) {
|
|
187
|
+
const results = pt.conditions.map((cond) => evaluateCondition(value, cond));
|
|
188
|
+
if (pt.logic === "AND" ? results.every((r) => r) : results.some((r) => r)) return rec(pi + 1, pti + 1);
|
|
189
|
+
}
|
|
190
|
+
return false;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
return rec(0, 0);
|
|
194
|
+
}
|
|
195
|
+
const matchesAnyFilter = (path, value) => filterPatterns.some((p) => matchPath(path, p, value));
|
|
196
|
+
const matchesAnyReject = (path, value) => rejectPatterns.some((p) => matchPath(path, p, value));
|
|
197
|
+
function getSortPriority(path) {
|
|
198
|
+
for (let i = 0; i < sortPatternsParsed.length; i++) if (matchPath(path, sortPatternsParsed[i])) return i;
|
|
199
|
+
return sortPatternsParsed.length;
|
|
200
|
+
}
|
|
201
|
+
function applySortKeys(keys, obj, sortOrder) {
|
|
202
|
+
if (sortOrder === "asc") return [...keys].sort();
|
|
203
|
+
if (sortOrder === "desc") return [...keys].sort().reverse();
|
|
204
|
+
return sortBy(sortBy(keys, (k) => k), (key) => {
|
|
205
|
+
const value = obj[key];
|
|
206
|
+
if (value !== void 0 && value !== null) {
|
|
207
|
+
if (Array.isArray(value) && value.length === 0) return 0;
|
|
208
|
+
if (isPlainObject(value)) return 1.99 + Object.keys(value).length * -.001;
|
|
209
|
+
if (Array.isArray(value)) if (value.every((item) => typeof item === "string" || typeof item === "number" || typeof item === "boolean" || item === null || item === void 0)) return 1.9 + value.length * -.001;
|
|
210
|
+
else return 1.5 + value.length * -.01;
|
|
211
|
+
if (key === "id" || key === "key") return 5;
|
|
212
|
+
if (ID_PROP_REGEXP.test(key)) return 4.5;
|
|
213
|
+
if (typeof value === "boolean") return 4;
|
|
214
|
+
if (typeof value === "number") return 3.5;
|
|
215
|
+
if (typeof value === "string" && value.length < 20) return 3;
|
|
216
|
+
return 2;
|
|
217
|
+
}
|
|
218
|
+
return 0;
|
|
219
|
+
}, "desc");
|
|
220
|
+
}
|
|
221
|
+
function sortKeysWithPatterns(keys_, obj, currentPath) {
|
|
222
|
+
if (!sortKeys && sortPatternsParsed.length === 0) return keys_;
|
|
223
|
+
let keysToSort = keys_;
|
|
224
|
+
if (sortKeys) keysToSort = applySortKeys(keysToSort, obj, sortKeys);
|
|
225
|
+
return [...keysToSort].sort((a, b) => {
|
|
226
|
+
const pathA = currentPath.concat({
|
|
227
|
+
type: "KEY",
|
|
228
|
+
name: a
|
|
229
|
+
});
|
|
230
|
+
const pathB = currentPath.concat({
|
|
231
|
+
type: "KEY",
|
|
232
|
+
name: b
|
|
233
|
+
});
|
|
234
|
+
const priorityA = getSortPriority(pathA);
|
|
235
|
+
const priorityB = getSortPriority(pathB);
|
|
236
|
+
if (priorityA !== priorityB) return priorityA - priorityB;
|
|
237
|
+
if (sortKeys === "desc") return b.localeCompare(a);
|
|
238
|
+
if (sortKeys === "asc") return a.localeCompare(b);
|
|
239
|
+
return 0;
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
const build = (value, path, allowedByFilter, stack, isRoot, parentIsArray) => {
|
|
243
|
+
if (Array.isArray(value)) {
|
|
244
|
+
if (stack.has(value)) throw new TypeError("Circular references are not supported");
|
|
245
|
+
stack.add(value);
|
|
246
|
+
const out = [];
|
|
247
|
+
const includeAllChildren = allowedByFilter || !hasFilters;
|
|
248
|
+
for (let index = 0; index < value.length; index += 1) {
|
|
249
|
+
const childPath = path.concat({
|
|
250
|
+
type: "INDEX",
|
|
251
|
+
index
|
|
252
|
+
});
|
|
253
|
+
const child = value[index];
|
|
254
|
+
if (hasRejects && matchesAnyReject(childPath, child)) continue;
|
|
255
|
+
const directInclude = hasFilters ? matchesAnyFilter(childPath, child) : true;
|
|
256
|
+
const childAllowed = includeAllChildren || directInclude;
|
|
257
|
+
if (isPlainObject(child) || Array.isArray(child)) {
|
|
258
|
+
const builtChild = build(child, childPath, childAllowed, stack, false, true);
|
|
259
|
+
if (builtChild !== void 0) out.push(builtChild);
|
|
260
|
+
} else if (childAllowed) out.push(child);
|
|
261
|
+
}
|
|
262
|
+
stack.delete(value);
|
|
263
|
+
const filteredOut = rejectEmptyObjectsInArray ? out.filter((item) => !(isPlainObject(item) && Object.keys(item).length === 0)) : out;
|
|
264
|
+
if (filteredOut.length === 0 && !allowedByFilter && !isRoot) return void 0;
|
|
265
|
+
return filteredOut;
|
|
266
|
+
}
|
|
267
|
+
if (isPlainObject(value)) {
|
|
268
|
+
if (stack.has(value)) throw new TypeError("Circular references are not supported");
|
|
269
|
+
stack.add(value);
|
|
270
|
+
const result = {};
|
|
271
|
+
const includeAllChildren = allowedByFilter || !hasFilters;
|
|
272
|
+
const sortedKeys = sortKeysWithPatterns(Object.keys(value), value, path);
|
|
273
|
+
for (const key of sortedKeys) {
|
|
274
|
+
const childPath = path.concat({
|
|
275
|
+
type: "KEY",
|
|
276
|
+
name: key
|
|
277
|
+
});
|
|
278
|
+
if (hasRejects && matchesAnyReject(childPath)) continue;
|
|
279
|
+
const val = value[key];
|
|
280
|
+
const directInclude = hasFilters ? matchesAnyFilter(childPath) : true;
|
|
281
|
+
const childAllowed = includeAllChildren || directInclude;
|
|
282
|
+
if (isPlainObject(val) || Array.isArray(val)) {
|
|
283
|
+
const builtChild = build(val, childPath, childAllowed, stack, false, false);
|
|
284
|
+
if (builtChild === void 0) continue;
|
|
285
|
+
if (Array.isArray(builtChild) && builtChild.length === 0 && !childAllowed) continue;
|
|
286
|
+
if (isPlainObject(builtChild) && Object.keys(builtChild).length === 0 && !childAllowed) continue;
|
|
287
|
+
result[key] = builtChild;
|
|
288
|
+
} else if (childAllowed) result[key] = val;
|
|
289
|
+
}
|
|
290
|
+
stack.delete(value);
|
|
291
|
+
if (Object.keys(result).length === 0 && !allowedByFilter && !isRoot) {
|
|
292
|
+
if (parentIsArray && !rejectEmptyObjectsInArray) return {};
|
|
293
|
+
return;
|
|
294
|
+
}
|
|
295
|
+
return result;
|
|
296
|
+
}
|
|
297
|
+
return allowedByFilter || !hasFilters ? value : void 0;
|
|
298
|
+
};
|
|
299
|
+
const built = build(dataToProcess, [], !hasFilters, /* @__PURE__ */ new WeakSet(), true, false);
|
|
300
|
+
if (built === void 0) return Array.isArray(dataToProcess) ? [] : {};
|
|
301
|
+
return built;
|
|
302
|
+
}
|
|
303
|
+
function parseFilterConditions(filterContent) {
|
|
304
|
+
const conditions = [];
|
|
305
|
+
let logic = "AND";
|
|
306
|
+
const caseInsensitive = filterContent.startsWith("i");
|
|
307
|
+
const content = caseInsensitive ? filterContent.slice(1) : filterContent;
|
|
308
|
+
const hasAnd = content.includes("&&");
|
|
309
|
+
const hasOr = content.includes(" || ");
|
|
310
|
+
if (hasAnd && hasOr) throw new Error("Mixing && and || operators in the same filter is not supported. Use separate filter patterns instead.");
|
|
311
|
+
const andGroups = content.split("&&").map((s) => s.trim());
|
|
312
|
+
for (const andGroup of andGroups) if (andGroup.includes(" || ")) {
|
|
313
|
+
logic = "OR";
|
|
314
|
+
const orConditions = andGroup.split(" || ").map((s) => s.trim());
|
|
315
|
+
for (const orCondition of orConditions) {
|
|
316
|
+
const parsed = parseSingleCondition(orCondition, caseInsensitive);
|
|
317
|
+
if (parsed) conditions.push(parsed);
|
|
318
|
+
}
|
|
319
|
+
} else {
|
|
320
|
+
const parsed = parseSingleCondition(andGroup, caseInsensitive);
|
|
321
|
+
if (parsed) conditions.push(parsed);
|
|
322
|
+
}
|
|
323
|
+
if (conditions.length === 0) return null;
|
|
324
|
+
return {
|
|
325
|
+
type: "INDEX_FILTER",
|
|
326
|
+
conditions,
|
|
327
|
+
logic
|
|
328
|
+
};
|
|
329
|
+
}
|
|
330
|
+
function parseSingleCondition(condition, caseInsensitive = false) {
|
|
331
|
+
const cleanCondition = condition.startsWith("%") ? condition.slice(1) : condition;
|
|
332
|
+
let operator = null;
|
|
333
|
+
let operatorIndex = -1;
|
|
334
|
+
let operatorLength = 0;
|
|
335
|
+
for (const [op, opType] of [
|
|
336
|
+
["!*=", "!*="],
|
|
337
|
+
["!^=", "!^="],
|
|
338
|
+
["!$=", "!$="],
|
|
339
|
+
["!=", "!="],
|
|
340
|
+
["*=", "*="],
|
|
341
|
+
["^=", "^="],
|
|
342
|
+
["$=", "$="],
|
|
343
|
+
["=", "="]
|
|
344
|
+
]) {
|
|
345
|
+
const index = cleanCondition.indexOf(op);
|
|
346
|
+
if (index !== -1) {
|
|
347
|
+
operator = opType;
|
|
348
|
+
operatorIndex = index;
|
|
349
|
+
operatorLength = op.length;
|
|
350
|
+
break;
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
if (operator === null || operatorIndex === -1) return null;
|
|
354
|
+
const property = cleanCondition.slice(0, operatorIndex).trim();
|
|
355
|
+
const valueStr = cleanCondition.slice(operatorIndex + operatorLength).trim();
|
|
356
|
+
const values = [];
|
|
357
|
+
if (valueStr.includes(" | ")) {
|
|
358
|
+
const parts = valueStr.split(" | ");
|
|
359
|
+
for (const part of parts) {
|
|
360
|
+
const trimmed = part.trim();
|
|
361
|
+
const value = trimmed.startsWith("\"") && trimmed.endsWith("\"") ? trimmed.slice(1, -1) : trimmed;
|
|
362
|
+
values.push(value);
|
|
363
|
+
}
|
|
364
|
+
} else {
|
|
365
|
+
const trimmed = valueStr.trim();
|
|
366
|
+
const value = trimmed.startsWith("\"") && trimmed.endsWith("\"") ? trimmed.slice(1, -1) : trimmed;
|
|
367
|
+
values.push(value);
|
|
368
|
+
}
|
|
369
|
+
return {
|
|
370
|
+
property,
|
|
371
|
+
operator,
|
|
372
|
+
values,
|
|
373
|
+
caseInsensitive
|
|
374
|
+
};
|
|
375
|
+
}
|
|
376
|
+
function separateFilterPatterns(patterns) {
|
|
377
|
+
const filterOnlyPatterns = [];
|
|
378
|
+
const combinedPatterns = [];
|
|
379
|
+
for (const pattern of patterns) {
|
|
380
|
+
const filterMatch = pattern.match(/^(.+\[[i%][^[\]]*\])\.(.+)$/);
|
|
381
|
+
if (filterMatch?.[1] && filterMatch[2]) {
|
|
382
|
+
const filterPart = filterMatch[1];
|
|
383
|
+
const fieldPart = filterMatch[2];
|
|
384
|
+
const baseArrayPath = filterPart.replace(/\[[i%][^[\]]*\]/, "[*]");
|
|
385
|
+
combinedPatterns.push({
|
|
386
|
+
filterPart,
|
|
387
|
+
fieldPart: `${baseArrayPath}.${fieldPart}`
|
|
388
|
+
});
|
|
389
|
+
} else filterOnlyPatterns.push(pattern);
|
|
390
|
+
}
|
|
391
|
+
return {
|
|
392
|
+
filterOnlyPatterns,
|
|
393
|
+
combinedPatterns
|
|
394
|
+
};
|
|
395
|
+
}
|
|
396
|
+
function expandPatterns(pattern) {
|
|
397
|
+
function expandSingle(str) {
|
|
398
|
+
const start = str.indexOf("(");
|
|
399
|
+
if (start === -1) return [str];
|
|
400
|
+
const end = str.indexOf(")", start);
|
|
401
|
+
if (end === -1) return [str];
|
|
402
|
+
const before = str.slice(0, start);
|
|
403
|
+
const inside = str.slice(start + 1, end);
|
|
404
|
+
const after = str.slice(end + 1);
|
|
405
|
+
if (!inside.includes("|")) return expandSingle(before + inside + after);
|
|
406
|
+
const options = inside.split("|").filter((option) => option.trim().length > 0);
|
|
407
|
+
const results = [];
|
|
408
|
+
for (const option of options) {
|
|
409
|
+
const newStr = before + option + after;
|
|
410
|
+
results.push(...expandSingle(newStr));
|
|
411
|
+
}
|
|
412
|
+
return results;
|
|
413
|
+
}
|
|
414
|
+
return expandSingle(pattern);
|
|
415
|
+
}
|
|
416
|
+
function parsePattern(pattern) {
|
|
417
|
+
const tokens = [];
|
|
418
|
+
let i = 0;
|
|
419
|
+
const n = pattern.length;
|
|
420
|
+
const pushKey = (name) => {
|
|
421
|
+
if (name.length === 0) return;
|
|
422
|
+
tokens.push({
|
|
423
|
+
type: "KEY",
|
|
424
|
+
name
|
|
425
|
+
});
|
|
426
|
+
};
|
|
427
|
+
while (i < n) {
|
|
428
|
+
const ch = pattern[i];
|
|
429
|
+
if (ch === ".") {
|
|
430
|
+
i += 1;
|
|
431
|
+
continue;
|
|
432
|
+
}
|
|
433
|
+
if (ch === "[") {
|
|
434
|
+
const end = pattern.indexOf("]", i + 1);
|
|
435
|
+
const inside = end === -1 ? pattern.slice(i + 1) : pattern.slice(i + 1, end);
|
|
436
|
+
if (inside.startsWith("%") || inside.startsWith("i%")) {
|
|
437
|
+
let filterContent;
|
|
438
|
+
if (inside.startsWith("i%")) filterContent = `i${inside.slice(2)}`;
|
|
439
|
+
else if (inside.startsWith("%")) filterContent = inside.slice(1);
|
|
440
|
+
else filterContent = inside;
|
|
441
|
+
const filterToken = parseFilterConditions(filterContent);
|
|
442
|
+
if (filterToken) tokens.push(filterToken);
|
|
443
|
+
} else if (inside === "*") tokens.push({ type: "INDEX_ANY" });
|
|
444
|
+
else if (inside.includes("-")) {
|
|
445
|
+
const parts = inside.split("-");
|
|
446
|
+
const startStr = parts[0] ?? "";
|
|
447
|
+
const endStr = parts[1] ?? "";
|
|
448
|
+
const start = parseInt(startStr, 10);
|
|
449
|
+
const endNum = endStr === "*" ? null : parseInt(endStr, 10);
|
|
450
|
+
tokens.push({
|
|
451
|
+
type: "INDEX_RANGE",
|
|
452
|
+
start,
|
|
453
|
+
end: endNum === null || Number.isFinite(endNum) ? endNum : null
|
|
454
|
+
});
|
|
455
|
+
} else if (inside.length > 0) {
|
|
456
|
+
const idx = parseInt(inside, 10);
|
|
457
|
+
tokens.push({
|
|
458
|
+
type: "INDEX",
|
|
459
|
+
index: idx
|
|
460
|
+
});
|
|
461
|
+
}
|
|
462
|
+
i = end === -1 ? n : end + 1;
|
|
463
|
+
continue;
|
|
464
|
+
}
|
|
465
|
+
if (ch === "*") if (pattern[i + 1] === "*") {
|
|
466
|
+
tokens.push({ type: "WILDCARD_ANY" });
|
|
467
|
+
i += 2;
|
|
468
|
+
let j$1 = i;
|
|
469
|
+
while (j$1 < n) {
|
|
470
|
+
const c = pattern[j$1];
|
|
471
|
+
if (c === "." || c === "[") break;
|
|
472
|
+
j$1 += 1;
|
|
473
|
+
}
|
|
474
|
+
if (j$1 > i) {
|
|
475
|
+
pushKey(pattern.slice(i, j$1));
|
|
476
|
+
i = j$1;
|
|
477
|
+
}
|
|
478
|
+
continue;
|
|
479
|
+
} else {
|
|
480
|
+
tokens.push({ type: "WILDCARD_ONE" });
|
|
481
|
+
i += 1;
|
|
482
|
+
continue;
|
|
483
|
+
}
|
|
484
|
+
let j = i;
|
|
485
|
+
while (j < n) {
|
|
486
|
+
const c = pattern[j];
|
|
487
|
+
if (c === "." || c === "[") break;
|
|
488
|
+
j += 1;
|
|
489
|
+
}
|
|
490
|
+
pushKey(pattern.slice(i, j));
|
|
491
|
+
i = j;
|
|
492
|
+
}
|
|
493
|
+
return tokens;
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
//#endregion
|
|
497
|
+
export { filterObjectOrArrayKeys };
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
//#region src/getAutoIncrementId.d.ts
|
|
1
2
|
/**
|
|
2
3
|
* Returns a unique auto-incrementing number each time it's called. This is
|
|
3
4
|
* useful for generating simple unique identifiers within a single
|
|
@@ -38,9 +39,12 @@ declare function getAutoIncrementId(): number;
|
|
|
38
39
|
* @param options.suffix - Optional suffix to append to each generated ID
|
|
39
40
|
* @returns A function that generates formatted auto-increment IDs
|
|
40
41
|
*/
|
|
41
|
-
declare function getLocalAutoIncrementIdGenerator({
|
|
42
|
-
|
|
43
|
-
|
|
42
|
+
declare function getLocalAutoIncrementIdGenerator({
|
|
43
|
+
prefix,
|
|
44
|
+
suffix
|
|
45
|
+
}: {
|
|
46
|
+
prefix?: string;
|
|
47
|
+
suffix?: string;
|
|
44
48
|
}): () => string;
|
|
45
|
-
|
|
46
|
-
export { getAutoIncrementId, getLocalAutoIncrementIdGenerator };
|
|
49
|
+
//#endregion
|
|
50
|
+
export { getAutoIncrementId, getLocalAutoIncrementIdGenerator };
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
//#region src/getAutoIncrementId.ts
|
|
2
|
+
let id = 1;
|
|
3
|
+
/**
|
|
4
|
+
* Returns a unique auto-incrementing number each time it's called. This is
|
|
5
|
+
* useful for generating simple unique identifiers within a single
|
|
6
|
+
* session/process.
|
|
7
|
+
*
|
|
8
|
+
* **Note:** This is not suitable for distributed systems or persistent storage.
|
|
9
|
+
* For cryptographically secure or collision-resistant IDs, use `nanoid()`
|
|
10
|
+
* instead.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* const id1 = getAutoIncrementId(); // 1
|
|
15
|
+
* const id2 = getAutoIncrementId(); // 2
|
|
16
|
+
* const id3 = getAutoIncrementId(); // 3
|
|
17
|
+
* ```;
|
|
18
|
+
*
|
|
19
|
+
* @returns A unique incrementing number starting from 1
|
|
20
|
+
*/
|
|
21
|
+
function getAutoIncrementId() {
|
|
22
|
+
return id++;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Creates a local auto-increment ID generator with optional prefix and suffix.
|
|
26
|
+
* Each generator maintains its own independent counter starting from 1. This is
|
|
27
|
+
* useful when you need multiple independent ID sequences or formatted IDs.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```ts
|
|
31
|
+
* const userIdGen = getLocalAutoIncrementIdGenerator({ prefix: 'user-' });
|
|
32
|
+
* const postIdGen = getLocalAutoIncrementIdGenerator({ prefix: 'post-', suffix: '-draft' });
|
|
33
|
+
*
|
|
34
|
+
* console.log(userIdGen()); // "user-1"
|
|
35
|
+
* console.log(userIdGen()); // "user-2"
|
|
36
|
+
* console.log(postIdGen()); // "post-1-draft"
|
|
37
|
+
* console.log(postIdGen()); // "post-2-draft"
|
|
38
|
+
* ```;
|
|
39
|
+
*
|
|
40
|
+
* @param options - Configuration object
|
|
41
|
+
* @param options.prefix - Optional prefix to prepend to each generated ID
|
|
42
|
+
* @param options.suffix - Optional suffix to append to each generated ID
|
|
43
|
+
* @returns A function that generates formatted auto-increment IDs
|
|
44
|
+
*/
|
|
45
|
+
function getLocalAutoIncrementIdGenerator({ prefix, suffix }) {
|
|
46
|
+
let localId = 1;
|
|
47
|
+
return () => {
|
|
48
|
+
return `${prefix || ""}${localId++}${suffix || ""}`;
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
//#endregion
|
|
53
|
+
export { getAutoIncrementId, getLocalAutoIncrementIdGenerator };
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
//#region src/getCompositeKey.d.ts
|
|
1
2
|
/**
|
|
2
3
|
* Returns a stable key for the input value.
|
|
3
4
|
*
|
|
@@ -7,5 +8,5 @@
|
|
|
7
8
|
* @returns A stable key for the input value.
|
|
8
9
|
*/
|
|
9
10
|
declare function getCompositeKey(input: unknown, maxSortingDepth?: number): string;
|
|
10
|
-
|
|
11
|
-
export { getCompositeKey };
|
|
11
|
+
//#endregion
|
|
12
|
+
export { getCompositeKey };
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { o as isObject } from "./assertions-qMxfVhSu.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/getCompositeKey.ts
|
|
4
|
+
/**
|
|
5
|
+
* Returns a stable key for the input value.
|
|
6
|
+
*
|
|
7
|
+
* @param input - The value to get a stable key for.
|
|
8
|
+
* @param maxSortingDepth - The maximum depth to sort the input value. Default
|
|
9
|
+
* is 3.
|
|
10
|
+
* @returns A stable key for the input value.
|
|
11
|
+
*/
|
|
12
|
+
function getCompositeKey(input, maxSortingDepth = 3) {
|
|
13
|
+
if (typeof input === "string") return `"${input}`;
|
|
14
|
+
if (!input || typeof input !== "object") return `$${input}`;
|
|
15
|
+
return stringifyCompact(input, maxSortingDepth, 0, /* @__PURE__ */ new WeakSet());
|
|
16
|
+
}
|
|
17
|
+
function stringifyCompact(input, maxSortingDepth, depth, refs) {
|
|
18
|
+
const isJsObj = input && typeof input === "object";
|
|
19
|
+
if (isJsObj) {
|
|
20
|
+
if (refs.has(input)) throw new Error("Circular reference detected");
|
|
21
|
+
refs.add(input);
|
|
22
|
+
}
|
|
23
|
+
let result;
|
|
24
|
+
if (Array.isArray(input)) {
|
|
25
|
+
result = "[";
|
|
26
|
+
for (const v of input) {
|
|
27
|
+
if (result.length > 1) result += ",";
|
|
28
|
+
result += stringifyCompact(v, maxSortingDepth, depth + 1, refs);
|
|
29
|
+
}
|
|
30
|
+
result += "]";
|
|
31
|
+
} else if (isObject(input)) {
|
|
32
|
+
let entries = Object.entries(input);
|
|
33
|
+
if (entries.length === 0) result = "{}";
|
|
34
|
+
else {
|
|
35
|
+
if (depth < maxSortingDepth) entries = entries.sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0);
|
|
36
|
+
result = "{";
|
|
37
|
+
for (const [k, v] of entries) {
|
|
38
|
+
if (v === void 0) continue;
|
|
39
|
+
if (result.length > 1) result += ",";
|
|
40
|
+
result += `${k}:${stringifyCompact(v, maxSortingDepth, depth + 1, refs)}`;
|
|
41
|
+
}
|
|
42
|
+
result += "}";
|
|
43
|
+
}
|
|
44
|
+
} else result = JSON.stringify(input);
|
|
45
|
+
if (isJsObj) refs.delete(input);
|
|
46
|
+
return result;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
//#endregion
|
|
50
|
+
export { getCompositeKey };
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import { getCompositeKey } from
|
|
1
|
+
import { getCompositeKey } from "./getCompositeKey.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/getValueStableKey.d.ts
|
|
2
4
|
|
|
3
5
|
/**
|
|
4
6
|
* Returns a stable key for the input value.
|
|
@@ -11,5 +13,5 @@ import { getCompositeKey } from './getCompositeKey.cjs';
|
|
|
11
13
|
* @returns A stable key for the input value.
|
|
12
14
|
*/
|
|
13
15
|
declare const getValueStableKey: typeof getCompositeKey;
|
|
14
|
-
|
|
15
|
-
export { getValueStableKey };
|
|
16
|
+
//#endregion
|
|
17
|
+
export { getValueStableKey };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { getCompositeKey } from "./getCompositeKey.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/getValueStableKey.ts
|
|
4
|
+
/**
|
|
5
|
+
* Returns a stable key for the input value.
|
|
6
|
+
*
|
|
7
|
+
* @deprecated Use `getCompositeKey` from `@ls-stack/utils/getCompositeKey`
|
|
8
|
+
* instead.
|
|
9
|
+
* @param input - The value to get a stable key for.
|
|
10
|
+
* @param maxSortingDepth - The maximum depth to sort the input value. Default
|
|
11
|
+
* is 3.
|
|
12
|
+
* @returns A stable key for the input value.
|
|
13
|
+
*/
|
|
14
|
+
const getValueStableKey = getCompositeKey;
|
|
15
|
+
|
|
16
|
+
//#endregion
|
|
17
|
+
export { getValueStableKey };
|