@cocreate/utils 1.27.3 → 1.28.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/CHANGELOG.md +15 -0
- package/package.json +1 -1
- package/src/index.js +69 -20
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,18 @@
|
|
|
1
|
+
# [1.28.0](https://github.com/CoCreate-app/CoCreate-utils/compare/v1.27.4...v1.28.0) (2023-11-19)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* update dependecies for th latest features and bug fixes ([a28b912](https://github.com/CoCreate-app/CoCreate-utils/commit/a28b912ccccc9253e99fa6ba7e59f83b797d9ffa))
|
|
7
|
+
|
|
8
|
+
## [1.27.4](https://github.com/CoCreate-app/CoCreate-utils/compare/v1.27.3...v1.27.4) (2023-11-18)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* $in operator support ([891577e](https://github.com/CoCreate-app/CoCreate-utils/commit/891577eb61ba2760b2441f1e031e759242ba5797))
|
|
14
|
+
* improved handeling of $nin operator ([740c98f](https://github.com/CoCreate-app/CoCreate-utils/commit/740c98ff080751d1da83ccadef80d142a42a5ba7))
|
|
15
|
+
|
|
1
16
|
## [1.27.3](https://github.com/CoCreate-app/CoCreate-utils/compare/v1.27.2...v1.27.3) (2023-11-16)
|
|
2
17
|
|
|
3
18
|
|
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -109,14 +109,14 @@
|
|
|
109
109
|
for (let i = 0; i < keys.length; i++) {
|
|
110
110
|
if (/\[([0-9]*)\]/g.test(keys[i])) {
|
|
111
111
|
let [k, index] = keys[i].split('[');
|
|
112
|
-
index = index.slice(0, -1)
|
|
112
|
+
index = index.slice(0, -1) || 0
|
|
113
|
+
newObject[k] = oldObject[k] || [];
|
|
113
114
|
if (length == i) {
|
|
114
115
|
if (value === undefined)
|
|
115
116
|
newObject[k].splice(index, 1);
|
|
116
117
|
else
|
|
117
118
|
newObject[k][index] = value;
|
|
118
119
|
} else {
|
|
119
|
-
newObject[k] = oldObject[k] || [];
|
|
120
120
|
newObject[k][index] = oldObject[k][index] || {};
|
|
121
121
|
newObject = newObject[k][index]
|
|
122
122
|
oldObject = oldObject[k][index]
|
|
@@ -446,8 +446,13 @@
|
|
|
446
446
|
dataValue = ''
|
|
447
447
|
let logicalOperator = query[i].logicalOperator || 'and'
|
|
448
448
|
let queryValues = query[i].value
|
|
449
|
+
|
|
450
|
+
let queryIsArray = false
|
|
449
451
|
if (!Array.isArray(queryValues))
|
|
450
452
|
queryValues = [queryValues]
|
|
453
|
+
else
|
|
454
|
+
queryIsArray = true
|
|
455
|
+
|
|
451
456
|
|
|
452
457
|
let queryStatus = false
|
|
453
458
|
for (let queryValue of queryValues) {
|
|
@@ -462,7 +467,6 @@
|
|
|
462
467
|
dataValue = new Date(dataValue)
|
|
463
468
|
queryValue = new Date(queryValue)
|
|
464
469
|
}
|
|
465
|
-
|
|
466
470
|
switch (query[i].operator) {
|
|
467
471
|
case '$includes':
|
|
468
472
|
case 'includes':
|
|
@@ -478,8 +482,16 @@
|
|
|
478
482
|
queryStatus = true
|
|
479
483
|
break;
|
|
480
484
|
case '$ne':
|
|
481
|
-
|
|
482
|
-
|
|
485
|
+
if (Array.isArray(dataValue)) {
|
|
486
|
+
// Check if the entire array is different from queryValue
|
|
487
|
+
queryStatus = !isEqualArray(dataValue, queryValue);
|
|
488
|
+
} else if (Array.isArray(queryValue)) {
|
|
489
|
+
// If queryValue is an array, check if dataValue is different from this array
|
|
490
|
+
queryStatus = !isEqualArray(queryValue, dataValue);
|
|
491
|
+
} else {
|
|
492
|
+
// If neither is an array, simple comparison
|
|
493
|
+
queryStatus = (dataValue != queryValue);
|
|
494
|
+
}
|
|
483
495
|
break;
|
|
484
496
|
case '$lt':
|
|
485
497
|
if (dataValue < queryValue)
|
|
@@ -498,12 +510,18 @@
|
|
|
498
510
|
queryStatus = true
|
|
499
511
|
break;
|
|
500
512
|
case '$in':
|
|
501
|
-
if (Array.isArray(dataValue)
|
|
502
|
-
queryStatus =
|
|
513
|
+
if (Array.isArray(dataValue)) {
|
|
514
|
+
queryStatus = dataValue.some(element => queryValue.includes(element));
|
|
515
|
+
} else {
|
|
516
|
+
queryStatus = queryValue.includes(dataValue);
|
|
517
|
+
}
|
|
503
518
|
break;
|
|
504
519
|
case '$nin':
|
|
505
|
-
if (
|
|
506
|
-
queryStatus =
|
|
520
|
+
if (Array.isArray(dataValue)) {
|
|
521
|
+
queryStatus = !dataValue.some(element => queryValue.includes(element));
|
|
522
|
+
} else {
|
|
523
|
+
queryStatus = !queryValue.includes(dataValue);
|
|
524
|
+
}
|
|
507
525
|
break;
|
|
508
526
|
case '$range':
|
|
509
527
|
if (queryValue[0] !== null && queryValue[1] !== null) {
|
|
@@ -521,17 +539,19 @@
|
|
|
521
539
|
queryStatus = true
|
|
522
540
|
break;
|
|
523
541
|
}
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
542
|
+
if (!queryIsArray || query[i].operator === "$nin") {
|
|
543
|
+
switch (logicalOperator) {
|
|
544
|
+
case 'and':
|
|
545
|
+
if (queryStatus == false)
|
|
546
|
+
return false
|
|
547
|
+
break;
|
|
548
|
+
// case 'or':
|
|
549
|
+
// if (queryStatus == true)
|
|
550
|
+
// queryResult = queryStatus
|
|
551
|
+
// break;
|
|
552
|
+
}
|
|
553
|
+
} else if (queryStatus && query[i].operator === "$in")
|
|
554
|
+
return true
|
|
535
555
|
queryResult = queryStatus
|
|
536
556
|
}
|
|
537
557
|
}
|
|
@@ -540,6 +560,35 @@
|
|
|
540
560
|
return queryResult;
|
|
541
561
|
}
|
|
542
562
|
|
|
563
|
+
function isEqualArray(arr1, arr2) {
|
|
564
|
+
if (arr1.length !== arr2.length) {
|
|
565
|
+
return false;
|
|
566
|
+
}
|
|
567
|
+
for (let i = 0; i < arr1.length; i++) {
|
|
568
|
+
if (!isEqualObject(arr1[i], arr2[i])) {
|
|
569
|
+
return false;
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
return true;
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
function isEqualObject(obj1, obj2) {
|
|
576
|
+
const keys1 = Object.keys(obj1);
|
|
577
|
+
const keys2 = Object.keys(obj2);
|
|
578
|
+
|
|
579
|
+
if (keys1.length !== keys2.length) {
|
|
580
|
+
return false;
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
for (const key of keys1) {
|
|
584
|
+
if (obj1[key] !== obj2[key]) {
|
|
585
|
+
return false;
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
return true;
|
|
590
|
+
}
|
|
591
|
+
|
|
543
592
|
function searchData(data, search) {
|
|
544
593
|
if (!search)
|
|
545
594
|
return true
|