@jdeighan/coffee-utils 5.0.1 → 5.0.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@jdeighan/coffee-utils",
3
3
  "type": "module",
4
- "version": "5.0.1",
4
+ "version": "5.0.4",
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.4"
53
+ "@jdeighan/unit-tester": "^1.0.5"
57
54
  }
58
55
  }
@@ -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, localStore, isEmpty,
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
@@ -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';
@@ -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
+
@@ -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
+ };
@@ -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')
@@ -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') {
@@ -25,7 +25,7 @@ export splitLine = (line) ->
25
25
 
26
26
  export indentation = (level) ->
27
27
 
28
- assert (level >= 0), "indented(): negative level"
28
+ assert (level >= 0), "indentation(): negative level"
29
29
  return '\t'.repeat(level)
30
30
 
31
31
  # ---------------------------------------------------------------------------
@@ -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, "indented(): negative level");
38
+ assert(level >= 0, "indentation(): negative level");
39
39
  return '\t'.repeat(level);
40
40
  };
41
41
 
@@ -14,6 +14,14 @@ logger = undef
14
14
  export stringify = undef
15
15
  export id = 42
16
16
 
17
+ # ---------------------------------------------------------------------------
18
+ # This is useful for debugging and easy to remove after debugging
19
+
20
+ export LOG = (lArgs...) ->
21
+
22
+ console.log lArgs...
23
+ return
24
+
17
25
  # ---------------------------------------------------------------------------
18
26
 
19
27
  export setStringifier = (func) ->
package/src/log_utils.js CHANGED
@@ -32,6 +32,12 @@ export var stringify = undef;
32
32
 
33
33
  export var id = 42;
34
34
 
35
+ // ---------------------------------------------------------------------------
36
+ // This is useful for debugging and easy to remove after debugging
37
+ export var LOG = function(...lArgs) {
38
+ console.log(...lArgs);
39
+ };
40
+
35
41
  // ---------------------------------------------------------------------------
36
42
  export var setStringifier = function(func) {
37
43
  var orgStringifier;