@cocreate/utils 1.32.0 → 1.33.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 CHANGED
@@ -1,3 +1,16 @@
1
+ # [1.33.0](https://github.com/CoCreate-app/CoCreate-utils/compare/v1.32.0...v1.33.0) (2024-01-30)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * removed sortDataOld ([9755f81](https://github.com/CoCreate-app/CoCreate-utils/commit/9755f815fedd5156ea4a9c2b11b4896c10441424))
7
+ * supput values null, false, undefined, 0 ([954c126](https://github.com/CoCreate-app/CoCreate-utils/commit/954c1262b37c42d8f0badf9fe1c5855f4e244b8e))
8
+
9
+
10
+ ### Features
11
+
12
+ * queryData $type, $mod, $where operators ([94684a0](https://github.com/CoCreate-app/CoCreate-utils/commit/94684a0959fbf353d77ae363b522d5e17f209af0))
13
+
1
14
  # [1.32.0](https://github.com/CoCreate-app/CoCreate-utils/compare/v1.31.0...v1.32.0) (2024-01-17)
2
15
 
3
16
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/utils",
3
- "version": "1.32.0",
3
+ "version": "1.33.0",
4
4
  "description": "A simple utils component in vanilla javascript. Easily configured using HTML5 attributes and/or JavaScript API.",
5
5
  "keywords": [
6
6
  "utils",
package/src/index.js CHANGED
@@ -161,7 +161,7 @@
161
161
 
162
162
  data = data[subpath[i]];
163
163
  if (!data)
164
- return;
164
+ break;
165
165
  }
166
166
 
167
167
  return data;
@@ -556,6 +556,29 @@
556
556
  queryStatus = regex.test(dataValue);
557
557
  }
558
558
  break;
559
+ case '$type':
560
+ let dataType = typeof dataValue;
561
+ if (Array.isArray(dataValue)) {
562
+ dataType = 'array';
563
+ }
564
+ queryStatus = (dataType === queryValue);
565
+ break;
566
+ case '$mod':
567
+ if (typeof dataValue === 'number' && Array.isArray(queryValue) && queryValue.length === 2) {
568
+ const [divisor, remainder] = queryValue;
569
+ queryStatus = (dataValue % divisor === remainder);
570
+ }
571
+ break;
572
+ case '$where':
573
+ if (typeof queryValue === 'function') {
574
+ try {
575
+ // queryStatus = queryValue.call(data);
576
+ } catch (error) {
577
+ console.error('Error in queryData $where function:', error);
578
+ }
579
+ }
580
+ break;
581
+
559
582
  default:
560
583
  console.log('unknown operator')
561
584
  break;
@@ -686,52 +709,6 @@
686
709
  });
687
710
  }
688
711
 
689
- function sortDataOld(data, sort) {
690
- if (!Array.isArray(sort))
691
- sort = [sort]
692
- for (let i = 0; i < sort.length; i++) {
693
- let key = sort[i].key
694
- if (key) {
695
- try {
696
- data.sort((a, b) => {
697
- if (sort[i].direction == 'desc') {
698
- switch (typeof b[key]) {
699
- case 'string':
700
- if (!b[key])
701
- b[key] = ""
702
- return b[key].localeCompare(a[key])
703
- case 'number':
704
- if (!b[key])
705
- b[key] = 0
706
- return b[key] - a[key]
707
- case 'array':
708
- case 'object':
709
- break;
710
- }
711
- } else {
712
- switch (typeof a[key]) {
713
- case 'string':
714
- if (!a[key])
715
- a[key] = ""
716
- return a[key].localeCompare(b[key])
717
- case 'number':
718
- if (!a[key])
719
- a[key] = 0
720
- return a[key] - b[key]
721
- case 'array':
722
- case 'object':
723
- break;
724
- }
725
- }
726
- });
727
- } catch (error) {
728
- console.log(error)
729
- }
730
- }
731
- }
732
- return data;
733
- }
734
-
735
712
  function getAttributes(el) {
736
713
  if (!el) return;
737
714