@jdeighan/coffee-utils 16.0.21 → 16.0.22
Sign up to get free protection for your applications and to get access to all the features.
- package/package.json +2 -2
- package/src/lib/browser.coffee +8 -2
- package/src/lib/browser.js +13 -2
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@jdeighan/coffee-utils",
|
3
3
|
"type": "module",
|
4
|
-
"version": "16.0.
|
4
|
+
"version": "16.0.22",
|
5
5
|
"description": "A set of utility functions for CoffeeScript",
|
6
6
|
"main": "coffee_utils.js",
|
7
7
|
"exports": {
|
@@ -46,7 +46,7 @@
|
|
46
46
|
},
|
47
47
|
"homepage": "https://github.com/johndeighan/coffee-utils#readme",
|
48
48
|
"dependencies": {
|
49
|
-
"@jdeighan/base-utils": "^8.0.
|
49
|
+
"@jdeighan/base-utils": "^8.0.23",
|
50
50
|
"cross-env": "^7.0.3",
|
51
51
|
"n-readlines": "^1.0.1",
|
52
52
|
"readline-sync": "^1.4.10",
|
package/src/lib/browser.coffee
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# browser.coffee
|
2
2
|
|
3
|
+
import {browser} from "$app/env"
|
4
|
+
|
3
5
|
import {undef, defined, notdefined} from '@jdeighan/base-utils'
|
4
6
|
import {assert, croak} from '@jdeighan/base-utils/exceptions'
|
5
7
|
|
@@ -27,6 +29,8 @@ export beep = (volume=100, freq=520, duration=200) =>
|
|
27
29
|
|
28
30
|
export localStorageAvailable = () ->
|
29
31
|
|
32
|
+
if ! browser
|
33
|
+
return false
|
30
34
|
storage = window.localStorage
|
31
35
|
if notdefined(storage)
|
32
36
|
return false
|
@@ -43,7 +47,8 @@ export localStorageAvailable = () ->
|
|
43
47
|
|
44
48
|
export getLocalStore = (key, defValue={}) =>
|
45
49
|
|
46
|
-
|
50
|
+
if ! localStorageAvailable()
|
51
|
+
return undef
|
47
52
|
if localStorage.hasOwnProperty(key)
|
48
53
|
return JSON.parse(localStorage.getItem(key))
|
49
54
|
else
|
@@ -54,6 +59,7 @@ export getLocalStore = (key, defValue={}) =>
|
|
54
59
|
|
55
60
|
export setLocalStore = (key, value) =>
|
56
61
|
|
57
|
-
|
62
|
+
if ! localStorageAvailable()
|
63
|
+
return
|
58
64
|
localStorage.setItem key, JSON.stringify(value)
|
59
65
|
return
|
package/src/lib/browser.js
CHANGED
@@ -2,6 +2,10 @@
|
|
2
2
|
// browser.coffee
|
3
3
|
var audio;
|
4
4
|
|
5
|
+
import {
|
6
|
+
browser
|
7
|
+
} from "$app/env";
|
8
|
+
|
5
9
|
import {
|
6
10
|
undef,
|
7
11
|
defined,
|
@@ -37,6 +41,9 @@ export var beep = (volume = 100, freq = 520, duration = 200) => {
|
|
37
41
|
// ---------------------------------------------------------------------------
|
38
42
|
export var localStorageAvailable = function() {
|
39
43
|
var e, got, storage, x;
|
44
|
+
if (!browser) {
|
45
|
+
return false;
|
46
|
+
}
|
40
47
|
storage = window.localStorage;
|
41
48
|
if (notdefined(storage)) {
|
42
49
|
return false;
|
@@ -55,7 +62,9 @@ export var localStorageAvailable = function() {
|
|
55
62
|
|
56
63
|
// ---------------------------------------------------------------------------
|
57
64
|
export var getLocalStore = (key, defValue = {}) => {
|
58
|
-
|
65
|
+
if (!localStorageAvailable()) {
|
66
|
+
return undef;
|
67
|
+
}
|
59
68
|
if (localStorage.hasOwnProperty(key)) {
|
60
69
|
return JSON.parse(localStorage.getItem(key));
|
61
70
|
} else {
|
@@ -66,6 +75,8 @@ export var getLocalStore = (key, defValue = {}) => {
|
|
66
75
|
|
67
76
|
// ---------------------------------------------------------------------------
|
68
77
|
export var setLocalStore = (key, value) => {
|
69
|
-
|
78
|
+
if (!localStorageAvailable()) {
|
79
|
+
return;
|
80
|
+
}
|
70
81
|
localStorage.setItem(key, JSON.stringify(value));
|
71
82
|
};
|