@taybart/corvid 0.1.25 → 0.1.27

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/dist/index.js CHANGED
@@ -167,20 +167,36 @@ const clipboard = {
167
167
  if (!navigator.clipboard) throw new Error('Clipboard API not supported, or context is not https');
168
168
  },
169
169
  async copy (text) {
170
- this.check();
171
- await navigator.clipboard.writeText(text);
170
+ try {
171
+ this.check();
172
+ await navigator.clipboard.writeText(text);
173
+ } catch (e) {
174
+ throw e;
175
+ }
172
176
  },
173
177
  async copyArbitrary (data) {
174
- this.check();
175
- await navigator.clipboard.write(data);
178
+ try {
179
+ this.check();
180
+ await navigator.clipboard.write(data);
181
+ } catch (e) {
182
+ throw e;
183
+ }
176
184
  },
177
185
  async read () {
178
- this.check();
179
- return await navigator.clipboard.readText();
186
+ try {
187
+ this.check();
188
+ return await navigator.clipboard.readText();
189
+ } catch (e) {
190
+ throw e;
191
+ }
180
192
  },
181
193
  async readArbitrary () {
182
- this.check();
183
- return await navigator.clipboard.read();
194
+ try {
195
+ this.check();
196
+ return await navigator.clipboard.read();
197
+ } catch (e) {
198
+ throw e;
199
+ }
184
200
  },
185
201
  listen (query, cb) {
186
202
  let el;
@@ -703,17 +719,24 @@ function get(key, _default) {
703
719
  function getJSON(key, _default) {
704
720
  const val = get(key, _default);
705
721
  if (null === val) return null;
706
- return JSON.parse(val);
722
+ try {
723
+ return JSON.parse(val);
724
+ } catch (e) {
725
+ console.error(e);
726
+ return val;
727
+ }
707
728
  }
708
729
  function local_storage_update(key, update1, broadcast = false) {
709
730
  const prev = get(key);
710
- const value = update1(prev);
731
+ let value = update1(prev);
732
+ const v = value;
733
+ if ('object' == typeof value) value = JSON.stringify(value);
711
734
  localStorage.setItem(key, value);
712
735
  if (prev !== value || broadcast) {
713
736
  const event = new CustomEvent('@corvid/ls-update', {
714
737
  detail: {
715
738
  key,
716
- value
739
+ value: v
717
740
  }
718
741
  });
719
742
  document.dispatchEvent(event);
package/dist/ls.js CHANGED
@@ -258,17 +258,24 @@ function get(key, _default) {
258
258
  function getJSON(key, _default) {
259
259
  const val = get(key, _default);
260
260
  if (null === val) return null;
261
- return JSON.parse(val);
261
+ try {
262
+ return JSON.parse(val);
263
+ } catch (e) {
264
+ console.error(e);
265
+ return val;
266
+ }
262
267
  }
263
268
  function local_storage_update(key, update1, broadcast = false) {
264
269
  const prev = get(key);
265
- const value = update1(prev);
270
+ let value = update1(prev);
271
+ const v = value;
272
+ if ('object' == typeof value) value = JSON.stringify(value);
266
273
  localStorage.setItem(key, value);
267
274
  if (prev !== value || broadcast) {
268
275
  const event = new CustomEvent('@corvid/ls-update', {
269
276
  detail: {
270
277
  key,
271
- value
278
+ value: v
272
279
  }
273
280
  });
274
281
  document.dispatchEvent(event);
package/dist/utils.js CHANGED
@@ -18,20 +18,36 @@ const clipboard = {
18
18
  if (!navigator.clipboard) throw new Error('Clipboard API not supported, or context is not https');
19
19
  },
20
20
  async copy (text) {
21
- this.check();
22
- await navigator.clipboard.writeText(text);
21
+ try {
22
+ this.check();
23
+ await navigator.clipboard.writeText(text);
24
+ } catch (e) {
25
+ throw e;
26
+ }
23
27
  },
24
28
  async copyArbitrary (data) {
25
- this.check();
26
- await navigator.clipboard.write(data);
29
+ try {
30
+ this.check();
31
+ await navigator.clipboard.write(data);
32
+ } catch (e) {
33
+ throw e;
34
+ }
27
35
  },
28
36
  async read () {
29
- this.check();
30
- return await navigator.clipboard.readText();
37
+ try {
38
+ this.check();
39
+ return await navigator.clipboard.readText();
40
+ } catch (e) {
41
+ throw e;
42
+ }
31
43
  },
32
44
  async readArbitrary () {
33
- this.check();
34
- return await navigator.clipboard.read();
45
+ try {
46
+ this.check();
47
+ return await navigator.clipboard.read();
48
+ } catch (e) {
49
+ throw e;
50
+ }
35
51
  },
36
52
  listen (query, cb) {
37
53
  let el;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@taybart/corvid",
3
- "version": "0.1.25",
3
+ "version": "0.1.27",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "exports": {