@jdeighan/coffee-utils 5.0.2 → 5.0.3
Sign up to get free protection for your applications and to get access to all the features.
- package/package.json +1 -1
- package/src/DataStores.coffee +2 -1
- package/src/DataStores.js +4 -1
- package/src/browser_utils.coffee +18 -0
- package/src/browser_utils.js +18 -0
- package/src/coffee_utils.coffee +0 -17
- package/src/coffee_utils.js +0 -18
- package/src/indent_utils.coffee +1 -1
- package/src/indent_utils.js +1 -1
package/package.json
CHANGED
package/src/DataStores.coffee
CHANGED
@@ -5,8 +5,9 @@ import yaml from 'js-yaml'
|
|
5
5
|
import {writable, readable, get} from 'svelte/store'
|
6
6
|
|
7
7
|
import {
|
8
|
-
assert, undef, pass, error,
|
8
|
+
assert, undef, pass, error, isEmpty,
|
9
9
|
} from '@jdeighan/coffee-utils'
|
10
|
+
import {localStore} from '@jdeighan/coffee-utils/browser'
|
10
11
|
import {log} from '@jdeighan/coffee-utils/log'
|
11
12
|
import {
|
12
13
|
withExt, slurp, barf, newerDestFileExists,
|
package/src/DataStores.js
CHANGED
package/src/browser_utils.coffee
CHANGED
@@ -21,3 +21,21 @@ export beep = (volume=100, freq=520, duration=200) ->
|
|
21
21
|
v.start(audio.currentTime)
|
22
22
|
v.stop(audio.currentTime + duration * 0.001)
|
23
23
|
return
|
24
|
+
|
25
|
+
# ---------------------------------------------------------------------------
|
26
|
+
|
27
|
+
export localStore = (key, value=undef) ->
|
28
|
+
# --- if value is undef, returns the current value
|
29
|
+
|
30
|
+
if typeof localStorage == 'undefined'
|
31
|
+
return
|
32
|
+
if value?
|
33
|
+
localStorage.setItem key, JSON.stringify(value)
|
34
|
+
return
|
35
|
+
else
|
36
|
+
value = localStorage.getItem(key)
|
37
|
+
if value?
|
38
|
+
return JSON.parse(localStorage.getItem(key))
|
39
|
+
else
|
40
|
+
return undef
|
41
|
+
|
package/src/browser_utils.js
CHANGED
@@ -26,3 +26,21 @@ export var beep = function(volume = 100, freq = 520, duration = 200) {
|
|
26
26
|
v.start(audio.currentTime);
|
27
27
|
v.stop(audio.currentTime + duration * 0.001);
|
28
28
|
};
|
29
|
+
|
30
|
+
// ---------------------------------------------------------------------------
|
31
|
+
export var localStore = function(key, value = undef) {
|
32
|
+
// --- if value is undef, returns the current value
|
33
|
+
if (typeof localStorage === 'undefined') {
|
34
|
+
return;
|
35
|
+
}
|
36
|
+
if (value != null) {
|
37
|
+
localStorage.setItem(key, JSON.stringify(value));
|
38
|
+
} else {
|
39
|
+
value = localStorage.getItem(key);
|
40
|
+
if (value != null) {
|
41
|
+
return JSON.parse(localStorage.getItem(key));
|
42
|
+
} else {
|
43
|
+
return undef;
|
44
|
+
}
|
45
|
+
}
|
46
|
+
};
|
package/src/coffee_utils.coffee
CHANGED
@@ -42,23 +42,6 @@ export croak = (err, label, obj) ->
|
|
42
42
|
|
43
43
|
# ---------------------------------------------------------------------------
|
44
44
|
|
45
|
-
export localStore = (key, value=undef) ->
|
46
|
-
# --- if value is undef, returns the current value
|
47
|
-
|
48
|
-
if typeof localStorage == 'undefined'
|
49
|
-
return
|
50
|
-
if value?
|
51
|
-
localStorage.setItem key, JSON.stringify(value)
|
52
|
-
return
|
53
|
-
else
|
54
|
-
value = localStorage.getItem(key)
|
55
|
-
if value?
|
56
|
-
return JSON.parse(localStorage.getItem(key))
|
57
|
-
else
|
58
|
-
return undef
|
59
|
-
|
60
|
-
# ---------------------------------------------------------------------------
|
61
|
-
|
62
45
|
export getClassName = (obj) ->
|
63
46
|
|
64
47
|
if (typeof obj != 'object')
|
package/src/coffee_utils.js
CHANGED
@@ -38,24 +38,6 @@ ${JSON.stringify(obj)}`;
|
|
38
38
|
throw new Error(newmsg);
|
39
39
|
};
|
40
40
|
|
41
|
-
// ---------------------------------------------------------------------------
|
42
|
-
export var localStore = function(key, value = undef) {
|
43
|
-
// --- if value is undef, returns the current value
|
44
|
-
if (typeof localStorage === 'undefined') {
|
45
|
-
return;
|
46
|
-
}
|
47
|
-
if (value != null) {
|
48
|
-
localStorage.setItem(key, JSON.stringify(value));
|
49
|
-
} else {
|
50
|
-
value = localStorage.getItem(key);
|
51
|
-
if (value != null) {
|
52
|
-
return JSON.parse(localStorage.getItem(key));
|
53
|
-
} else {
|
54
|
-
return undef;
|
55
|
-
}
|
56
|
-
}
|
57
|
-
};
|
58
|
-
|
59
41
|
// ---------------------------------------------------------------------------
|
60
42
|
export var getClassName = function(obj) {
|
61
43
|
if (typeof obj !== 'object') {
|
package/src/indent_utils.coffee
CHANGED
@@ -25,7 +25,7 @@ export splitLine = (line) ->
|
|
25
25
|
|
26
26
|
export indentation = (level) ->
|
27
27
|
|
28
|
-
assert (level >= 0), "
|
28
|
+
assert (level >= 0), "indentation(): negative level"
|
29
29
|
return '\t'.repeat(level)
|
30
30
|
|
31
31
|
# ---------------------------------------------------------------------------
|
package/src/indent_utils.js
CHANGED
@@ -35,7 +35,7 @@ export var splitLine = function(line) {
|
|
35
35
|
// indentation - return appropriate indentation string for given level
|
36
36
|
// export only to allow unit testing
|
37
37
|
export var indentation = function(level) {
|
38
|
-
assert(level >= 0, "
|
38
|
+
assert(level >= 0, "indentation(): negative level");
|
39
39
|
return '\t'.repeat(level);
|
40
40
|
};
|
41
41
|
|