@jdeighan/coffee-utils 11.0.2 → 11.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.
Files changed (37) hide show
  1. package/package.json +14 -13
  2. package/src/DataStores.coffee +6 -15
  3. package/src/DataStores.js +8 -21
  4. package/src/Section.coffee +1 -1
  5. package/src/Section.js +1 -2
  6. package/src/SectionMap.coffee +5 -7
  7. package/src/SectionMap.js +6 -14
  8. package/src/arrow.coffee +1 -1
  9. package/src/arrow.js +1 -1
  10. package/src/{block_utils.coffee → block.coffee} +5 -5
  11. package/src/{block_utils.js → block.js} +4 -6
  12. package/src/{browser_utils.coffee → browser.coffee} +1 -1
  13. package/src/{browser_utils.js → browser.js} +1 -1
  14. package/src/{debug_utils.coffee → debug.coffee} +7 -12
  15. package/src/{debug_utils.js → debug.js} +6 -25
  16. package/src/{fs_utils.coffee → fs.coffee} +5 -40
  17. package/src/{fs_utils.js → fs.js} +9 -51
  18. package/src/fsa.coffee +1 -2
  19. package/src/fsa.js +2 -5
  20. package/src/{html_utils.coffee → html.coffee} +5 -6
  21. package/src/{html_utils.js → html.js} +5 -10
  22. package/src/{indent_utils.coffee → indent.coffee} +7 -9
  23. package/src/{indent_utils.js → indent.js} +7 -9
  24. package/src/{log_utils.coffee → log.coffee} +5 -44
  25. package/src/{log_utils.js → log.js} +6 -55
  26. package/src/placeholders.coffee +1 -1
  27. package/src/placeholders.js +1 -2
  28. package/src/{server_utils.coffee → server.coffee} +1 -1
  29. package/src/{server_utils.js → server.js} +1 -1
  30. package/src/{call_stack.coffee → stack.coffee} +2 -2
  31. package/src/{call_stack.js → stack.js} +2 -2
  32. package/src/{svelte_utils.coffee → svelte.coffee} +4 -5
  33. package/src/{svelte_utils.js → svelte.js} +6 -10
  34. package/src/taml.coffee +20 -25
  35. package/src/taml.js +25 -34
  36. package/src/{coffee_utils.coffee → utils.coffee} +3 -4
  37. package/src/{coffee_utils.js → utils.js} +8 -15
@@ -1,12 +1,12 @@
1
1
  // Generated by CoffeeScript 2.7.0
2
- // log_utils.coffee
2
+ // log.coffee
3
3
  var doDebugLog, fixForTerminal, fourSpaces, loaded, maxOneLine, putBlock, putstr;
4
4
 
5
5
  import {
6
+ LOG,
6
7
  assert,
7
- error,
8
8
  croak
9
- } from '@jdeighan/unit-tester/utils';
9
+ } from '@jdeighan/exceptions';
10
10
 
11
11
  import {
12
12
  undef,
@@ -23,16 +23,9 @@ import {
23
23
  } from '@jdeighan/coffee-utils';
24
24
 
25
25
  import {
26
- blockToArray
26
+ toArray
27
27
  } from '@jdeighan/coffee-utils/block';
28
28
 
29
- import {
30
- tabify,
31
- untabify,
32
- indentation,
33
- indented
34
- } from '@jdeighan/coffee-utils/indent';
35
-
36
29
  import {
37
30
  toTAML
38
31
  } from '@jdeighan/coffee-utils/taml';
@@ -54,48 +47,6 @@ export var debugLog = function(flag = true) {
54
47
  }
55
48
  };
56
49
 
57
- // ---------------------------------------------------------------------------
58
- // This is useful for debugging
59
- export var LOG = function(...lArgs) {
60
- var item, label;
61
- [label, item] = lArgs;
62
- if (lArgs.length > 1) {
63
- // --- There's both a label and an item
64
- if (item === undef) {
65
- console.log(`${label} = undef`);
66
- } else if (item === null) {
67
- console.log(`${label} = null`);
68
- } else {
69
- console.log(sep_dash);
70
- console.log(`${label}:`);
71
- if (isString(item)) {
72
- console.log(untabify(item));
73
- } else {
74
- console.log(untabify(orderedStringify(item)));
75
- }
76
- console.log(sep_dash);
77
- }
78
- } else {
79
- console.log(label);
80
- }
81
- return true; // to allow use in boolean expressions
82
- };
83
-
84
-
85
- // --- Use this instead to make it easier to remove all instances
86
- export var DEBUG = LOG; // synonym
87
-
88
-
89
- // ---------------------------------------------------------------------------
90
- export var LOGLINES = function(label, lLines) {
91
- var i, len, line;
92
- LOG(`${label}:`);
93
- for (i = 0, len = lLines.length; i < len; i++) {
94
- line = lLines[i];
95
- LOG(`${OL(line)}`);
96
- }
97
- };
98
-
99
50
  // ---------------------------------------------------------------------------
