enigmatic 0.11.2 → 0.11.3

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/enigmatic.js CHANGED
@@ -41,8 +41,9 @@ w.flatten = (obj, text) => {
41
41
  for (let k in obj) {
42
42
  let html = text.replaceAll('{$key}', k)
43
43
  for (let j in obj[k]) {
44
- html = html.replaceAll('{_key_}', j).replaceAll('{_val_}', obj[k][j])
45
- html = html.replaceAll(`{${j}}`, obj[k][j])
44
+ const val = typeof obj[k] === 'object' ? obj[k][j] : obj[k]
45
+ html = html.replaceAll('{_key_}', j).replaceAll('{_val_}', val)
46
+ html = html.replaceAll(`{${j}}`, val)
46
47
  }
47
48
  htmls += html
48
49
  }
@@ -68,12 +69,9 @@ w.element = (
68
69
  if (!this.template.match('{')) this.innerHTML = this.template
69
70
  }
70
71
  set(o) {
71
- this.innerHTML = ''
72
72
  o = beforeData(o)
73
- if (!Array.isArray(o)) o = [o]
74
- const m = new Function('o', 'return `' + this.template + '`')
75
- o.map((i) => (this.innerHTML += m(i)))
76
- return true
73
+ w.flatten(o, this.template)
74
+ return o
77
75
  }
78
76
  }
79
77
  )
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "enigmatic",
3
3
  "main": "enigmatic.js",
4
- "version": "0.11.2",
4
+ "version": "0.11.3",
5
5
  "scripts": {
6
6
  "test": "node test.mjs"
7
7
  },
package/test-flatten.html CHANGED
@@ -6,6 +6,7 @@
6
6
 
7
7
  <button onclick='window.testone()'>Test one</button>
8
8
  <button onclick='window.testtwo()'>Test two</button>
9
+ <button onclick='window.testthree()'>Test three</button>
9
10
 
10
11
  <script type="module">
11
12
  window.testone = () => {
@@ -22,4 +23,11 @@
22
23
  }
23
24
  state.akey = testt
24
25
  }
26
+ window.testthree = () => {
27
+ const testt = {
28
+ "k1": 'val1',
29
+ "k2": 'val2',
30
+ }
31
+ state.akey = testt
32
+ }
25
33
  </script>