@cocreate/utils 1.26.2 → 1.27.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,17 @@
1
+ # [1.27.0](https://github.com/CoCreate-app/CoCreate-utils/compare/v1.26.2...v1.27.0) (2023-11-03)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * favicon.ico path ([4474c25](https://github.com/CoCreate-app/CoCreate-utils/commit/4474c25089a0953c6d24264152fe3b9d690dce25))
7
+ * update dependencies to the lates versions ([d0bd60b](https://github.com/CoCreate-app/CoCreate-utils/commit/d0bd60bb21b2f555ddee0412861a9e7510173fb7))
8
+
9
+
10
+ ### Features
11
+
12
+ * checkMediaQuries ([f9322d2](https://github.com/CoCreate-app/CoCreate-utils/commit/f9322d26261a4ee7007064115c86303a78534034))
13
+ * isValidDate converts date to system local date ([4519b7c](https://github.com/CoCreate-app/CoCreate-utils/commit/4519b7ce2b2d739bd9c76dd0605f91c41837d7d0))
14
+
1
15
  ## [1.26.2](https://github.com/CoCreate-app/CoCreate-utils/compare/v1.26.1...v1.26.2) (2023-10-25)
2
16
 
3
17
 
package/demo/index.html CHANGED
@@ -6,9 +6,9 @@
6
6
  <!-- CoCreate Favicon -->
7
7
  <link
8
8
  rel="icon"
9
- href="https://cdn.cocreate.app/favicon.ico"
10
- type="image/ico"
11
- sizes="16x16" />
9
+ type="image/png"
10
+ sizes="32x32"
11
+ href="../assets/favicon.ico" />
12
12
  <!-- CoCreate CSS CDN -->
13
13
  <link
14
14
  rel="stylesheet"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/utils",
3
- "version": "1.26.2",
3
+ "version": "1.27.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
@@ -88,21 +88,19 @@
88
88
  }
89
89
 
90
90
  function isValidDate(value) {
91
- // Check if the value is a string and can be converted to a Date object
92
- if (typeof value === 'string'
93
- && !isNaN(value)
94
- && !(/^[0-9a-fA-F]{24}$/.test(value))
95
- && !(/^(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d{1,3})?Z|Mon|Tue|Wed|Thu|Fri|Sat|Sun [A-Za-z]{3} \d{2} \d{4} \d{2}:\d{2}:\d{2} [A-Za-z]{3} \+\d{4}|\d{4}\/\d{2}\/\d{2} \d{2}:\d{2}:\d{2}(\.\d{1,3})?|\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}(\.\d{1,3})?|\d{4}\/\d{2}\/\d{2} \d{2}:\d{2}:\d{2}(\.\d{1,3})?|Sun|Mon|Tue|Wed|Thu|Fri|Sat),? .+$/.test(value))
96
- ) {
97
- const dateObject = new Date(value);
98
-
99
- // Check if the result of the Date constructor is a valid Date object
100
- if (!isNaN(dateObject) && dateObject.toString() !== 'Invalid Date') {
101
- return dateObject; // It's a valid Date object
91
+ if (typeof value === 'string' && value.length >= 20 && value.length <= 24) {
92
+ const iso8601Regex = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d{1,3})?Z$/i;
93
+ if (iso8601Regex.test(value)) {
94
+ const dateObject = new Date(value);
95
+ dateObject.setUTCHours(dateObject.getUTCHours(), 0, 0, 0);
96
+ if (!isNaN(dateObject)) {
97
+ return dateObject; // Is a valid date object and now utc
98
+ }
102
99
  }
103
100
  }
104
101
 
105
- return value; // It's not a valid Date object
102
+ return value; // Is a valid date object adjusted to UTC time
103
+
106
104
  }
107
105
 
108
106
  function dotNotationToObject(data, obj = {}) {
@@ -308,6 +306,12 @@
308
306
 
309
307
  let selectors = Selector.split(',');
310
308
  for (let j = 0; j < selectors.length; j++) {
309
+ if (selectors[j].includes('@')) {
310
+ selectors[j] = checkMediaQueries(selectors[j])
311
+ if (selectors[j] === false)
312
+ continue
313
+ }
314
+
311
315
  let queriedElement = element
312
316
  let specialSelectors = selectors[j].split(';')
313
317
  for (let k = 0; k < specialSelectors.length; k++) {
@@ -385,6 +389,41 @@
385
389
  return elements
386
390
  }
387
391
 
392
+ const mediaRanges = {
393
+ xs: [0, 575],
394
+ sm: [576, 768],
395
+ md: [769, 992],
396
+ lg: [993, 1200],
397
+ xl: [1201, 0],
398
+ };
399
+
400
+ function checkMediaQueries(selector) {
401
+ if (selector && selector.includes('@')) {
402
+ let screenSizes = selector.split('@')
403
+ selector = screenSizes.shift();
404
+ for (let screenSize of screenSizes) {
405
+ const viewportWidth = window.innerWidth;
406
+ let mediaViewport = false;
407
+
408
+ // Check if screenSize is a valid range in the 'ranges' object
409
+ if (mediaRanges.hasOwnProperty(screenSize)) {
410
+ const [minWidth, maxWidth] = mediaRanges[screenSize];
411
+ if (viewportWidth >= minWidth && viewportWidth <= maxWidth) {
412
+ mediaViewport = true;
413
+ break;
414
+ }
415
+ }
416
+
417
+ if (!mediaViewport)
418
+ return false
419
+
420
+ }
421
+ }
422
+
423
+ return selector
424
+ }
425
+
426
+
388
427
  function queryData(data, query) {
389
428
  if (!data)
390
429
  return false;
@@ -424,6 +463,9 @@
424
463
  queryValue = queryValue.toLowerCase()
425
464
  }
426
465
 
466
+ dataValue = isValidDate(dataValue)
467
+ queryValue = isValidDate(queryValue)
468
+
427
469
  switch (query[i].operator) {
428
470
  case '$includes':
429
471
  case 'includes':
@@ -443,19 +485,19 @@
443
485
  queryStatus = true
444
486
  break;
445
487
  case '$lt':
446
- if (dataValue > queryValue)
488
+ if (dataValue < queryValue)
447
489
  queryStatus = true
448
490
  break;
449
491
  case '$lte':
450
- if (dataValue >= queryValue)
492
+ if (dataValue <= queryValue)
451
493
  queryStatus = true
452
494
  break;
453
495
  case '$gt':
454
- if (dataValue < queryValue)
496
+ if (dataValue > queryValue)
455
497
  queryStatus = true
456
498
  break;
457
499
  case '$gte':
458
- if (dataValue <= queryValue)
500
+ if (dataValue >= queryValue)
459
501
  queryStatus = true
460
502
  break;
461
503
  case '$in':
@@ -667,6 +709,7 @@
667
709
  escapeHtml,
668
710
  cssPath,
669
711
  queryElements,
712
+ checkMediaQueries,
670
713
  queryData,
671
714
  searchData,
672
715
  sortData,