@jdeighan/coffee-utils 5.0.2 → 5.0.5

Sign up to get free protection for your applications and to get access to all the features.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@jdeighan/coffee-utils",
3
3
  "type": "module",
4
- "version": "5.0.2",
4
+ "version": "5.0.5",
5
5
  "description": "A set of utility functions for CoffeeScript",
6
6
  "main": "coffee_utils.js",
7
7
  "exports": {
@@ -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
 
@@ -4,7 +4,7 @@ import yaml from 'js-yaml'
4
4
 
5
5
  import {
6
6
  assert, undef, isNumber, isInteger, isString, isHash, isFunction,
7
- escapeStr, sep_eq,
7
+ escapeStr, sep_eq, sep_dash
8
8
  } from '@jdeighan/coffee-utils'
9
9
  import {blockToArray} from '@jdeighan/coffee-utils/block'
10
10
  import {tabify, untabify} from '@jdeighan/coffee-utils/indent'
@@ -14,6 +14,19 @@ 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 = (item, label, ch='=') ->
21
+
22
+ if label
23
+ console.log ch.repeat(42)
24
+ console.log "[#{label}]:"
25
+ console.log untabify(orderedStringify(item))
26
+ else
27
+ console.log item
28
+ return
29
+
17
30
  # ---------------------------------------------------------------------------
18
31
 
19
32
  export setStringifier = (func) ->
package/src/log_utils.js CHANGED
@@ -13,7 +13,8 @@ import {
13
13
  isHash,
14
14
  isFunction,
15
15
  escapeStr,
16
- sep_eq
16
+ sep_eq,
17
+ sep_dash
17
18
  } from '@jdeighan/coffee-utils';
18
19
 
19
20
  import {
@@ -32,6 +33,18 @@ export var stringify = undef;
32
33
 
33
34
  export var id = 42;
34
35
 
36
+ // ---------------------------------------------------------------------------
37
+ // This is useful for debugging and easy to remove after debugging
38
+ export var LOG = function(item, label, ch = '=') {
39
+ if (label) {
40
+ console.log(ch.repeat(42));
41
+ console.log(`[${label}]:`);
42
+ console.log(untabify(orderedStringify(item)));
43
+ } else {
44
+ console.log(item);
45
+ }
46
+ };
47
+
35
48
  // ---------------------------------------------------------------------------
36
49
  export var setStringifier = function(func) {
37
50
  var orgStringifier;