@jdeighan/coffee-utils 5.0.0 → 5.0.3
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 +3 -6
- package/src/DataStores.coffee +3 -1
- package/src/DataStores.js +8 -1
- package/src/browser_utils.coffee +18 -0
- package/src/browser_utils.js +18 -0
- package/src/coffee_utils.coffee +7 -24
- package/src/coffee_utils.js +6 -27
- package/src/indent_utils.coffee +1 -1
- package/src/indent_utils.js +1 -1
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@jdeighan/coffee-utils",
|
3
3
|
"type": "module",
|
4
|
-
"version": "5.0.
|
4
|
+
"version": "5.0.3",
|
5
5
|
"description": "A set of utility functions for CoffeeScript",
|
6
6
|
"main": "coffee_utils.js",
|
7
7
|
"exports": {
|
@@ -17,7 +17,6 @@
|
|
17
17
|
"./svelte": "./src/svelte_utils.js",
|
18
18
|
"./store": "./src/DataStores.js",
|
19
19
|
"./taml": "./src/taml.js",
|
20
|
-
"./templib": "./src/templib.js",
|
21
20
|
"./package.json": "./package.json"
|
22
21
|
},
|
23
22
|
"engines": {
|
@@ -29,9 +28,7 @@
|
|
29
28
|
"scripts": {
|
30
29
|
"build": "cls && rm -f ./src/*.js && coffee -c ./src",
|
31
30
|
"pretest": "cls && cielo -qfc ./test && coffee -c .",
|
32
|
-
"test": "npx ava ./test/*.test.js"
|
33
|
-
"prefinaltest": "npm run pretest",
|
34
|
-
"finaltest": "cross-env FINALTEST=yes ava ./test/*.test.js"
|
31
|
+
"test": "npx ava ./test/*.test.js"
|
35
32
|
},
|
36
33
|
"repository": {
|
37
34
|
"type": "git",
|
@@ -53,6 +50,6 @@
|
|
53
50
|
"svelte": "^3.46.4"
|
54
51
|
},
|
55
52
|
"devDependencies": {
|
56
|
-
"@jdeighan/unit-tester": "^1.0.
|
53
|
+
"@jdeighan/unit-tester": "^1.0.5"
|
57
54
|
}
|
58
55
|
}
|
package/src/DataStores.coffee
CHANGED
@@ -5,12 +5,14 @@ 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,
|
13
14
|
} from '@jdeighan/coffee-utils/fs'
|
15
|
+
import {untabify} from '@jdeighan/coffee-utils/indent'
|
14
16
|
|
15
17
|
# ---------------------------------------------------------------------------
|
16
18
|
|
package/src/DataStores.js
CHANGED
@@ -15,10 +15,13 @@ import {
|
|
15
15
|
undef,
|
16
16
|
pass,
|
17
17
|
error,
|
18
|
-
localStore,
|
19
18
|
isEmpty
|
20
19
|
} from '@jdeighan/coffee-utils';
|
21
20
|
|
21
|
+
import {
|
22
|
+
localStore
|
23
|
+
} from '@jdeighan/coffee-utils/browser';
|
24
|
+
|
22
25
|
import {
|
23
26
|
log
|
24
27
|
} from '@jdeighan/coffee-utils/log';
|
@@ -30,6 +33,10 @@ import {
|
|
30
33
|
newerDestFileExists
|
31
34
|
} from '@jdeighan/coffee-utils/fs';
|
32
35
|
|
36
|
+
import {
|
37
|
+
untabify
|
38
|
+
} from '@jdeighan/coffee-utils/indent';
|
39
|
+
|
33
40
|
// ---------------------------------------------------------------------------
|
34
41
|
export var WritableDataStore = class WritableDataStore {
|
35
42
|
constructor(value = undef) {
|
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
@@ -30,32 +30,15 @@ export assert = (cond, msg) ->
|
|
30
30
|
|
31
31
|
export croak = (err, label, obj) ->
|
32
32
|
|
33
|
-
|
34
|
-
|
35
|
-
|
33
|
+
curmsg = if isString(err) then err else err.message
|
34
|
+
newmsg = """
|
35
|
+
ERROR (croak): #{curmsg}
|
36
|
+
#{label}:
|
37
|
+
#{JSON.stringify(obj)}
|
38
|
+
"""
|
36
39
|
|
37
40
|
# --- re-throw the error
|
38
|
-
|
39
|
-
throw err
|
40
|
-
else
|
41
|
-
throw new Error(message)
|
42
|
-
|
43
|
-
# ---------------------------------------------------------------------------
|
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
|
41
|
+
throw new Error(newmsg)
|
59
42
|
|
60
43
|
# ---------------------------------------------------------------------------
|
61
44
|
|
package/src/coffee_utils.js
CHANGED
@@ -29,34 +29,13 @@ export var assert = function(cond, msg) {
|
|
29
29
|
// ---------------------------------------------------------------------------
|
30
30
|
// croak - throws an error after possibly printing useful info
|
31
31
|
export var croak = function(err, label, obj) {
|
32
|
-
var
|
33
|
-
|
34
|
-
|
35
|
-
|
32
|
+
var curmsg, newmsg;
|
33
|
+
curmsg = isString(err) ? err : err.message;
|
34
|
+
newmsg = `ERROR (croak): ${curmsg}
|
35
|
+
${label}:
|
36
|
+
${JSON.stringify(obj)}`;
|
36
37
|
// --- re-throw the error
|
37
|
-
|
38
|
-
throw err;
|
39
|
-
} else {
|
40
|
-
throw new Error(message);
|
41
|
-
}
|
42
|
-
};
|
43
|
-
|
44
|
-
// ---------------------------------------------------------------------------
|
45
|
-
export var localStore = function(key, value = undef) {
|
46
|
-
// --- if value is undef, returns the current value
|
47
|
-
if (typeof localStorage === 'undefined') {
|
48
|
-
return;
|
49
|
-
}
|
50
|
-
if (value != null) {
|
51
|
-
localStorage.setItem(key, JSON.stringify(value));
|
52
|
-
} else {
|
53
|
-
value = localStorage.getItem(key);
|
54
|
-
if (value != null) {
|
55
|
-
return JSON.parse(localStorage.getItem(key));
|
56
|
-
} else {
|
57
|
-
return undef;
|
58
|
-
}
|
59
|
-
}
|
38
|
+
throw new Error(newmsg);
|
60
39
|
};
|
61
40
|
|
62
41
|
// ---------------------------------------------------------------------------
|
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
|
|