100
51
  export var setStringifier = function(func) {
101
52
  var orgStringifier;
@@ -210,7 +161,7 @@ export var logItem = function(label, item, pre = '', itemPre = undef) {
210
161
  if (label) {
211
162
  putstr(`${pre}${label}:`);
212
163
  }
213
- ref = blockToArray(stringify(item, true));
164
+ ref = toArray(stringify(item, true));
214
165
  // --- escape special chars
215
166
  for (i = 0, len = ref.length; i < len; i++) {
216
167
  str = ref[i];
@@ -239,7 +190,7 @@ fixForTerminal = function(str) {
239
190
  putBlock = function(item, prefix = '') {
240
191
  var i, len, line, ref;
241
192
  putstr(`${prefix}${sep_eq}`);
242
- ref = blockToArray(item);
193
+ ref = toArray(item);
243
194
  for (i = 0, len = ref.length; i < len; i++) {
244
195
  line = ref[i];
245
196
  putstr(`${prefix}${escapeStr(line)}`);
@@ -1,6 +1,6 @@
1
1
  # placeholders.coffee
2
2
 
3
- import {assert, error, croak} from '@jdeighan/unit-tester/utils'
3
+ import {assert, croak} from '@jdeighan/exceptions'
4
4
  import {undef, defined} from '@jdeighan/coffee-utils'
5
5
 
6
6
  hDefOptions = {
@@ -4,9 +4,8 @@ var hDefOptions;
4
4
 
5
5
  import {
6
6
  assert,
7
- error,
8
7
  croak
9
- } from '@jdeighan/unit-tester/utils';
8
+ } from '@jdeighan/exceptions';
10
9
 
11
10
  import {
12
11
  undef,
@@ -1,4 +1,4 @@
1
- # server_utils.coffee
1
+ # server.coffee
2
2
 
3
3
  import getline from 'readline-sync'
4
4
  import {execSync} from 'child_process'
@@ -1,5 +1,5 @@
1
1
  // Generated by CoffeeScript 2.7.0
2
- // server_utils.coffee
2
+ // server.coffee
3
3
  import getline from 'readline-sync';
4
4
 
5
5
  import {
@@ -1,6 +1,6 @@
1
- # call_stack.coffee
1
+ # stack.coffee
2
2
 
3
- import {assert, croak} from '@jdeighan/unit-tester/utils'
3
+ import {assert, croak} from '@jdeighan/exceptions'
4
4
  import {
5
5
  undef, defined, OL, escapeStr, deepCopy,
6
6
  isArray, isBoolean,
@@ -1,11 +1,11 @@
1
1
  // Generated by CoffeeScript 2.7.0
2
- // call_stack.coffee
2
+ // stack.coffee
3
3
  var doDebugStack;
4
4
 
5
5
  import {
6
6
  assert,
7
7
  croak
8
- } from '@jdeighan/unit-tester/utils';
8
+ } from '@jdeighan/exceptions';
9
9
 
10
10
  import {
11
11
  undef,
@@ -1,8 +1,7 @@
1
- # svelte_utils.coffee
1
+ # svelte.coffee
2
2
 
3
- import {assert, error, croak} from '@jdeighan/unit-tester/utils'
3
+ import {assert, croak, LOG} from '@jdeighan/exceptions'
4
4
  import {isFunction} from '@jdeighan/coffee-utils'
5
- import {log} from '@jdeighan/coffee-utils/log'
6
5
 
7
6
  # ---------------------------------------------------------------------------
8
7
  # svelteSourceCodeEsc - to display source code for a *.starbucks page
@@ -33,10 +32,10 @@ export onInterval = (func, secs, doLog=false) ->
33
32
  assert isFunction(func), "onInterval(): 1st arg not a function"
34
33
  ms = Math.floor(1000 * secs)
35
34
  if doLog
36
- log "calling func every #{ms} ms."
35
+ LOG "calling func every #{ms} ms."
37
36
  interval = setInterval(func, ms)
38
37
 
39
38
  return () ->
40
39
  if doLog
41
- log "destroying interval timer"
40
+ LOG "destroying interval timer"
42
41
  clearInterval interval
@@ -1,19 +1,15 @@
1
1
  // Generated by CoffeeScript 2.7.0
2
- // svelte_utils.coffee
2
+ // svelte.coffee
3
3
  import {
4
4
  assert,
5
- error,
6
- croak
7
- } from '@jdeighan/unit-tester/utils';
5
+ croak,
6
+ LOG
7
+ } from '@jdeighan/exceptions';
8
8
 
9
9
  import {
10
10
  isFunction
11
11
  } from '@jdeighan/coffee-utils';
12
12
 
13
- import {
14
- log
15
- } from '@jdeighan/coffee-utils/log';
16
-
17
13
  // ---------------------------------------------------------------------------
18
14
  // svelteSourceCodeEsc - to display source code for a *.starbucks page
19
15
  export var svelteSourceCodeEsc = function(str) {
@@ -32,12 +28,12 @@ export var onInterval = function(func, secs, doLog = false) {
32
28
  assert(isFunction(func), "onInterval(): 1st arg not a function");
33
29
  ms = Math.floor(1000 * secs);
34
30
  if (doLog) {
35
- log(`calling func every ${ms} ms.`);
31
+ LOG(`calling func every ${ms} ms.`);
36
32
  }
37
33
  interval = setInterval(func, ms);
38
34
  return function() {
39
35
  if (doLog) {
40
- log("destroying interval timer");
36
+ LOG("destroying interval timer");
41
37
  }
42
38
  return clearInterval(interval);
43
39
  };
package/src/taml.coffee CHANGED
@@ -2,16 +2,16 @@
2
2
 
3
3
  import yaml from 'js-yaml'
4
4
 
5
- import {assert, error, croak} from '@jdeighan/unit-tester/utils'
5
+ import {assert, croak} from '@jdeighan/exceptions'
6
6
  import {
7
- undef, defined, notdefined, oneline, isString, chomp, escapeStr,
7
+ undef, defined, notdefined, OL, chomp, escapeStr,
8
+ isString, isObject, isEmpty,
8
9
  } from '@jdeighan/coffee-utils'
9
- import {untabify, tabify, splitLine} from '@jdeighan/coffee-utils/indent'
10
- import {slurp} from '@jdeighan/coffee-utils/fs'
11
- import {debug} from '@jdeighan/coffee-utils/debug'
10
+ import {splitLine} from '@jdeighan/coffee-utils/indent'
12
11
  import {
13
- firstLine, blockToArray, arrayToBlock,
12
+ firstLine, toArray, toBlock,
14
13
  } from '@jdeighan/coffee-utils/block'
14
+ import {slurp} from '@jdeighan/coffee-utils/fs'
15
15
 
16
16
  # ---------------------------------------------------------------------------
17
17
  # isTAML - is the string valid TAML?
@@ -20,24 +20,16 @@ export isTAML = (text) ->
20
20
 
21
21
  return isString(text) && (firstLine(text).indexOf('---') == 0)
22
22
 
23
- # ---------------------------------------------------------------------------
24
-
25
- squote = (text) ->
26
-
27
- return "'" + text.replace(/'/g, "''") + "'"
28
-
29
23
  # ---------------------------------------------------------------------------
30
24
  # taml - convert valid TAML string to a JavaScript value
31
25
 
32
- export taml = (text) ->
26
+ export fromTAML = (text) ->
33
27
 
34
- debug "enter taml(#{oneline(text)})"
35
- if ! text?
36
- debug "return undef from taml() - text is not defined"
28
+ if notdefined(text)
37
29
  return undef
38
- assert isTAML(text), "taml(): string #{oneline(text)} isn't TAML"
30
+ assert isTAML(text), "string #{OL(text)} isn't TAML"
39
31
 
40
- lLines = for line in blockToArray(text)
32
+ lLines = for line in toArray(text)
41
33
  [level, str] = splitLine(line)
42
34
  prefix = ' '.repeat(level)
43
35
  if lMatches = line.match(///^
@@ -55,12 +47,7 @@ export taml = (text) ->
55
47
  else
56
48
  prefix + str
57
49
 
58
- debug "return from taml()"
59
- return yaml.load(arrayToBlock(lLines), {skipInvalid: true})
60
-
61
- # ---------------------------------------------------------------------------
62
-
63
- export fromTAML = taml
50
+ return yaml.load(toBlock(lLines), {skipInvalid: true})
64
51
 
65
52
  # ---------------------------------------------------------------------------
66
53
  # --- a replacer is (key, value) -> newvalue
@@ -69,6 +56,8 @@ myReplacer = (name, value) ->
69
56
 
70
57
  if isString(value)
71
58
  return escapeStr(value)
59
+ else if isObject(value, ['tamlReplacer'])
60
+ return value.tamlReplacer()
72
61
  else
73
62
  return value
74
63
 
@@ -90,10 +79,16 @@ export toTAML = (obj, hOptions={}) ->
90
79
  str = str.replace(/ /g, "\t")
91
80
  return "---\n" + chomp(str)
92
81
 
82
+ # ---------------------------------------------------------------------------
83
+
84
+ squote = (text) ->
85
+
86
+ return "'" + text.replace(/'/g, "''") + "'"
87
+
93
88
  # ---------------------------------------------------------------------------
94
89
  # slurpTAML - read TAML from a file
95
90
 
96
91
  export slurpTAML = (filepath) ->
97
92
 
98
93
  contents = slurp(filepath)
99
- return taml(contents)
94
+ return fromTAML(contents)
package/src/taml.js CHANGED
@@ -6,64 +6,52 @@ import yaml from 'js-yaml';
6
6
 
7
7
  import {
8
8
  assert,
9
- error,
10
9
  croak
11
- } from '@jdeighan/unit-tester/utils';
10
+ } from '@jdeighan/exceptions';
12
11
 
13
12
  import {
14
13
  undef,
15
14
  defined,
16
15
  notdefined,
17
- oneline,
18
- isString,
16
+ OL,
19
17
  chomp,
20
- escapeStr
18
+ escapeStr,
19
+ isString,
20
+ isObject,
21
+ isEmpty
21
22
  } from '@jdeighan/coffee-utils';
22
23
 
23
24
  import {
24
- untabify,
25
- tabify,
26
25
  splitLine
27
26
  } from '@jdeighan/coffee-utils/indent';
28
27
 
29
- import {
30
- slurp
31
- } from '@jdeighan/coffee-utils/fs';
32
-
33
- import {
34
- debug
35
- } from '@jdeighan/coffee-utils/debug';
36
-
37
28
  import {
38
29
  firstLine,
39
- blockToArray,
40
- arrayToBlock
30
+ toArray,
31
+ toBlock
41
32
  } from '@jdeighan/coffee-utils/block';
42
33
 
34
+ import {
35
+ slurp
36
+ } from '@jdeighan/coffee-utils/fs';
37
+
43
38
  // ---------------------------------------------------------------------------
44
39
  // isTAML - is the string valid TAML?
45
40
  export var isTAML = function(text) {
46
41
  return isString(text) && (firstLine(text).indexOf('---') === 0);
47
42
  };
48
43
 
49
- // ---------------------------------------------------------------------------
50
- squote = function(text) {
51
- return "'" + text.replace(/'/g, "''") + "'";
52
- };
53
-
54
44
  // ---------------------------------------------------------------------------
55
45
  // taml - convert valid TAML string to a JavaScript value
56
- export var taml = function(text) {
46
+ export var fromTAML = function(text) {
57
47
  var _, key, lLines, lMatches, level, line, prefix, str;
58
- debug(`enter taml(${oneline(text)})`);
59
- if (text == null) {
60
- debug("return undef from taml() - text is not defined");
48
+ if (notdefined(text)) {
61
49
  return undef;
62
50
  }
63
- assert(isTAML(text), `taml(): string ${oneline(text)} isn't TAML`);
51
+ assert(isTAML(text), `string ${OL(text)} isn't TAML`);
64
52
  lLines = (function() {
65
53
  var i, len, ref, results;
66
- ref = blockToArray(text);
54
+ ref = toArray(text);
67
55
  results = [];
68
56
  for (i = 0, len = ref.length; i < len; i++) {
69
57
  line = ref[i];
@@ -82,20 +70,18 @@ export var taml = function(text) {
82
70
  }
83
71
  return results;
84
72
  })();
85
- debug("return from taml()");
86
- return yaml.load(arrayToBlock(lLines), {
73
+ return yaml.load(toBlock(lLines), {
87
74
  skipInvalid: true
88
75
  });
89
76
  };
90
77
 
91
- // ---------------------------------------------------------------------------
92
- export var fromTAML = taml;
93
-
94
78
  // ---------------------------------------------------------------------------
95
79
  // --- a replacer is (key, value) -> newvalue
96
80
  myReplacer = function(name, value) {
97
81
  if (isString(value)) {
98
82
  return escapeStr(value);
83
+ } else if (isObject(value, ['tamlReplacer'])) {
84
+ return value.tamlReplacer();
99
85
  } else {
100
86
  return value;
101
87
  }
@@ -121,10 +107,15 @@ export var toTAML = function(obj, hOptions = {}) {
121
107
  return "---\n" + chomp(str);
122
108
  };
123
109
 
110
+ // ---------------------------------------------------------------------------
111
+ squote = function(text) {
112
+ return "'" + text.replace(/'/g, "''") + "'";
113
+ };
114
+
124
115
  // ---------------------------------------------------------------------------
125
116
  // slurpTAML - read TAML from a file
126
117
  export var slurpTAML = function(filepath) {
127
118
  var contents;
128
119
  contents = slurp(filepath);
129
- return taml(contents);
120
+ return fromTAML(contents);
130
121
  };
@@ -1,11 +1,10 @@
1
- # coffee_utils.coffee
1
+ # utils.coffee
2
2
 
3
- import {assert, error, croak} from '@jdeighan/unit-tester/utils'
3
+ import {LOG, assert, croak} from '@jdeighan/exceptions'
4
4
 
5
5
  export sep_dash = '-'.repeat(42)
6
6
  export sep_eq = '='.repeat(42)
7
7
  `export const undef = undefined`
8
- LOG = (lArgs...) -> console.log lArgs... # synonym for console.log()
9
8
 
10
9
  # ---------------------------------------------------------------------------
11
10
  # TEMP!!!!!
@@ -258,7 +257,7 @@ export nonEmpty = (x) ->
258
257
  if isHash(x)
259
258
  return Object.keys(x).length > 0
260
259
  else
261
- error "isEmpty(): Invalid parameter"
260
+ croak "isEmpty(): Invalid parameter"
262
261
 
263
262
  # ---------------------------------------------------------------------------
264
263
 
@@ -1,12 +1,10 @@
1
1
  // Generated by CoffeeScript 2.7.0
2
- // coffee_utils.coffee
3
- var LOG;
4
-
2
+ // utils.coffee
5
3
  import {
4
+ LOG,
6
5
  assert,
7
- error,
8
6
  croak
9
- } from '@jdeighan/unit-tester/utils';
7
+ } from '@jdeighan/exceptions';
10
8
 
11
9
  export var sep_dash = '-'.repeat(42);
12
10
 
@@ -14,11 +12,6 @@ export var sep_eq = '='.repeat(42);
14
12
 
15
13
  export const undef = undefined;
16
14
 
17
- LOG = function(...lArgs) {
18
- return console.log(...lArgs); // synonym for console.log()
19
- };
20
-
21
-
22
15
  // ---------------------------------------------------------------------------
23
16
  // TEMP!!!!!
24
17
  export var isComment = function(line) {
@@ -103,8 +96,8 @@ export var isConstructor = function(f) {
103
96
  var err;
104
97
  try {
105
98
  new f();
106
- } catch (error1) {
107
- err = error1;
99
+ } catch (error) {
100
+ err = error;
108
101
  if (err.message.indexOf('is not a constructor') >= 0) {
109
102
  return false;
110
103
  }
@@ -280,7 +273,7 @@ export var nonEmpty = function(x) {
280
273
  if (isHash(x)) {
281
274
  return Object.keys(x).length > 0;
282
275
  } else {
283
- return error("isEmpty(): Invalid parameter");
276
+ return croak("isEmpty(): Invalid parameter");
284
277
  }
285
278
  };
286
279
 
@@ -516,8 +509,8 @@ export var deepCopy = function(obj) {
516
509
  objStr = JSON.stringify(obj);
517
510
  try {
518
511
  newObj = JSON.parse(objStr);
519
- } catch (error1) {
520
- err = error1;
512
+ } catch (error) {
513
+ err = error;
521
514
  croak("ERROR: err.message", objStr);
522
515
  }
523
516
  return newObj;