@jdeighan/coffee-utils 16.0.20 → 16.0.21
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/package.json +1 -1
- package/src/lib/browser.coffee +18 -2
- package/src/lib/browser.js +21 -2
package/package.json
CHANGED
package/src/lib/browser.coffee
CHANGED
@@ -25,9 +25,25 @@ export beep = (volume=100, freq=520, duration=200) =>
|
|
25
25
|
|
26
26
|
# ---------------------------------------------------------------------------
|
27
27
|
|
28
|
+
export localStorageAvailable = () ->
|
29
|
+
|
30
|
+
storage = window.localStorage
|
31
|
+
if notdefined(storage)
|
32
|
+
return false
|
33
|
+
try
|
34
|
+
x = '__storage_test__'
|
35
|
+
storage.setItem x, x
|
36
|
+
got = storage.getItem x
|
37
|
+
storage.removeItem x
|
38
|
+
return (got == x)
|
39
|
+
catch e
|
40
|
+
return false
|
41
|
+
|
42
|
+
# ---------------------------------------------------------------------------
|
43
|
+
|
28
44
|
export getLocalStore = (key, defValue={}) =>
|
29
45
|
|
30
|
-
assert (
|
46
|
+
assert localStorageAvailable(), "no localStorage"
|
31
47
|
if localStorage.hasOwnProperty(key)
|
32
48
|
return JSON.parse(localStorage.getItem(key))
|
33
49
|
else
|
@@ -38,6 +54,6 @@ export getLocalStore = (key, defValue={}) =>
|
|
38
54
|
|
39
55
|
export setLocalStore = (key, value) =>
|
40
56
|
|
41
|
-
assert (
|
57
|
+
assert localStorageAvailable(), "no localStorage"
|
42
58
|
localStorage.setItem key, JSON.stringify(value)
|
43
59
|
return
|
package/src/lib/browser.js
CHANGED
@@ -34,9 +34,28 @@ export var beep = (volume = 100, freq = 520, duration = 200) => {
|
|
34
34
|
v.stop(audio.currentTime + duration * 0.001);
|
35
35
|
};
|
36
36
|
|
37
|
+
// ---------------------------------------------------------------------------
|
38
|
+
export var localStorageAvailable = function() {
|
39
|
+
var e, got, storage, x;
|
40
|
+
storage = window.localStorage;
|
41
|
+
if (notdefined(storage)) {
|
42
|
+
return false;
|
43
|
+
}
|
44
|
+
try {
|
45
|
+
x = '__storage_test__';
|
46
|
+
storage.setItem(x, x);
|
47
|
+
got = storage.getItem(x);
|
48
|
+
storage.removeItem(x);
|
49
|
+
return got === x;
|
50
|
+
} catch (error) {
|
51
|
+
e = error;
|
52
|
+
return false;
|
53
|
+
}
|
54
|
+
};
|
55
|
+
|
37
56
|
// ---------------------------------------------------------------------------
|
38
57
|
export var getLocalStore = (key, defValue = {}) => {
|
39
|
-
assert(
|
58
|
+
assert(localStorageAvailable(), "no localStorage");
|
40
59
|
if (localStorage.hasOwnProperty(key)) {
|
41
60
|
return JSON.parse(localStorage.getItem(key));
|
42
61
|
} else {
|
@@ -47,6 +66,6 @@ export var getLocalStore = (key, defValue = {}) => {
|
|
47
66
|
|
48
67
|
// ---------------------------------------------------------------------------
|
49
68
|
export var setLocalStore = (key, value) => {
|
50
|
-
assert(
|
69
|
+
assert(localStorageAvailable(), "no localStorage");
|
51
70
|
localStorage.setItem(key, JSON.stringify(value));
|
52
71
|
};
|