|
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]
|
|
478 | 478 | queryStatus = true
|
479 | 479 | break;
|
480 | 480 | case '$ne':
|
481 |
| - // if (dataValue != queryValue) |
482 |
| - queryStatus = (dataValue != queryValue) |
| 481 | + if (Array.isArray(dataValue)) { |
| 482 | + // Check if the entire array is different from queryValue |
| 483 | + queryStatus = !isEqualArray(dataValue, queryValue); |
| 484 | + } else if (Array.isArray(queryValue)) { |
| 485 | + // If queryValue is an array, check if dataValue is different from this array |
| 486 | + queryStatus = !isEqualArray(queryValue, dataValue); |
| 487 | + } else { |
| 488 | + // If neither is an array, simple comparison |
| 489 | + queryStatus = (dataValue != queryValue); |
| 490 | + } |
483 | 491 | break;
|
484 | 492 | case '$lt':
|
485 | 493 | if (dataValue < queryValue)
|
|
502 | 510 | queryStatus = true
|
503 | 511 | break;
|
504 | 512 | case '$nin':
|
505 |
| - if (!Array.isArray(dataValue) || !dataValue.some(x => queryValue.includes(x))) |
506 |
| - queryStatus = true |
| 513 | + if (Array.isArray(dataValue)) { |
| 514 | + queryStatus = !dataValue.some(element => queryValue.includes(element)); |
| 515 | + } else { |
| 516 | + queryStatus = !queryValue.includes(dataValue); |
| 517 | + } |
507 | 518 | break;
|
508 | 519 | case '$range':
|
509 | 520 | if (queryValue[0] !== null && queryValue[1] !== null) {
|
|
540 | 551 | return queryResult;
|
541 | 552 | }
|
542 | 553 |
|
| 554 | + function isEqualArray(arr1, arr2) { |
| 555 | + if (arr1.length !== arr2.length) { |
| 556 | + return false; |
| 557 | + } |
| 558 | + for (let i = 0; i < arr1.length; i++) { |
| 559 | + if (!isEqualObject(arr1[i], arr2[i])) { |
| 560 | + return false; |
| 561 | + } |
| 562 | + } |
| 563 | + return true; |
| 564 | + } |
| 565 | + |
| 566 | + function isEqualObject(obj1, obj2) { |
| 567 | + const keys1 = Object.keys(obj1); |
| 568 | + const keys2 = Object.keys(obj2); |
| 569 | + |
| 570 | + if (keys1.length !== keys2.length) { |
| 571 | + return false; |
| 572 | + } |
| 573 | + |
| 574 | + for (const key of keys1) { |
| 575 | + if (obj1[key] !== obj2[key]) { |
| 576 | + return false; |
| 577 | + } |
| 578 | + } |
| 579 | + |
| 580 | + return true; |
| 581 | + } |
| 582 | + |
543 | 583 | function searchData(data, search) {
|
544 | 584 | if (!search)
|
545 | 585 | return true
|
|
0 commit comments