@cocreate/utils 1.13.1 → 1.14.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,22 @@
1
+ ## [1.14.1](https://github.com/CoCreate-app/CoCreate-utils/compare/v1.14.0...v1.14.1) (2022-12-04)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * bump dependencies ([047612f](https://github.com/CoCreate-app/CoCreate-utils/commit/047612f5d961df25b08994cd2bd394db5ed552b6))
7
+
8
+ # [1.14.0](https://github.com/CoCreate-app/CoCreate-utils/compare/v1.13.1...v1.14.0) (2022-12-04)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * operator typo ([fd47c03](https://github.com/CoCreate-app/CoCreate-utils/commit/fd47c03fcccc2e55d55fd01d50b24bfb36914106))
14
+
15
+
16
+ ### Features
17
+
18
+ * ObjectId generator ([7b2de66](https://github.com/CoCreate-app/CoCreate-utils/commit/7b2de667e83ab5420228b86052cd2d6918d17188))
19
+
1
20
  ## [1.13.1](https://github.com/CoCreate-app/CoCreate-utils/compare/v1.13.0...v1.13.1) (2022-12-02)
2
21
 
3
22
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/utils",
3
- "version": "1.13.1",
3
+ "version": "1.14.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",
@@ -61,6 +61,6 @@
61
61
  "webpack-log": "^3.0.1"
62
62
  },
63
63
  "dependencies": {
64
- "@cocreate/docs": "^1.4.11"
64
+ "@cocreate/docs": "^1.4.13"
65
65
  }
66
66
  }
package/src/utils.js CHANGED
@@ -10,7 +10,6 @@
10
10
  }
11
11
  }(typeof self !== 'undefined' ? self : this, function (isBrowser) {
12
12
 
13
-
14
13
  /*globals DOMParser*/
15
14
  function clickedElement() {
16
15
  document.addEventListener('click', e => {
@@ -33,6 +32,9 @@
33
32
  }
34
33
  }
35
34
 
35
+ const ObjectId = (rnd = r16 => Math.floor(r16).toString(16)) =>
36
+ rnd(Date.now()/1000) + ' '.repeat(16).replace(/./g, () => rnd(Math.random()*16));
37
+
36
38
  function dotNotationToObject(data, obj = {}) {
37
39
  try {
38
40
  for (const [key, value] of Object.entries(data)) {
@@ -98,6 +100,31 @@
98
100
  }
99
101
  }
100
102
 
103
+ function domParser(str) {
104
+ try {
105
+ var mainTag = str.match(/\<(?<tag>[a-z0-9]+)(.*?)?\>/).groups.tag;
106
+ } catch (e){
107
+ // console.log(e, 'find position: can not find the main tag');
108
+ }
109
+ let doc;
110
+ switch (mainTag) {
111
+ case 'html':
112
+ doc = new DOMParser().parseFromString(str, "text/html");
113
+ return doc.documentElement;
114
+ case 'body':
115
+ doc = new DOMParser().parseFromString(str, "text/html");
116
+ return doc.body;
117
+ case 'head':
118
+ doc = new DOMParser().parseFromString(str, "text/html");
119
+ return doc.head;
120
+
121
+ default:
122
+ let con = document.createElement('dom-parser');
123
+ con.innerHTML = str;
124
+ return con;
125
+ }
126
+ }
127
+
101
128
  function parseTextToHtml(text) {
102
129
  let doc = new DOMParser().parseFromString(text, "text/html");
103
130
  if (doc.head.children[0]) return doc.head.children[0];
@@ -173,31 +200,6 @@
173
200
  return path;
174
201
  }
175
202
 
176
- function domParser(str) {
177
- try {
178
- var mainTag = str.match(/\<(?<tag>[a-z0-9]+)(.*?)?\>/).groups.tag;
179
- } catch (e){
180
- // console.log(e, 'find position: can not find the main tag');
181
- }
182
- let doc;
183
- switch (mainTag) {
184
- case 'html':
185
- doc = new DOMParser().parseFromString(str, "text/html");
186
- return doc.documentElement;
187
- case 'body':
188
- doc = new DOMParser().parseFromString(str, "text/html");
189
- return doc.body;
190
- case 'head':
191
- doc = new DOMParser().parseFromString(str, "text/html");
192
- return doc.head;
193
-
194
- default:
195
- let con = document.createElement('dom-parser');
196
- con.innerHTML = str;
197
- return con;
198
- }
199
- }
200
-
201
203
  function queryDocumentSelectorAll(selector) {
202
204
  let elements = [];
203
205
 
@@ -426,7 +428,7 @@
426
428
 
427
429
  }
428
430
  }
429
- if (search[i].value.length && operator == 'or')
431
+ if (search[i].value.length && search[i].operator == 'or')
430
432
  return false
431
433
 
432
434
  }
@@ -496,11 +498,12 @@
496
498
  clickedElement();
497
499
 
498
500
  return {
499
- parseTextToHtml,
501
+ ObjectId,
500
502
  dotNotationToObject,
501
503
  getValueFromObject,
502
- cssPath,
503
504
  domParser,
505
+ parseTextToHtml,
506
+ cssPath,
504
507
  queryDocumentSelector,
505
508
  queryDocumentSelectorAll,
506
509
  queryData,