@jdeighan/coffee-utils 16.0.15 → 16.0.17
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 +4 -3
- package/src/lib/SectionMap.coffee +1 -1
- package/src/lib/SectionMap.js +1 -1
- package/src/lib/browser.coffee +26 -17
- package/src/lib/browser.js +27 -21
- package/src/lib/fs.coffee +1 -1
- package/src/lib/fs.js +1 -1
- package/src/lib/prefs.coffee +12 -0
- package/src/lib/prefs.js +13 -0
package/package.json
CHANGED
@@ -1,13 +1,14 @@
|
|
1
1
|
{
|
2
2
|
"name": "@jdeighan/coffee-utils",
|
3
3
|
"type": "module",
|
4
|
-
"version": "16.0.
|
4
|
+
"version": "16.0.17",
|
5
5
|
"description": "A set of utility functions for CoffeeScript",
|
6
6
|
"main": "coffee_utils.js",
|
7
7
|
"exports": {
|
8
8
|
".": "./src/lib/browser.js",
|
9
9
|
"./server": "./src/lib/server.js",
|
10
10
|
"./browser": "./src/lib/browser.js",
|
11
|
+
"./prefs": "./src/lib/prefs.js",
|
11
12
|
"./fs": "./src/lib/fs.js",
|
12
13
|
"./log": "./src/lib/log.js",
|
13
14
|
"./block": "./src/lib/block.js",
|
@@ -46,14 +47,14 @@
|
|
46
47
|
},
|
47
48
|
"homepage": "https://github.com/johndeighan/coffee-utils#readme",
|
48
49
|
"dependencies": {
|
49
|
-
"@jdeighan/base-utils": "^8.0.
|
50
|
+
"@jdeighan/base-utils": "^8.0.18",
|
50
51
|
"cross-env": "^7.0.3",
|
51
52
|
"n-readlines": "^1.0.1",
|
52
53
|
"readline-sync": "^1.4.10",
|
53
54
|
"svelte": "^4.1.1"
|
54
55
|
},
|
55
56
|
"devDependencies": {
|
56
|
-
"@jdeighan/unit-tester": "^3.0.
|
57
|
+
"@jdeighan/unit-tester": "^3.0.67",
|
57
58
|
"ava": "^6.0.1"
|
58
59
|
}
|
59
60
|
}
|
@@ -10,7 +10,7 @@ import {LOG, LOGVALUE, LOGTAML} from '@jdeighan/base-utils/log'
|
|
10
10
|
import {
|
11
11
|
dbg, dbgEnter, dbgReturn, dbgYield, dbgResume,
|
12
12
|
} from '@jdeighan/base-utils/debug'
|
13
|
-
import {isTAML, fromTAML} from '@jdeighan/base-utils/
|
13
|
+
import {isTAML, fromTAML} from '@jdeighan/base-utils/taml'
|
14
14
|
|
15
15
|
import {Section} from '@jdeighan/coffee-utils/section'
|
16
16
|
|
package/src/lib/SectionMap.js
CHANGED
package/src/lib/browser.coffee
CHANGED
@@ -24,28 +24,37 @@ export beep = (volume=100, freq=520, duration=200) =>
|
|
24
24
|
|
25
25
|
# ---------------------------------------------------------------------------
|
26
26
|
|
27
|
-
export
|
28
|
-
# --- if value is undef, returns the current value
|
29
|
-
|
30
|
-
if (typeof localStorage != 'undefined')
|
31
|
-
if defined(value)
|
32
|
-
localStorage.setItem key, JSON.stringify(value)
|
33
|
-
else
|
34
|
-
value = localStorage.getItem(key)
|
35
|
-
if defined(value)
|
36
|
-
return JSON.parse(localStorage.getItem(key))
|
37
|
-
return undef
|
27
|
+
export getLocalStore = (key, defValue={}) =>
|
38
28
|
|
39
|
-
|
29
|
+
if (typeof localStorage == 'undefined')
|
30
|
+
console.log "localStorage not available!"
|
31
|
+
return undef
|
40
32
|
|
41
|
-
|
42
|
-
|
33
|
+
value = localStorage.getItem(key)
|
34
|
+
if defined(value)
|
35
|
+
return JSON.parse(value)
|
36
|
+
else
|
37
|
+
localStorage.setItem key, JSON.stringify(defValue)
|
38
|
+
return defValue
|
43
39
|
|
44
40
|
# ---------------------------------------------------------------------------
|
45
41
|
|
46
|
-
export
|
42
|
+
export setLocalStore = (key, value) =>
|
43
|
+
|
44
|
+
if (typeof localStorage == 'undefined')
|
45
|
+
console.log "localStorage not available!"
|
46
|
+
return undef
|
47
47
|
|
48
|
-
|
49
|
-
|
48
|
+
localStorage.setItem key, JSON.stringify(value)
|
49
|
+
return
|
50
50
|
|
51
51
|
# ---------------------------------------------------------------------------
|
52
|
+
# --- only here for backward compatibility
|
53
|
+
|
54
|
+
export localStore = (key, value) =>
|
55
|
+
|
56
|
+
if defined(value)
|
57
|
+
setLocalStore key, value
|
58
|
+
else
|
59
|
+
getLocalStore key, undef
|
60
|
+
return
|
package/src/lib/browser.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
// Generated by CoffeeScript 2.7.0
|
2
2
|
// browser.coffee
|
3
|
-
var audio
|
3
|
+
var audio;
|
4
4
|
|
5
5
|
import {
|
6
6
|
undef,
|
@@ -30,30 +30,36 @@ export var beep = (volume = 100, freq = 520, duration = 200) => {
|
|
30
30
|
};
|
31
31
|
|
32
32
|
// ---------------------------------------------------------------------------
|
33
|
-
export var
|
34
|
-
|
35
|
-
if (typeof localStorage
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
33
|
+
export var getLocalStore = (key, defValue = {}) => {
|
34
|
+
var value;
|
35
|
+
if (typeof localStorage === 'undefined') {
|
36
|
+
console.log("localStorage not available!");
|
37
|
+
return undef;
|
38
|
+
}
|
39
|
+
value = localStorage.getItem(key);
|
40
|
+
if (defined(value)) {
|
41
|
+
return JSON.parse(value);
|
42
|
+
} else {
|
43
|
+
localStorage.setItem(key, JSON.stringify(defValue));
|
44
|
+
return defValue;
|
44
45
|
}
|
45
|
-
return undef;
|
46
46
|
};
|
47
47
|
|
48
48
|
// ---------------------------------------------------------------------------
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
hPrefs[key] = value;
|
56
|
-
return localStore(storeKey, hPrefs);
|
49
|
+
export var setLocalStore = (key, value) => {
|
50
|
+
if (typeof localStorage === 'undefined') {
|
51
|
+
console.log("localStorage not available!");
|
52
|
+
return undef;
|
53
|
+
}
|
54
|
+
localStorage.setItem(key, JSON.stringify(value));
|
57
55
|
};
|
58
56
|
|
59
57
|
// ---------------------------------------------------------------------------
|
58
|
+
// --- only here for backward compatibility
|
59
|
+
export var localStore = (key, value) => {
|
60
|
+
if (defined(value)) {
|
61
|
+
setLocalStore(key, value);
|
62
|
+
} else {
|
63
|
+
getLocalStore(key, undef);
|
64
|
+
}
|
65
|
+
};
|
package/src/lib/fs.coffee
CHANGED
@@ -22,7 +22,7 @@ import {
|
|
22
22
|
import {assert, croak} from '@jdeighan/base-utils/exceptions'
|
23
23
|
import {LOG, LOGVALUE} from '@jdeighan/base-utils/log'
|
24
24
|
import {dbg, dbgEnter, dbgReturn} from '@jdeighan/base-utils/debug'
|
25
|
-
import {fromTAML} from '@jdeighan/base-utils/
|
25
|
+
import {fromTAML} from '@jdeighan/base-utils/taml'
|
26
26
|
|
27
27
|
export {
|
28
28
|
mydir, mkpath, isFile, isDir, rmFileSync, mkdirSync,
|
package/src/lib/fs.js
CHANGED
@@ -0,0 +1,12 @@
|
|
1
|
+
# prefs.coffee
|
2
|
+
|
3
|
+
import {getLocalStore} from '@jdeighan/coffee-utils/browser'
|
4
|
+
|
5
|
+
export hPrefs = getLocalStore 'hPrefs', {}
|
6
|
+
|
7
|
+
# ---------------------------------------------------------------------------
|
8
|
+
|
9
|
+
export setPref = (key, value) =>
|
10
|
+
|
11
|
+
hPrefs[key] = value
|
12
|
+
setLocalStore 'hPrefs', hPrefs
|
package/src/lib/prefs.js
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
// Generated by CoffeeScript 2.7.0
|
2
|
+
// prefs.coffee
|
3
|
+
import {
|
4
|
+
getLocalStore
|
5
|
+
} from '@jdeighan/coffee-utils/browser';
|
6
|
+
|
7
|
+
export var hPrefs = getLocalStore('hPrefs', {});
|
8
|
+
|
9
|
+
// ---------------------------------------------------------------------------
|
10
|
+
export var setPref = (key, value) => {
|
11
|
+
hPrefs[key] = value;
|
12
|
+
return setLocalStore('hPrefs', hPrefs);
|
13
|
+
};
|