@cocreate/utils 1.26.2 → 1.27.1

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,26 @@
1
+ ## [1.27.1](https://github.com/CoCreate-app/CoCreate-utils/compare/v1.27.0...v1.27.1) (2023-11-09)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * meta name typo ([e629a89](https://github.com/CoCreate-app/CoCreate-utils/commit/e629a89c8a3943d9ef8eaa891f41756cd766e6bb))
7
+ * ObjectId use new Date(new Date().toISOString()).getTime() instead of date.now() preventing 24 possible collisions in a day ([89236e5](https://github.com/CoCreate-app/CoCreate-utils/commit/89236e534d958399827f7ad0fa9345bdecc06497))
8
+ * update host ([d234c14](https://github.com/CoCreate-app/CoCreate-utils/commit/d234c1459da3064105ba50cfef9bbdb0fe484cd9))
9
+
10
+ # [1.27.0](https://github.com/CoCreate-app/CoCreate-utils/compare/v1.26.2...v1.27.0) (2023-11-03)
11
+
12
+
13
+ ### Bug Fixes
14
+
15
+ * favicon.ico path ([4474c25](https://github.com/CoCreate-app/CoCreate-utils/commit/4474c25089a0953c6d24264152fe3b9d690dce25))
16
+ * update dependencies to the lates versions ([d0bd60b](https://github.com/CoCreate-app/CoCreate-utils/commit/d0bd60bb21b2f555ddee0412861a9e7510173fb7))
17
+
18
+
19
+ ### Features
20
+
21
+ * checkMediaQuries ([f9322d2](https://github.com/CoCreate-app/CoCreate-utils/commit/f9322d26261a4ee7007064115c86303a78534034))
22
+ * isValidDate converts date to system local date ([4519b7c](https://github.com/CoCreate-app/CoCreate-utils/commit/4519b7ce2b2d739bd9c76dd0605f91c41837d7d0))
23
+
1
24
  ## [1.26.2](https://github.com/CoCreate-app/CoCreate-utils/compare/v1.26.1...v1.26.2) (2023-10-25)
2
25
 
3
26
 
@@ -12,8 +12,7 @@ module.exports = {
12
12
  "pathname": "/docs/utils/index.html",
13
13
  "src": "{{./docs/index.html}}",
14
14
  "host": [
15
- "*",
16
- "general.cocreate.app"
15
+ "*"
17
16
  ],
18
17
  "directory": "utils",
19
18
  "content-type": "{{content-type}}",
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/docs/index.html CHANGED
@@ -11,10 +11,10 @@
11
11
  sizes="32x32"
12
12
  href="https://cocreate.app/images/favicon.ico" />
13
13
  <meta
14
- key="description"
14
+ name="description"
15
15
  content="A simple HTML5 and pure javascript component. Easy configuration using HTML5 attributes or Javscript api and highly styleable." />
16
16
  <meta
17
- key="keywords"
17
+ name="keywords"
18
18
  content="helper classes, utility classes, css framework, css library, inline style classes" />
19
19
  <meta name="robots" content="index,follow" />
20
20
  <meta
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/utils",
3
- "version": "1.26.2",
3
+ "version": "1.27.1",
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
@@ -59,7 +59,7 @@
59
59
  }
60
60
 
61
61
  // Generate a new custom ObjectId
62
- const timestampHex = Math.floor(Date.now() / 1000).toString(16).padStart(8, '0');
62
+ const timestampHex = Math.floor(new Date(new Date().toISOString()).getTime() / 1000).toString(16).padStart(8, '0');
63
63
  const processIdHex = Math.floor(Math.random() * 0x100000000000).toString(16).padStart(12, '0');
64
64
 
65
65
  counter = (counter + 1) % 10000;
@@ -88,27 +88,20 @@
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
+ // if (/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d{1,3})?Z$/i.test(value))
93
+ if (/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d{3})?([-+]\d{2}:\d{2}|Z)?$/i.test(value)) {
94
+ return true
102
95
  }
103
96
  }
104
97
 
105
- return value; // It's not a valid Date object
98
+ return false;
106
99
  }
107
100
 
108
101
  function dotNotationToObject(data, obj = {}) {
109
102
  try {
110
103
  for (const key of Object.keys(data)) {
111
- let value = isValidDate(data[key])
104
+ let value = data[key]
112
105
  let newObject = obj
113
106
  let oldObject = new Object(obj)
114
107
  let keys = key.split('.');
@@ -308,6 +301,12 @@
308
301
 
309
302
  let selectors = Selector.split(',');
310
303
  for (let j = 0; j < selectors.length; j++) {
304
+ if (selectors[j].includes('@')) {
305
+ selectors[j] = checkMediaQueries(selectors[j])
306
+ if (selectors[j] === false)
307
+ continue
308
+ }
309
+
311
310
  let queriedElement = element
312
311
  let specialSelectors = selectors[j].split(';')
313
312
  for (let k = 0; k < specialSelectors.length; k++) {
@@ -385,6 +384,41 @@
385
384
  return elements
386
385
  }
387
386
 
387
+ const mediaRanges = {
388
+ xs: [0, 575],
389
+ sm: [576, 768],
390
+ md: [769, 992],
391
+ lg: [993, 1200],
392
+ xl: [1201, 0],
393
+ };
394
+
395
+ function checkMediaQueries(selector) {
396
+ if (selector && selector.includes('@')) {
397
+ let screenSizes = selector.split('@')
398
+ selector = screenSizes.shift();
399
+ for (let screenSize of screenSizes) {
400
+ const viewportWidth = window.innerWidth;
401
+ let mediaViewport = false;
402
+
403
+ // Check if screenSize is a valid range in the 'ranges' object
404
+ if (mediaRanges.hasOwnProperty(screenSize)) {
405
+ const [minWidth, maxWidth] = mediaRanges[screenSize];
406
+ if (viewportWidth >= minWidth && viewportWidth <= maxWidth) {
407
+ mediaViewport = true;
408
+ break;
409
+ }
410
+ }
411
+
412
+ if (!mediaViewport)
413
+ return false
414
+
415
+ }
416
+ }
417
+
418
+ return selector
419
+ }
420
+
421
+
388
422
  function queryData(data, query) {
389
423
  if (!data)
390
424
  return false;
@@ -424,6 +458,11 @@
424
458
  queryValue = queryValue.toLowerCase()
425
459
  }
426
460
 
461
+ if (isValidDate(dataValue) && isValidDate(queryValue)) {
462
+ dataValue = new Date(dataValue)
463
+ queryValue = new Date(queryValue)
464
+ }
465
+
427
466
  switch (query[i].operator) {
428
467
  case '$includes':
429
468
  case 'includes':
@@ -443,19 +482,19 @@
443
482
  queryStatus = true
444
483
  break;
445
484
  case '$lt':
446
- if (dataValue > queryValue)
485
+ if (dataValue < queryValue)
447
486
  queryStatus = true
448
487
  break;
449
488
  case '$lte':
450
- if (dataValue >= queryValue)
489
+ if (dataValue <= queryValue)
451
490
  queryStatus = true
452
491
  break;
453
492
  case '$gt':
454
- if (dataValue < queryValue)
493
+ if (dataValue > queryValue)
455
494
  queryStatus = true
456
495
  break;
457
496
  case '$gte':
458
- if (dataValue <= queryValue)
497
+ if (dataValue >= queryValue)
459
498
  queryStatus = true
460
499
  break;
461
500
  case '$in':
@@ -667,6 +706,7 @@
667
706
  escapeHtml,
668
707
  cssPath,
669
708
  queryElements,
709
+ checkMediaQueries,
670
710
  queryData,
671
711
  searchData,
672
712
  sortData,