@fluixi/utils 1.0.0-alpha.100 → 1.0.0-alpha.101
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/index.cjs +1 -1
- package/dist/index.mjs +1 -1
- package/dist/lib/array/advanced.d.ts +0 -4
- package/dist/lib/array/advanced.d.ts.map +1 -1
- package/dist/lib/array/advanced.js +0 -4
- package/dist/lib/array/index.cjs +1 -1
- package/dist/lib/array/index.mjs +1 -1
- package/dist/lib/array/utils.d.ts.map +1 -1
- package/dist/lib/array/utils.js +0 -6
- package/dist/lib/color/conversions.d.ts +0 -103
- package/dist/lib/color/conversions.d.ts.map +1 -1
- package/dist/lib/color/conversions.js +0 -133
- package/dist/lib/color/helpers.d.ts +0 -7
- package/dist/lib/color/helpers.d.ts.map +1 -1
- package/dist/lib/color/helpers.js +0 -7
- package/dist/lib/color/index.cjs +1 -1
- package/dist/lib/color/index.d.ts +0 -5
- package/dist/lib/color/index.d.ts.map +1 -1
- package/dist/lib/color/index.js +0 -5
- package/dist/lib/color/index.mjs +1 -1
- package/dist/lib/color/types.d.ts +0 -10
- package/dist/lib/color/types.d.ts.map +1 -1
- package/dist/lib/color/utils.d.ts +0 -7
- package/dist/lib/color/utils.d.ts.map +1 -1
- package/dist/lib/color/utils.js +0 -99
- package/dist/lib/compare/comparators.js +2 -2
- package/dist/lib/compare/index.cjs +1 -1
- package/dist/lib/compare/index.mjs +1 -1
- package/dist/lib/cookie/index.cjs +1 -1
- package/dist/lib/cookie/index.mjs +1 -1
- package/dist/lib/dom/events.d.ts.map +1 -1
- package/dist/lib/dom/index.cjs +1 -1
- package/dist/lib/dom/index.mjs +1 -1
- package/dist/lib/functions/index.cjs +1 -1
- package/dist/lib/functions/index.mjs +1 -1
- package/dist/lib/index.d.ts.map +1 -1
- package/dist/lib/index.js +0 -3
- package/dist/lib/maths/constants.cjs +1 -1
- package/dist/lib/maths/constants.d.ts +0 -15
- package/dist/lib/maths/constants.d.ts.map +1 -1
- package/dist/lib/maths/constants.js +0 -15
- package/dist/lib/maths/constants.mjs +1 -1
- package/dist/lib/maths/fn/advanced.d.ts.map +1 -1
- package/dist/lib/maths/fn/basic.d.ts.map +1 -1
- package/dist/lib/maths/fn/basic.js +0 -4
- package/dist/lib/maths/fn/index.cjs +1 -1
- package/dist/lib/maths/fn/index.mjs +1 -1
- package/dist/lib/maths/fn/trigo.d.ts.map +1 -1
- package/dist/lib/maths/fn/trigo.js +0 -2
- package/dist/lib/maths/fn/vector.d.ts.map +1 -1
- package/dist/lib/maths/fn/vector.js +0 -4
- package/dist/lib/maths/guards.cjs +1 -1
- package/dist/lib/maths/guards.d.ts.map +1 -1
- package/dist/lib/maths/guards.js +0 -2
- package/dist/lib/maths/guards.mjs +1 -1
- package/dist/lib/maths/index.cjs +1 -1
- package/dist/lib/maths/index.d.ts.map +1 -1
- package/dist/lib/maths/index.js +0 -3
- package/dist/lib/maths/index.mjs +1 -1
- package/dist/lib/maths/types/advanced.d.ts +0 -9
- package/dist/lib/maths/types/advanced.d.ts.map +1 -1
- package/dist/lib/maths/types/basic.d.ts.map +1 -1
- package/dist/lib/maths/types/index.cjs +1 -1
- package/dist/lib/maths/types/index.mjs +1 -1
- package/dist/lib/maths/types/operations.d.ts +0 -3
- package/dist/lib/maths/types/operations.d.ts.map +1 -1
- package/dist/lib/object/clone.d.ts.map +1 -1
- package/dist/lib/object/clone.js +0 -4
- package/dist/lib/object/diff.d.ts +0 -7
- package/dist/lib/object/diff.d.ts.map +1 -1
- package/dist/lib/object/diff.js +0 -8
- package/dist/lib/object/getter-setter.d.ts.map +1 -1
- package/dist/lib/object/getter-setter.js +0 -91
- package/dist/lib/object/index.cjs +1 -1
- package/dist/lib/object/index.mjs +1 -1
- package/dist/lib/object/merge.d.ts.map +1 -1
- package/dist/lib/object/merge.js +0 -22
- package/dist/lib/object/object.d.ts.map +1 -1
- package/dist/lib/object/object.js +0 -116
- package/dist/lib/object/omit.d.ts.map +1 -1
- package/dist/lib/object/omit.js +0 -4
- package/dist/lib/object/selector.d.ts.map +1 -1
- package/dist/lib/object/selector.js +0 -11
- package/dist/lib/object/sort.d.ts.map +1 -1
- package/dist/lib/object/sort.js +3 -4
- package/dist/lib/object/transform.d.ts.map +1 -1
- package/dist/lib/object/transform.js +0 -54
- package/dist/lib/object/types.d.ts +0 -15
- package/dist/lib/object/types.d.ts.map +1 -1
- package/dist/lib/primitive/boolean/boolean.cjs +0 -1
- package/dist/lib/primitive/boolean/boolean.d.ts.map +1 -1
- package/dist/lib/primitive/boolean/boolean.js +0 -5
- package/dist/lib/primitive/boolean/boolean.mjs +0 -1
- package/dist/lib/primitive/boolean/index.cjs +0 -1
- package/dist/lib/primitive/boolean/index.mjs +0 -1
- package/dist/lib/primitive/boolean/types.d.ts +0 -3
- package/dist/lib/primitive/boolean/types.d.ts.map +1 -1
- package/dist/lib/primitive/date/date.d.ts.map +1 -1
- package/dist/lib/primitive/date/date.js +0 -89
- package/dist/lib/primitive/index.cjs +1 -2
- package/dist/lib/primitive/index.mjs +1 -2
- package/dist/lib/primitive/string/parser-2.d.ts.map +1 -1
- package/dist/lib/primitive/string/parser-2.js +0 -11
- package/dist/lib/primitive/string/parser.d.ts.map +1 -1
- package/dist/lib/primitive/string/parser.js +0 -433
- package/dist/lib/primitive/string/string.d.ts.map +1 -1
- package/dist/lib/primitive/string/string.js +0 -96
- package/dist/lib/primitive/string/types.d.ts.map +1 -1
- package/dist/lib/url/parser.d.ts.map +1 -1
- package/dist/lib/url/parser.js +0 -2
- package/dist/tsconfig.lib.tsbuildinfo +1 -1
- package/package.json +1 -1
|
@@ -27,7 +27,6 @@ export function get(obj, selector, options = {}) {
|
|
|
27
27
|
return obj;
|
|
28
28
|
}
|
|
29
29
|
// console.log('try to get', selector)
|
|
30
|
-
// Handle array of selectors
|
|
31
30
|
if (Array.isArray(selector)) {
|
|
32
31
|
if (preserveStructure) {
|
|
33
32
|
// Return an object with all selected paths
|
|
@@ -89,7 +88,6 @@ export function set(_obj, first, second, third, fourth) {
|
|
|
89
88
|
}
|
|
90
89
|
return first;
|
|
91
90
|
}
|
|
92
|
-
// const [first, second, third, fourth, fifth] = params;
|
|
93
91
|
// Pattern 1 & 2: set(obj, "path", value) or set(obj, "path", updateFunction)
|
|
94
92
|
// console.log('set v', first, second, params.length);
|
|
95
93
|
if (params.length === 1) {
|
|
@@ -101,7 +99,6 @@ export function set(_obj, first, second, third, fourth) {
|
|
|
101
99
|
// console.log('is array', [...params[0]])
|
|
102
100
|
// if ([...params[0]].some((v) => v.title === 'S / Red / Nike')) throw new Error('stop')
|
|
103
101
|
if (Array.isArray(obj)) {
|
|
104
|
-
// obj = params[0];
|
|
105
102
|
if (first.length === 0) {
|
|
106
103
|
for (let i = 0; i < obj.length; i++) {
|
|
107
104
|
obj.pop();
|
|
@@ -115,24 +112,16 @@ export function set(_obj, first, second, third, fourth) {
|
|
|
115
112
|
return obj;
|
|
116
113
|
}
|
|
117
114
|
}
|
|
118
|
-
// updateWithCallBack(obj, (value) => );
|
|
119
115
|
}
|
|
120
116
|
else if (typeof params[0] === 'object' && !Array.isArray(params[0])) {
|
|
121
117
|
if (typeof obj === 'object' && !Array.isArray(obj)) {
|
|
122
118
|
applyDiff(obj, params[0], true);
|
|
123
119
|
}
|
|
124
|
-
// if (Array.isArray(obj)) {
|
|
125
|
-
// obj.push(params[0]);
|
|
126
|
-
// } else {
|
|
127
|
-
// obj = { ...obj, ...params[0] };
|
|
128
|
-
// }
|
|
129
|
-
// return updateWithCallBack(obj, (value) => ({ ...value, ...params[0] }));
|
|
130
120
|
}
|
|
131
121
|
else {
|
|
132
122
|
obj = params[0];
|
|
133
123
|
}
|
|
134
124
|
return obj;
|
|
135
|
-
// return updateWithCallBack(obj, (value) => params[0]);
|
|
136
125
|
}
|
|
137
126
|
if (Array.isArray(obj)) {
|
|
138
127
|
if (typeof first === 'string' &&
|
|
@@ -152,9 +141,6 @@ export function set(_obj, first, second, third, fourth) {
|
|
|
152
141
|
return setValueAtPath(obj, first, second);
|
|
153
142
|
}
|
|
154
143
|
}
|
|
155
|
-
// if (Array.isArray(obj) && typeof second === 'object') {
|
|
156
|
-
// console.log('items', obj, first, second);
|
|
157
|
-
// }
|
|
158
144
|
if ((typeof first === 'string' || typeof first === 'number') &&
|
|
159
145
|
(params.length === 2 || params.length === 3)) {
|
|
160
146
|
if (isRangeObject(second)) {
|
|
@@ -169,7 +155,6 @@ export function set(_obj, first, second, third, fourth) {
|
|
|
169
155
|
return setValueAtPath(obj, `[${first}]`, second, third);
|
|
170
156
|
}
|
|
171
157
|
}
|
|
172
|
-
// console.log('len 1', params.length);
|
|
173
158
|
if (typeof second === 'number' && typeof third !== 'undefined') {
|
|
174
159
|
return setValueAtIndex(obj, first, second, third);
|
|
175
160
|
}
|
|
@@ -256,7 +241,6 @@ export function set(_obj, first, second, third, fourth) {
|
|
|
256
241
|
if (params.length === 2 &&
|
|
257
242
|
typeof second === 'object' &&
|
|
258
243
|
!Array.isArray(second)) {
|
|
259
|
-
// Array of selectors with update object
|
|
260
244
|
return setValueWithArraySelectors(obj, first, second);
|
|
261
245
|
}
|
|
262
246
|
else if (params.length === 2) {
|
|
@@ -268,7 +252,6 @@ export function set(_obj, first, second, third, fourth) {
|
|
|
268
252
|
}
|
|
269
253
|
function handleFunctionParams(selector, data, value, isArray = false) {
|
|
270
254
|
const paths = parseSelector(selector);
|
|
271
|
-
// console.log('p', { paths, selector, res: paths[paths.length - 1] });
|
|
272
255
|
if (paths.length === 0)
|
|
273
256
|
return value;
|
|
274
257
|
const isWildcard = paths[paths.length - 1].type === 'wildcard';
|
|
@@ -293,9 +276,6 @@ function handleFunctionParams(selector, data, value, isArray = false) {
|
|
|
293
276
|
if (!isWildcard && !finalValue) {
|
|
294
277
|
finalValue = typeof value === 'function' ? value(data) : value;
|
|
295
278
|
}
|
|
296
|
-
// if (selector === 'person.wife.childs') {
|
|
297
|
-
// console.log('final', { finalValue, data, value });
|
|
298
|
-
// }
|
|
299
279
|
return finalValue;
|
|
300
280
|
}
|
|
301
281
|
/**
|
|
@@ -335,15 +315,11 @@ function isArrayOfString(value) {
|
|
|
335
315
|
* setValueAtPath({ a: { b: { c: 1 } } }, 'a.b.c', (prev) => prev + 1, 'd'); // { a: { b: { c: { d: 2 } } } }
|
|
336
316
|
*/
|
|
337
317
|
export function setValueAtPath(obj, selector, value, subPath) {
|
|
338
|
-
// console.log('set value', selector);
|
|
339
318
|
const paths = parseSelector(selector);
|
|
340
319
|
let target = ValueOfKey(obj, selector, {
|
|
341
320
|
paths,
|
|
342
321
|
createMissing: true,
|
|
343
322
|
});
|
|
344
|
-
// if (selector === 'variantRows') {
|
|
345
|
-
// console.log('set at p', target, value);
|
|
346
|
-
// }
|
|
347
323
|
let get_value;
|
|
348
324
|
if (subPath) {
|
|
349
325
|
if (typeof value === 'function') {
|
|
@@ -352,10 +328,6 @@ export function setValueAtPath(obj, selector, value, subPath) {
|
|
|
352
328
|
}
|
|
353
329
|
const data = subPath ? get_value : target;
|
|
354
330
|
const finalValue = handleFunctionParams(selector, data, value, Array.isArray(obj));
|
|
355
|
-
// console.log('set value at path', {data, finalValue, selector, obj});
|
|
356
|
-
// if (selector === '[*]') {
|
|
357
|
-
// console.log('finalValue', finalValue, selector);
|
|
358
|
-
// }
|
|
359
331
|
if (subPath) {
|
|
360
332
|
const result = setAtPath(obj, `${selector}.${subPath}`, finalValue, {
|
|
361
333
|
createMissing: true,
|
|
@@ -364,11 +336,6 @@ export function setValueAtPath(obj, selector, value, subPath) {
|
|
|
364
336
|
}
|
|
365
337
|
else {
|
|
366
338
|
const r = setAtPath(obj, selector, finalValue, { createMissing: true });
|
|
367
|
-
// if (selector === '[*]') {
|
|
368
|
-
// // console.log('r', r);
|
|
369
|
-
// // console.log('r', obj);
|
|
370
|
-
// }
|
|
371
|
-
// console.log('r', obj);
|
|
372
339
|
return r;
|
|
373
340
|
}
|
|
374
341
|
}
|
|
@@ -391,7 +358,6 @@ export function setValueAtIndex(obj, selector, index, value) {
|
|
|
391
358
|
}
|
|
392
359
|
const target_copy = structuredClone(target);
|
|
393
360
|
const finalValue = handleFunctionParams(selector, target_copy[index], value);
|
|
394
|
-
// console.log('set value at index', {obj, selector, index, finalValue, value, target_copy});
|
|
395
361
|
if (index < 0) {
|
|
396
362
|
// Negative index counts from end
|
|
397
363
|
const actualIndex = target.length + index;
|
|
@@ -420,7 +386,6 @@ export function setValueAtIndex(obj, selector, index, value) {
|
|
|
420
386
|
* console.log(obj); // { a: [1, { b: 4 }, 3] }
|
|
421
387
|
*/
|
|
422
388
|
const setIndexWithSubPath = (obj, selector, index, subPath, value) => {
|
|
423
|
-
// console.log('sub is fn', {obj, selector, index, subPath, value});
|
|
424
389
|
if (typeof subPath === 'function') {
|
|
425
390
|
return setValueAtPath(obj, `${selector}[${index}]`, subPath);
|
|
426
391
|
}
|
|
@@ -537,7 +502,6 @@ export const setValueBetweenRangeWithSubPath = (obj, selector, range, subPath, v
|
|
|
537
502
|
*/
|
|
538
503
|
export function castProps(arr, props) {
|
|
539
504
|
return Object.assign(arr, props);
|
|
540
|
-
// return arr as T;
|
|
541
505
|
}
|
|
542
506
|
/**
|
|
543
507
|
* Sets value for filtered items
|
|
@@ -567,7 +531,6 @@ export function setValueWithFilter(obj, selector, filterFn, value) {
|
|
|
567
531
|
}
|
|
568
532
|
export function setArrayValueWithFilter(obj, filterFn, selector, value) {
|
|
569
533
|
let target = obj;
|
|
570
|
-
// const target = ValueOfKey(obj, selector);
|
|
571
534
|
if (!Array.isArray(target)) {
|
|
572
535
|
throw new Error(`Target at ${selector} is not an array`);
|
|
573
536
|
}
|
|
@@ -578,13 +541,8 @@ export function setArrayValueWithFilter(obj, filterFn, selector, value) {
|
|
|
578
541
|
target.forEach((item, index) => {
|
|
579
542
|
const n = setAtPath(item, selector, value, { createMissing: true });
|
|
580
543
|
item = n;
|
|
581
|
-
// if (filterFn(item, index)) {
|
|
582
|
-
// // console.log('set filter for done', index)
|
|
583
|
-
// indices.push(index);
|
|
584
|
-
// }
|
|
585
544
|
});
|
|
586
545
|
return target;
|
|
587
|
-
// return setValueWithIndices(obj, selector, indices, value);
|
|
588
546
|
}
|
|
589
547
|
/**
|
|
590
548
|
* Sets value for filtered items with sub-path
|
|
@@ -784,7 +742,6 @@ export function ValueOfKey(obj, selector, options = {}) {
|
|
|
784
742
|
}
|
|
785
743
|
}
|
|
786
744
|
else if (createMissing) {
|
|
787
|
-
// const nextSegment = segments[i + 1];
|
|
788
745
|
current = {};
|
|
789
746
|
current[String(segment.value)] =
|
|
790
747
|
nextSegment.type === 'index' ||
|
|
@@ -918,10 +875,6 @@ export const setAtPath = (obj, selector, value, options = {}) => {
|
|
|
918
875
|
nextSegment.type === 'union' ||
|
|
919
876
|
nextSegment.type === 'wildcard';
|
|
920
877
|
if (segment.type === 'property') {
|
|
921
|
-
// if (selector === '[*].meta.count') {
|
|
922
|
-
// console.log('on property first', { selector, current });
|
|
923
|
-
// }
|
|
924
|
-
// Handle numeric property on array as index
|
|
925
878
|
if (Array.isArray(current) && typeof typeof segment.value === 'number') {
|
|
926
879
|
const index = segment.value;
|
|
927
880
|
if (index < 0) {
|
|
@@ -958,10 +911,6 @@ export const setAtPath = (obj, selector, value, options = {}) => {
|
|
|
958
911
|
break;
|
|
959
912
|
}
|
|
960
913
|
else if (segment.type === 'index' || segment.type === 'wildcard') {
|
|
961
|
-
// console.log('ind', current)
|
|
962
|
-
// if (selector === '[*].meta.count') {
|
|
963
|
-
// console.log('on index or wildcard first', { selector, current });
|
|
964
|
-
// }
|
|
965
914
|
if (!Array.isArray(current)) {
|
|
966
915
|
if (!createMissing)
|
|
967
916
|
return obj;
|
|
@@ -995,9 +944,6 @@ export const setAtPath = (obj, selector, value, options = {}) => {
|
|
|
995
944
|
throw new Error(`Invalid segment type for set: ${segment.type}`);
|
|
996
945
|
}
|
|
997
946
|
}
|
|
998
|
-
// if (selector === 'person.wife.childs') {
|
|
999
|
-
// console.log('is array data', { current, value, lastSegment });
|
|
1000
|
-
// }
|
|
1001
947
|
// Set the value
|
|
1002
948
|
switch (lastSegment.type) {
|
|
1003
949
|
case 'property':
|
|
@@ -1027,12 +973,6 @@ export const setAtPath = (obj, selector, value, options = {}) => {
|
|
|
1027
973
|
let ob;
|
|
1028
974
|
if (paths.length >= 2) {
|
|
1029
975
|
paths.shift();
|
|
1030
|
-
// if (Array.isArray(value)) {
|
|
1031
|
-
// }else{
|
|
1032
|
-
// }
|
|
1033
|
-
// if (selector === 'person.wife.childs') {
|
|
1034
|
-
// console.log('is array data', { current, value });
|
|
1035
|
-
// }
|
|
1036
976
|
for (let i = 0; i < current.length; i++) {
|
|
1037
977
|
if (Array.isArray(value)) {
|
|
1038
978
|
ob = fromPath(paths.join('.'), value[i]);
|
|
@@ -1057,14 +997,6 @@ export const setAtPath = (obj, selector, value, options = {}) => {
|
|
|
1057
997
|
}
|
|
1058
998
|
}
|
|
1059
999
|
else {
|
|
1060
|
-
// if (selector === 'person.wife.childs') {
|
|
1061
|
-
// console.log('on property', {
|
|
1062
|
-
// current,
|
|
1063
|
-
// lastSegment,
|
|
1064
|
-
// value,
|
|
1065
|
-
// key: String(lastSegment.value),
|
|
1066
|
-
// });
|
|
1067
|
-
// }
|
|
1068
1000
|
if (Array.isArray(value) && value.length === 0) {
|
|
1069
1001
|
if (typeof current[String(lastSegment.value)] === 'undefined') {
|
|
1070
1002
|
current[String(lastSegment.value)] = [];
|
|
@@ -1084,9 +1016,6 @@ export const setAtPath = (obj, selector, value, options = {}) => {
|
|
|
1084
1016
|
if (!Array.isArray(current)) {
|
|
1085
1017
|
throw new Error(`Cannot use index on non-array for final segment`);
|
|
1086
1018
|
}
|
|
1087
|
-
// if (selector === '[*].meta.count') {
|
|
1088
|
-
// console.log('on index or Wildcard last', { selector, current });
|
|
1089
|
-
// }
|
|
1090
1019
|
const index = lastSegment.value;
|
|
1091
1020
|
if (lastSegment.type === 'index') {
|
|
1092
1021
|
if (index < 0) {
|
|
@@ -1103,19 +1032,10 @@ export const setAtPath = (obj, selector, value, options = {}) => {
|
|
|
1103
1032
|
current[index] = applyDiff(deepClone(current[index]), value[index], true);
|
|
1104
1033
|
}
|
|
1105
1034
|
catch (e) {
|
|
1106
|
-
// console.log('expected on array', {
|
|
1107
|
-
// selector,
|
|
1108
|
-
// current,
|
|
1109
|
-
// value,
|
|
1110
|
-
// index,
|
|
1111
|
-
// });
|
|
1112
|
-
// console.log('current', current);
|
|
1113
1035
|
throw Error('expected on array');
|
|
1114
1036
|
}
|
|
1115
1037
|
}
|
|
1116
1038
|
else {
|
|
1117
|
-
// current[index] = value[index];
|
|
1118
|
-
// setValueAtIndex(current, selector, index, value[index]);
|
|
1119
1039
|
current[index] = value;
|
|
1120
1040
|
}
|
|
1121
1041
|
}
|
|
@@ -1298,7 +1218,6 @@ export const select = (obj, selector, options = {}) => {
|
|
|
1298
1218
|
* @returns True if selector matches at least one value (or array of booleans for array selector)
|
|
1299
1219
|
*/
|
|
1300
1220
|
export const has = (obj, selector, options = {}) => {
|
|
1301
|
-
// Handle array of selectors
|
|
1302
1221
|
if (Array.isArray(selector)) {
|
|
1303
1222
|
return selector.map((sel) => has(obj, sel, options));
|
|
1304
1223
|
}
|
|
@@ -1320,7 +1239,6 @@ export const has = (obj, selector, options = {}) => {
|
|
|
1320
1239
|
*/
|
|
1321
1240
|
export const deletePath = (obj, selector, options = {}) => {
|
|
1322
1241
|
const { throwOnError = false } = options;
|
|
1323
|
-
// Handle array of selectors
|
|
1324
1242
|
if (Array.isArray(selector)) {
|
|
1325
1243
|
return selector.map((sel) => deletePath(obj, sel, options));
|
|
1326
1244
|
}
|
|
@@ -1447,7 +1365,6 @@ const deleteSinglePath = (obj, selector) => {
|
|
|
1447
1365
|
*/
|
|
1448
1366
|
export const getPaths = (obj, selector, options = {}) => {
|
|
1449
1367
|
const { format = 'selector', maxDepth = 20 } = options;
|
|
1450
|
-
// Handle array of selectors
|
|
1451
1368
|
if (selector && Array.isArray(selector)) {
|
|
1452
1369
|
const allPaths = [];
|
|
1453
1370
|
for (const sel of selector) {
|
|
@@ -1462,7 +1379,6 @@ export const getPaths = (obj, selector, options = {}) => {
|
|
|
1462
1379
|
const results = traverseWithPaths(obj, segments, 0, maxDepth);
|
|
1463
1380
|
return results.map((r) => format === 'selector' ? r.path : r.stringPath);
|
|
1464
1381
|
}
|
|
1465
|
-
// Get all paths
|
|
1466
1382
|
const allPaths = [];
|
|
1467
1383
|
const traverseAll = (current, path = [], stringPath = [], depth = 0) => {
|
|
1468
1384
|
if (depth > maxDepth)
|
|
@@ -1542,7 +1458,6 @@ export const flattenWithArrays = (obj, separator = '.') => {
|
|
|
1542
1458
|
traverse(current[key], newPath);
|
|
1543
1459
|
}
|
|
1544
1460
|
}
|
|
1545
|
-
// Handle symbols
|
|
1546
1461
|
const symbols = Object.getOwnPropertySymbols(current);
|
|
1547
1462
|
for (const symbol of symbols) {
|
|
1548
1463
|
const newPath = [
|
|
@@ -1738,12 +1653,6 @@ export const update = (obj, path, updater) => {
|
|
|
1738
1653
|
};
|
|
1739
1654
|
export const updateWithCallBack = (obj, updater) => {
|
|
1740
1655
|
const newValue = updater(obj);
|
|
1741
|
-
// console.log('update trigger', obj, path, newValue)
|
|
1742
|
-
// if(typeof newValue === 'number'){
|
|
1743
|
-
// return setAtPath(obj, path, newValue);
|
|
1744
|
-
// }
|
|
1745
|
-
// return setValueAtPath(obj as any, path as any, newValue as any);
|
|
1746
|
-
// console.log('callback update before', Array.isArray(obj) ? [...obj] : {...obj} , newValue);
|
|
1747
1656
|
const result = applyDiff(obj, newValue, true);
|
|
1748
1657
|
// const result = deepMerge(obj, newValue);
|
|
1749
1658
|
// console.log('callback update', {obj, result, updater, newValue})
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! @fluixi/utils v1.0.0-alpha.
|
|
1
|
+
/*! @fluixi/utils v1.0.0-alpha.101 | (c) 2026 Ibrahima Touré and Fluixi contributors | MIT */
|
|
2
2
|
"use strict";
|
|
3
3
|
var __defProp = Object.defineProperty;
|
|
4
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"merge.d.ts","sourceRoot":"","sources":["../../../src/lib/object/merge.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EACT,aAAa,EACb,YAAY,EACZ,mBAAmB,EACpB,MAAM,YAAY,CAAC;AAMpB;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,KAAK,CAAC,CAAC,SAAS,SAAS,EAAE,EACzC,GAAG,OAAO,EAAE,CAAC,GACZ,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,EAAE,GAAG,aAAa,CAAC,mBAAmB,CAAC,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC;AACzE,wBAAgB,KAAK,CAAC,CAAC,SAAS,GAAG,EAAE,EAAE,EACrC,GAAG,OAAO,EAAE,CAAC,GACZ,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,EAAE,GAAG,aAAa,CAAC,mBAAmB,CAAC,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"merge.d.ts","sourceRoot":"","sources":["../../../src/lib/object/merge.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EACT,aAAa,EACb,YAAY,EACZ,mBAAmB,EACpB,MAAM,YAAY,CAAC;AAMpB;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,KAAK,CAAC,CAAC,SAAS,SAAS,EAAE,EACzC,GAAG,OAAO,EAAE,CAAC,GACZ,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,EAAE,GAAG,aAAa,CAAC,mBAAmB,CAAC,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC;AACzE,wBAAgB,KAAK,CAAC,CAAC,SAAS,GAAG,EAAE,EAAE,EACrC,GAAG,OAAO,EAAE,CAAC,GACZ,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,EAAE,GAAG,aAAa,CAAC,mBAAmB,CAAC,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC;AA2GzE,wBAAgB,WAAW,CAAC,CAAC,EAC3B,IAAI,EAAE,CAAC,EAAE,EACT,IAAI,EAAE,CAAC,EAAE,EACT,OAAO,CAAC,EAAE;IACR,GAAG,CAAC,EAAE,MAAM,CAAC,CAAC;IACd,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB,GACA,CAAC,EAAE,CA+BL;AA0BD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,oBAAoB,CAAC,CAAC,SAAS,MAAM,EACnD,MAAM,EAAE,CAAC,EACT,GAAG,IAAI,EAAE,GAAG,EAAE,GACb,CAAC,CAuJH;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,sBAAsB,CAAC,CAAC,SAAS,MAAM,EACrD,MAAM,EAAE,CAAC,EACT,GAAG,OAAO,EAAE,MAAM,EAAE,GACnB,CAAC,CAIH;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,eAAe,CAAC,CAAC,SAAS,MAAM,EAC9C,MAAM,EAAE,CAAC,EACT,GAAG,IAAI,EAAE,GAAG,EAAE,GACb,CAAC,CAcH;AAED;;;;;;;;GAQG;AACH,eAAO,MAAM,kBAAkB,GAC7B,QAAQ,YAAY,EACpB,UAAU,MAAM,EAChB,OAAO,GAAG,KACT,IAqFF,CAAC;AAGF,OAAO,EACL,sBAAsB,IAAI,SAAS,EACnC,eAAe,IAAI,WAAW,EAC9B,oBAAoB,IAAI,gBAAgB,GACzC,CAAC"}
|
package/dist/lib/object/merge.js
CHANGED
|
@@ -61,7 +61,6 @@ export function merge(...sources) {
|
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
|
-
// Handle symbols
|
|
65
64
|
const symbols = Object.getOwnPropertySymbols(sourceObj);
|
|
66
65
|
for (const symbol of symbols) {
|
|
67
66
|
const value = sourceObj[symbol];
|
|
@@ -147,7 +146,6 @@ function mergeInPlace(target, source) {
|
|
|
147
146
|
sVal &&
|
|
148
147
|
diff.hasChanges) {
|
|
149
148
|
applyDiff(tVal, sVal);
|
|
150
|
-
// mergeInPlace(tVal, sVal);
|
|
151
149
|
}
|
|
152
150
|
else {
|
|
153
151
|
target[key] = sVal;
|
|
@@ -223,27 +221,8 @@ export function deepMergeWithOptions(target, ...args) {
|
|
|
223
221
|
// In non-strict mode, concatenate arrays
|
|
224
222
|
// console.log('pushing', [...resultArray], [...sourceArray])
|
|
225
223
|
mergeInPlace(resultArray, sourceArray);
|
|
226
|
-
// if(sourceArray.length===resultArray.length){
|
|
227
|
-
// for (let i=0; i<sourceArray.length; i++) {
|
|
228
|
-
// const item = sourceArray[i];
|
|
229
|
-
// // const result = resultArray[i];
|
|
230
|
-
// // let index = -1;
|
|
231
|
-
// // if(typeof item === 'object'){
|
|
232
|
-
// // const key = getKey(item);
|
|
233
|
-
// // if(key){
|
|
234
|
-
// // index = resultArray.find(s=>)
|
|
235
|
-
// // }else{
|
|
236
224
|
// // }
|
|
237
225
|
// // }else{
|
|
238
|
-
// // }
|
|
239
|
-
// resultArray.push(deepClone(item));
|
|
240
|
-
// }
|
|
241
|
-
// }else{
|
|
242
|
-
// for (let i=0; i<sourceArray.length; i++) {
|
|
243
|
-
// const item = sourceArray[i]
|
|
244
|
-
// resultArray.push(deepClone(item));
|
|
245
|
-
// }
|
|
246
|
-
// }
|
|
247
226
|
}
|
|
248
227
|
}
|
|
249
228
|
else {
|
|
@@ -289,7 +268,6 @@ export function deepMergeWithOptions(target, ...args) {
|
|
|
289
268
|
resultObj[key] = deepClone(value);
|
|
290
269
|
}
|
|
291
270
|
}
|
|
292
|
-
// Handle symbols
|
|
293
271
|
const symbols = Object.getOwnPropertySymbols(sourceObj);
|
|
294
272
|
for (const symbol of symbols) {
|
|
295
273
|
if (options.strict && !(symbol in resultObj)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"object.d.ts","sourceRoot":"","sources":["../../../src/lib/object/object.ts"],"names":[],"mappings":"AA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AAI,CAAC,SAAS,SAAS,EAC3C,KAAK,CAAC,EACN,aAAa,CAAC,GAAG,EAAE,MAAM,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,MAAM,EAAE,GAAG,CAAC,KAC9D,SAgBF,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,OAAO,GAAI,CAAC,SAAS,SAAS,EACzC,OAAO,CAAC,EAAE,EACV,KAAK,MAAM,CAAC,KACX,MAAM,CAAC,MAAM,GAAG,MAAM,EAAE,CAAC,EAAE,CAqB7B,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,aAAa,GAAI,KAAK,SAAS,KAAG,MAwB9C,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,eAAe,GAAI,aAAa,MAAM,KAAG,SAkCrD,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,UAAU,GAAI,CAAC,EAAE,KAAK,CAAC,KAAG,YAAY,CAAC,CAAC,CA4BpD,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,eAAe,GAAI,OAAO,OAAO,KAAG,KAAK,IAAI,SAEzD,CAAC"}
|
|
@@ -44,22 +44,7 @@ export const invert = (obj, deep = false) => {
|
|
|
44
44
|
* @example
|
|
45
45
|
* mapValues({a: 1, b: 2}, (value) => value * 2) // {a: 2, b: 4}
|
|
46
46
|
*/
|
|
47
|
-
// export const mapValues = <T extends AnyObject, U>(
|
|
48
|
-
// obj: T,
|
|
49
|
-
// callback: (value: T[keyof T], key: keyof T) => U
|
|
50
|
-
// ): Record<keyof T, U> => {
|
|
51
|
-
// if (Array.isArray(obj)) {
|
|
52
|
-
// return (obj as any).map(callback);
|
|
53
|
-
// }
|
|
54
|
-
// if (!isObject(obj)) {
|
|
55
|
-
// return {} as Record<keyof T, U>;
|
|
56
|
-
// }
|
|
57
47
|
// const result: Partial<Record<keyof T, U>> = {};
|
|
58
|
-
// for (const key in obj) {
|
|
59
|
-
// result[key] = callback(obj[key], key as any);
|
|
60
|
-
// }
|
|
61
|
-
// return result as Record<keyof T, U>;
|
|
62
|
-
// };
|
|
63
48
|
/**
|
|
64
49
|
* Maps object keys using a callback function
|
|
65
50
|
* @param obj - Source object
|
|
@@ -68,23 +53,7 @@ export const invert = (obj, deep = false) => {
|
|
|
68
53
|
* @example
|
|
69
54
|
* mapKeys({a: 1, b: 2}, (key) => key.toUpperCase()) // {A: 1, B: 2}
|
|
70
55
|
*/
|
|
71
|
-
// export const mapKeys = <T extends AnyObject>(
|
|
72
|
-
// obj: T,
|
|
73
|
-
// callback: (key: keyof T, value: T[keyof T]) => string
|
|
74
|
-
// ): AnyObject => {
|
|
75
|
-
// if (Array.isArray(obj)) {
|
|
76
|
-
// return (obj as any).map(callback);
|
|
77
|
-
// }
|
|
78
|
-
// if (!isObject(obj)) {
|
|
79
|
-
// return {};
|
|
80
|
-
// }
|
|
81
56
|
// const result: AnyObject = {};
|
|
82
|
-
// for (const key in obj) {
|
|
83
|
-
// const newKey = callback(key as any, obj[key]);
|
|
84
|
-
// result[newKey] = obj[key];
|
|
85
|
-
// }
|
|
86
|
-
// return result;
|
|
87
|
-
// };
|
|
88
57
|
/**
|
|
89
58
|
* Filters object properties using a predicate
|
|
90
59
|
* @param obj - Source object
|
|
@@ -116,47 +85,6 @@ export const filter = (obj, predicate) => {
|
|
|
116
85
|
* @example
|
|
117
86
|
* flatten({a: {b: {c: 1}}, d: 2}) // {'a.b.c': 1, d: 2}
|
|
118
87
|
*/
|
|
119
|
-
// export const flatten = (obj: AnyObject, separator: string = '.'): AnyObject => {
|
|
120
|
-
// if (Array.isArray(obj)) {
|
|
121
|
-
// return obj.map((item) => flatten(item, separator));
|
|
122
|
-
// // return obj.reduce((acc, item) => {
|
|
123
|
-
// // return {
|
|
124
|
-
// // ...acc,
|
|
125
|
-
// // ...flatten(item, separator),
|
|
126
|
-
// // };
|
|
127
|
-
// // }, {});
|
|
128
|
-
// }
|
|
129
|
-
// const result: AnyObject = {};
|
|
130
|
-
// const flattenRecursive = (current: any, path: string = '') => {
|
|
131
|
-
// if (!isObject(current) && !Array.isArray(current)) {
|
|
132
|
-
// if (path) {
|
|
133
|
-
// result[path] = current;
|
|
134
|
-
// }
|
|
135
|
-
// return;
|
|
136
|
-
// }
|
|
137
|
-
// if (Array.isArray(current)) {
|
|
138
|
-
// for (let i = 0; i < current.length; i++) {
|
|
139
|
-
// const newPath = path ? `${path}[${i}]` : `[${i}]`;
|
|
140
|
-
// flattenRecursive(current[i], newPath);
|
|
141
|
-
// }
|
|
142
|
-
// } else {
|
|
143
|
-
// for (const key in current) {
|
|
144
|
-
// const newPath = path ? `${path}${separator}${key}` : key;
|
|
145
|
-
// flattenRecursive(current[key], newPath);
|
|
146
|
-
// }
|
|
147
|
-
// // Handle symbols
|
|
148
|
-
// const symbols = Object.getOwnPropertySymbols(current);
|
|
149
|
-
// for (const symbol of symbols) {
|
|
150
|
-
// const newPath = path
|
|
151
|
-
// ? `${path}${separator}${symbol.toString()}`
|
|
152
|
-
// : symbol.toString();
|
|
153
|
-
// flattenRecursive(current[symbol], newPath);
|
|
154
|
-
// }
|
|
155
|
-
// }
|
|
156
|
-
// };
|
|
157
|
-
// flattenRecursive(obj);
|
|
158
|
-
// return result;
|
|
159
|
-
// };
|
|
160
88
|
/**
|
|
161
89
|
* Unflattens an object (reverse of flatten)
|
|
162
90
|
* @param obj - Source object
|
|
@@ -165,52 +93,8 @@ export const filter = (obj, predicate) => {
|
|
|
165
93
|
* @example
|
|
166
94
|
* unflatten({'a.b.c': 1, d: 2}) // {a: {b: {c: 1}}, d: 2}
|
|
167
95
|
*/
|
|
168
|
-
// export const unflatten = (
|
|
169
|
-
// obj: AnyObject,
|
|
170
|
-
// separator: string = '.'
|
|
171
|
-
// ): AnyObject => {
|
|
172
|
-
// const result: AnyObject = {};
|
|
173
|
-
// for (const key in obj) {
|
|
174
|
-
// const keys = key.split(separator);
|
|
175
|
-
// let current: any = result;
|
|
176
96
|
// for (let i = 0; i < keys.length - 1; i++) {
|
|
177
97
|
// const part = keys[i];
|
|
178
|
-
// // Handle array indices
|
|
179
|
-
// if (part.startsWith('[') && part.endsWith(']')) {
|
|
180
|
-
// const index = parseInt(part.slice(1, -1), 10);
|
|
181
|
-
// if (!Array.isArray(current)) {
|
|
182
|
-
// current = [];
|
|
183
|
-
// }
|
|
184
|
-
// if (current[index] == null) {
|
|
185
|
-
// current[index] = {};
|
|
186
|
-
// }
|
|
187
|
-
// current = current[index];
|
|
188
|
-
// } else {
|
|
189
|
-
// if (current[part] == null) {
|
|
190
|
-
// current[part] = {};
|
|
191
|
-
// }
|
|
192
|
-
// current = current[part];
|
|
193
|
-
// }
|
|
194
|
-
// }
|
|
195
|
-
// const lastKey = keys[keys.length - 1];
|
|
196
|
-
// // Handle array indices
|
|
197
|
-
// if (lastKey.startsWith('[') && lastKey.endsWith(']')) {
|
|
198
|
-
// const index = parseInt(lastKey.slice(1, -1), 10);
|
|
199
|
-
// if (!Array.isArray(current)) {
|
|
200
|
-
// current = [];
|
|
201
|
-
// }
|
|
202
|
-
// if (index >= current.length) {
|
|
203
|
-
// for (let i = current.length; i <= index; i++) {
|
|
204
|
-
// current.push(undefined);
|
|
205
|
-
// }
|
|
206
|
-
// }
|
|
207
|
-
// current[index] = obj[key];
|
|
208
|
-
// } else {
|
|
209
|
-
// current[lastKey] = obj[key];
|
|
210
|
-
// }
|
|
211
|
-
// }
|
|
212
|
-
// return result;
|
|
213
|
-
// };
|
|
214
98
|
/**
|
|
215
99
|
* Removes undefined or null properties from an object
|
|
216
100
|
* @param obj - Source object
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"omit.d.ts","sourceRoot":"","sources":["../../../src/lib/object/omit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAmB,MAAM,YAAY,CAAC;AAMxD;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,IAAI,CAAC,CAAC,SAAS,SAAS,EAAE,CA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AAC,CAAC,EACxB,GAAG,EAAE,CAAC,EACN,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,EACxB,SAAS,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,KAAK,GAAG,GACzD,GAAG,CAqFL;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAC1B,GAAG,EAAE,CAAC,EACN,SAAS,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,KAAK,OAAO,GAC3D,CAAC,CAiCH"}
|
package/dist/lib/object/omit.js
CHANGED
|
@@ -331,7 +331,6 @@ export function pickBy(obj, predicate) {
|
|
|
331
331
|
*/
|
|
332
332
|
export function omitPath(obj, paths, transform) {
|
|
333
333
|
if (!isObject(obj)) {
|
|
334
|
-
// return obj;
|
|
335
334
|
return {};
|
|
336
335
|
}
|
|
337
336
|
// Make a deep clone to avoid modifying original
|
|
@@ -375,7 +374,6 @@ export function omitPath(obj, paths, transform) {
|
|
|
375
374
|
}
|
|
376
375
|
}
|
|
377
376
|
collectPaths(value);
|
|
378
|
-
// Process each path
|
|
379
377
|
for (const { fullPath, segments: pathSegments } of pathsToProcess) {
|
|
380
378
|
const pathSegmentsCopy = [...pathSegments];
|
|
381
379
|
const lastSegment = pathSegmentsCopy.pop();
|
|
@@ -521,7 +519,6 @@ export function pickPath(obj, paths, transform) {
|
|
|
521
519
|
if (!isObject(obj)) {
|
|
522
520
|
return {};
|
|
523
521
|
}
|
|
524
|
-
// Handle array of paths
|
|
525
522
|
if (Array.isArray(paths)) {
|
|
526
523
|
// Create a merged result from all paths
|
|
527
524
|
const result = {};
|
|
@@ -549,7 +546,6 @@ export function pickPath(obj, paths, transform) {
|
|
|
549
546
|
return transform(value, currentPath, obj);
|
|
550
547
|
};
|
|
551
548
|
const transformedValue = transformValue(pathValue, path);
|
|
552
|
-
// Merge into the result
|
|
553
549
|
deepMerge(result, transformedValue);
|
|
554
550
|
}
|
|
555
551
|
else {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"selector.d.ts","sourceRoot":"","sources":["../../../src/lib/object/selector.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,QAAQ,EACR,eAAe,EACf,eAAe,EACf,YAAY,EACb,MAAM,YAAY,CAAC;AAEpB;;;;;;;GAOG;AACH,eAAO,MAAM,aAAa,GACxB,UAAU,MAAM,EAChB,UAAS,eAAoB,KAC5B,eAAe,
|
|
1
|
+
{"version":3,"file":"selector.d.ts","sourceRoot":"","sources":["../../../src/lib/object/selector.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,QAAQ,EACR,eAAe,EACf,eAAe,EACf,YAAY,EACb,MAAM,YAAY,CAAC;AAEpB;;;;;;;GAOG;AACH,eAAO,MAAM,aAAa,GACxB,UAAU,MAAM,EAChB,UAAS,eAAoB,KAC5B,eAAe,EAiNjB,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,GAC/B,MAAM,MAAM,KACX,CAAC,CAAC,IAAI,EAAE,GAAG,KAAK,OAAO,CAazB,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,iBAAiB,GAAI,UAAU,eAAe,EAAE,KAAG,MAsD/D,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,gBAAgB,GAC3B,UAAU,QAAQ,EAClB,UAAS;IAAE,YAAY,CAAC,EAAE,YAAY,EAAE,CAAA;CAAO,KAE7C;IAAE,KAAK,EAAE,OAAO,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,YAAY,CAAA;CAAE,GACvD;IAAE,KAAK,EAAE,OAAO,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,YAAY,CAAA;CAAE,EA+C1D,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,kBAAkB,GAAI,UAAU,MAAM,KAAG,YAUrD,CAAC;AAEF;;;;;;;;;GASG;AACH,eAAO,MAAM,cAAc,GACzB,UAAU,MAAM,EAChB,cAAc,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,KAC5C,MAOF,CAAC"}
|
|
@@ -106,15 +106,9 @@ export const parseSelector = (selector, options = {}) => {
|
|
|
106
106
|
for (let i = 0; i < selector.length; i++) {
|
|
107
107
|
const char = selector[i];
|
|
108
108
|
const nextChar = selector[i + 1];
|
|
109
|
-
// Handle quotes
|
|
110
109
|
if ((char === '"' || char === "'") && !inQuotes) {
|
|
111
110
|
inQuotes = true;
|
|
112
111
|
quoteChar = char;
|
|
113
|
-
// if (inBrackets) {
|
|
114
|
-
// bracketContent += char;
|
|
115
|
-
// } else {
|
|
116
|
-
// current += char;
|
|
117
|
-
// }
|
|
118
112
|
continue;
|
|
119
113
|
}
|
|
120
114
|
else if (char === quoteChar && inQuotes) {
|
|
@@ -190,7 +184,6 @@ export const parseSelector = (selector, options = {}) => {
|
|
|
190
184
|
else {
|
|
191
185
|
const l = selector.split(lastDot?.raw)[1];
|
|
192
186
|
if (l !== undefined) {
|
|
193
|
-
// current = l;
|
|
194
187
|
current = l;
|
|
195
188
|
}
|
|
196
189
|
else {
|
|
@@ -202,14 +195,12 @@ export const parseSelector = (selector, options = {}) => {
|
|
|
202
195
|
if (current) {
|
|
203
196
|
segments.push({ type: 'property', value: current, raw: current });
|
|
204
197
|
}
|
|
205
|
-
// console.log('checking for last', segments);
|
|
206
198
|
// Convert numeric strings in property segments
|
|
207
199
|
return segments.map((segment) => {
|
|
208
200
|
if (segment.type === 'property' && typeof segment.value === 'string') {
|
|
209
201
|
if (/^-?\d+$/.test(segment.value)) {
|
|
210
202
|
const num = parseInt(segment.value, 10);
|
|
211
203
|
if (!isNaN(num)) {
|
|
212
|
-
// return { ...segment, type: 'property', value: String(num) };
|
|
213
204
|
return { ...segment, type: 'index', value: num };
|
|
214
205
|
}
|
|
215
206
|
}
|
|
@@ -291,7 +282,6 @@ export const stringifySelector = (segments) => {
|
|
|
291
282
|
* Checks if selector matches type signature
|
|
292
283
|
*/
|
|
293
284
|
export const validateSelector = (selector, options = {}) => {
|
|
294
|
-
// Handle array of selectors
|
|
295
285
|
if (Array.isArray(selector)) {
|
|
296
286
|
return selector.map((sel) => validateSelector(sel, options));
|
|
297
287
|
}
|
|
@@ -314,7 +304,6 @@ export const validateSelector = (selector, options = {}) => {
|
|
|
314
304
|
try {
|
|
315
305
|
const segments = parseSelector(selector, { throwOnError: true });
|
|
316
306
|
const type = detectSelectorType(selector);
|
|
317
|
-
// console.log('validate', segments, type);
|
|
318
307
|
if (options.allowedTypes) {
|
|
319
308
|
if (!options.allowedTypes.includes(type)) {
|
|
320
309
|
return {
|