@cocreate/utils 1.15.3 → 1.16.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,17 @@
1
+ ## [1.16.1](https://github.com/CoCreate-app/CoCreate-utils/compare/v1.16.0...v1.16.1) (2022-12-12)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * bump dependencies ([d36245c](https://github.com/CoCreate-app/CoCreate-utils/commit/d36245c5c78c5f33e9ecb23f2c5091cee7e46aee))
7
+
8
+ # [1.16.0](https://github.com/CoCreate-app/CoCreate-utils/compare/v1.15.3...v1.16.0) (2022-12-12)
9
+
10
+
11
+ ### Features
12
+
13
+ * getAttributes, getAttributeNames and setAttributeNames ([de2d962](https://github.com/CoCreate-app/CoCreate-utils/commit/de2d96223017f457a1bf13e07ee1a8c49a0596ed))
14
+
1
15
  ## [1.15.3](https://github.com/CoCreate-app/CoCreate-utils/compare/v1.15.2...v1.15.3) (2022-12-11)
2
16
 
3
17
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/utils",
3
- "version": "1.15.3",
3
+ "version": "1.16.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.17"
64
+ "@cocreate/docs": "^1.4.18"
65
65
  }
66
66
  }
package/src/utils.js CHANGED
@@ -480,7 +480,58 @@
480
480
  }
481
481
  }
482
482
  return data;
483
- }
483
+ }
484
+
485
+ function getAttributes(el) {
486
+ if (!el) return;
487
+
488
+ let attributes = window.CoCreateConfig.attributes;
489
+ let object = {};
490
+
491
+ for (let attribute of el.attributes) {
492
+ let variable = attributes[attribute.name]
493
+ if (variable) {
494
+ object[variable] = attribute.value
495
+ }
496
+ }
497
+
498
+ return object
499
+ }
500
+
501
+ function getAttributeNames(variables) {
502
+ let reversedObject = {}
503
+ for (const key of Object.keys(CoCreateConfig.attributes)) {
504
+ reversedObject[CoCreateConfig.attributes[key]] = key
505
+ }
506
+
507
+ let attributes = [];
508
+ for (const variable of variables) {
509
+ let attribute = reversedObject[variable]
510
+ if (attribute)
511
+ attributes.push(attribute)
512
+ }
513
+ return attributes
514
+ }
515
+
516
+ function setAttributeNames(attributes, overWrite) {
517
+ let reversedObject = {}
518
+ for (const key of Object.keys(CoCreateConfig.attributes)) {
519
+ reversedObject[CoCreateConfig.attributes[key]] = key
520
+ }
521
+
522
+ for (const attribute of Object.keys(attributes)) {
523
+ const variable = attributes[attribute]
524
+ if (!reversedObject[variable] || overWrite != false)
525
+ reversedObject[variable] = attribute
526
+ }
527
+
528
+ let revertObject = {}
529
+ for (const key of Object.keys(reversedObject)) {
530
+ revertObject[reversedObject[key]] = key
531
+ }
532
+ CoCreateConfig.attributes = revertObject
533
+ }
534
+
484
535
 
485
536
  // function computeStyles(el, properties) {
486
537
  // let computed = window.getComputedStyle(el);
@@ -518,7 +569,10 @@
518
569
  queryDocumentSelectorAll,
519
570
  queryData,
520
571
  searchData,
521
- sortData
572
+ sortData,
573
+ getAttributes,
574
+ setAttributeNames,
575
+ getAttributeNames
522
576
  }
523
577
 
524
578
  }));