enigmatic 0.21.1 → 0.21.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.
Files changed (2) hide show
  1. package/enigmatic.js +11 -5
  2. package/package.json +1 -1
package/enigmatic.js CHANGED
@@ -1,5 +1,5 @@
1
1
  const w = {}, d = document
2
- w.enigmatic = { version: '2023-07-29 0.21.1' }
2
+ w.enigmatic = { version: '2023-07-29 0.21.2' }
3
3
 
4
4
  window.onerror = (err, l, n) => {
5
5
  document.write(`<h2 style="border:8px solid Tomato;">${[l, 'line: ' + n, err].join('<br>')}</h2>`)
@@ -121,7 +121,14 @@ w.state = new Proxy({}, {
121
121
 
122
122
  w.get = async (url, options = {}, transform, key) => {
123
123
  console.log(`fetching ${url}`)
124
- let data = await (await fetch(url, options)).json()
124
+ let data
125
+ if (url.startsWith('{') || url.startsWith('[')) {
126
+ data = JSON.parse(url)
127
+ } else {
128
+ let f = await fetch(url, options)
129
+ if (!f.ok) throw Error(`Could not fetch ${url}`)
130
+ data = await f.json()
131
+ }
125
132
  if (transform) {
126
133
  console.log('transforming ' + data)
127
134
  data = transform(data)
@@ -148,9 +155,8 @@ w.start = async () => {
148
155
  e.fetch = async () => {
149
156
  return w.get(e.attr.fetch, {}, null, e.attr.data)
150
157
  }
151
- }
152
- if (!e.hasAttribute('defer')) {
153
- e.fetch()
158
+ if (!e.hasAttribute('defer'))
159
+ e.fetch()
154
160
  }
155
161
  if (e.attr?.stream) {
156
162
  e.stream = w.stream.bind(null, e.pr.stream, null, window[e.pr.transform], e.id)
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "enigmatic",
3
3
  "main": "enigmatic.js",
4
- "version": "0.21.1",
4
+ "version": "0.21.3",
5
5
  "scripts": {
6
6
  "test": "node test.mjs"
7
7
  },