@jdeighan/coffee-utils 11.0.2 → 11.0.3

Sign up to get free protection for your applications and to get access to all the features.
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
package/package.json CHANGED
@@ -1,22 +1,22 @@
1
1
  {
2
2
  "name": "@jdeighan/coffee-utils",
3
3
  "type": "module",
4
- "version": "11.0.2",
4
+ "version": "11.0.3",
5
5
  "description": "A set of utility functions for CoffeeScript",
6
6
  "main": "coffee_utils.js",
7
7
  "exports": {
8
- ".": "./src/coffee_utils.js",
9
- "./server": "./src/server_utils.js",
10
- "./browser": "./src/browser_utils.js",
11
- "./fs": "./src/fs_utils.js",
12
- "./log": "./src/log_utils.js",
13
- "./block": "./src/block_utils.js",
14
- "./indent": "./src/indent_utils.js",
15
- "./html": "./src/html_utils.js",
16
- "./stack": "./src/call_stack.js",
17
- "./debug": "./src/debug_utils.js",
8
+ ".": "./src/utils.js",
9
+ "./server": "./src/server.js",
10
+ "./browser": "./src/browser.js",
11
+ "./fs": "./src/fs.js",
12
+ "./log": "./src/log.js",
13
+ "./block": "./src/block.js",
14
+ "./indent": "./src/indent.js",
15
+ "./html": "./src/html.js",
16
+ "./stack": "./src/stack.js",
17
+ "./debug": "./src/debug.js",
18
18
  "./arrow": "./src/arrow.js",
19
- "./svelte": "./src/svelte_utils.js",
19
+ "./svelte": "./src/svelte.js",
20
20
  "./store": "./src/DataStores.js",
21
21
  "./taml": "./src/taml.js",
22
22
  "./placeholders": "./src/placeholders.js",
@@ -50,6 +50,7 @@
50
50
  },
51
51
  "homepage": "https://github.com/johndeighan/coffee-utils#readme",
52
52
  "dependencies": {
53
+ "@jdeighan/exceptions": "^1.0.3",
53
54
  "cross-env": "^7.0.3",
54
55
  "js-yaml": "^4.1.0",
55
56
  "n-readlines": "^1.0.1",
@@ -57,6 +58,6 @@
57
58
  "svelte": "^3.50.1"
58
59
  },
59
60
  "devDependencies": {
60
- "@jdeighan/unit-tester": "^2.0.24"
61
+ "@jdeighan/unit-tester": "^2.0.27"
61
62
  }
62
63
  }
@@ -1,16 +1,15 @@
1
1
  # DataStores.coffee
2
2
 
3
3
  import pathlib from 'path'
4
- import yaml from 'js-yaml'
5
4
  import {writable, readable, get} from 'svelte/store'
6
5
 
7
- import {assert, error} from '@jdeighan/unit-tester/utils'
8
- import {undef, pass, isEmpty} from '@jdeighan/coffee-utils'
6
+ import {assert, croak} from '@jdeighan/exceptions'
7
+ import {undef, pass} from '@jdeighan/coffee-utils'
9
8
  import {localStore} from '@jdeighan/coffee-utils/browser'
10
9
  import {
11
10
  withExt, slurp, barf, newerDestFileExists,
12
11
  } from '@jdeighan/coffee-utils/fs'
13
- import {untabify} from '@jdeighan/coffee-utils/indent'
12
+ import {fromTAML} from '@jdeighan/coffee-utils/taml'
14
13
 
15
14
  # ---------------------------------------------------------------------------
16
15
 
@@ -46,7 +45,7 @@ export class LocalStorageDataStore extends WritableDataStore
46
45
 
47
46
  set: (value) ->
48
47
  if ! value?
49
- error "LocalStorageStore.set(): cannont set to undef"
48
+ croak "LocalStorageStore.set(): cannont set to undef"
50
49
  super value
51
50
  localStore @masterKey, value
52
51
 
@@ -63,7 +62,7 @@ export class PropsDataStore extends LocalStorageDataStore
63
62
 
64
63
  setProp: (name, value) ->
65
64
  if ! name?
66
- error "PropStore.setProp(): empty key"
65
+ croak "PropStore.setProp(): empty key"
67
66
  @update (hPrefs) ->
68
67
  hPrefs[name] = value
69
68
  return hPrefs
@@ -122,20 +121,12 @@ export class TAMLDataStore extends WritableDataStore
122
121
 
123
122
  constructor: (str) ->
124
123
 
125
- super taml(str)
124
+ super fromTAML(str)
126
125
 
127
126
  # ---------------------------------------------------------------------------
128
127
  # UTILITIES
129
128
  # ---------------------------------------------------------------------------
130
129
 
131
- export taml = (text) ->
132
-
133
- if ! text?
134
- return undef
135
- return yaml.load(untabify(text, 1), {skipInvalid: true})
136
-
137
- # ---------------------------------------------------------------------------
138
-
139
130
  export brewTamlStr = (code, stub) ->
140
131
 
141
132
  return """
package/src/DataStores.js CHANGED
@@ -2,8 +2,6 @@
2
2
  // DataStores.coffee
3
3
  import pathlib from 'path';
4
4
 
5
- import yaml from 'js-yaml';
6
-
7
5
  import {
8
6
  writable,
9
7
  readable,
@@ -12,13 +10,12 @@ import {
12
10
 
13
11
  import {
14
12
  assert,
15
- error
16
- } from '@jdeighan/unit-tester/utils';
13
+ croak
14
+ } from '@jdeighan/exceptions';
17
15
 
18
16
  import {
19
17
  undef,
20
- pass,
21
- isEmpty
18
+ pass
22
19
  } from '@jdeighan/coffee-utils';
23
20
 
24
21
  import {
@@ -33,8 +30,8 @@ import {
33
30
  } from '@jdeighan/coffee-utils/fs';
34
31
 
35
32
  import {
36
- untabify
37
- } from '@jdeighan/coffee-utils/indent';
33
+ fromTAML
34
+ } from '@jdeighan/coffee-utils/taml';
38
35
 
39
36
  // ---------------------------------------------------------------------------
40
37
  export var WritableDataStore = class WritableDataStore {
@@ -72,7 +69,7 @@ export var LocalStorageDataStore = class LocalStorageDataStore extends WritableD
72
69
  // set() will also be called
73
70
  set(value) {
74
71
  if (value == null) {
75
- error("LocalStorageStore.set(): cannont set to undef");
72
+ croak("LocalStorageStore.set(): cannont set to undef");
76
73
  }
77
74
  super.set(value);
78
75
  return localStore(this.masterKey, value);
@@ -93,7 +90,7 @@ export var PropsDataStore = class PropsDataStore extends LocalStorageDataStore {
93
90
 
94
91
  setProp(name, value) {
95
92
  if (name == null) {
96
- error("PropStore.setProp(): empty key");
93
+ croak("PropStore.setProp(): empty key");
97
94
  }
98
95
  return this.update(function(hPrefs) {
99
96
  hPrefs[name] = value;
@@ -166,23 +163,13 @@ export var MousePosDataStore = class MousePosDataStore extends ReadableDataStore
166
163
  // ---------------------------------------------------------------------------
167
164
  export var TAMLDataStore = class TAMLDataStore extends WritableDataStore {
168
165
  constructor(str) {
169
- super(taml(str));
166
+ super(fromTAML(str));
170
167
  }
171
168
 
172
169
  };
173
170
 
174
171
  // ---------------------------------------------------------------------------
175
172
  // UTILITIES
176
- // ---------------------------------------------------------------------------
177
- export var taml = function(text) {
178
- if (text == null) {
179
- return undef;
180
- }
181
- return yaml.load(untabify(text, 1), {
182
- skipInvalid: true
183
- });
184
- };
185
-
186
173
  // ---------------------------------------------------------------------------
187
174
  export var brewTamlStr = function(code, stub) {
188
175
  return `import {TAMLDataStore} from '@jdeighan/starbucks/stores';
@@ -1,6 +1,6 @@
1
1
  # Section.coffee
2
2
 
3
- import {assert, error, croak} from '@jdeighan/unit-tester/utils'
3
+ import {assert, croak} from '@jdeighan/exceptions'
4
4
  import {
5
5
  pass, undef, defined, isArray, isEmpty,
6
6
  } from '@jdeighan/coffee-utils'
package/src/Section.js CHANGED
@@ -2,9 +2,8 @@
2
2
  // Section.coffee
3
3
  import {
4
4
  assert,
5
- error,
6
5
  croak
7
- } from '@jdeighan/unit-tester/utils';
6
+ } from '@jdeighan/exceptions';
8
7
 
9
8
  import {
10
9
  pass,
@@ -1,16 +1,14 @@
1
1
  # SectionMap.coffee
2
2
 
3
- import {assert, error, croak} from '@jdeighan/unit-tester/utils'
3
+ import {LOG, assert, croak} from '@jdeighan/exceptions'
4
4
  import {
5
5
  pass, undef, defined, notdefined, OL, isEmpty, nonEmpty,
6
6
  isString, isHash, isArray, isUniqueTree, isNonEmptyString,
7
7
  isNonEmptyArray,
8
8
  } from '@jdeighan/coffee-utils'
9
- import {arrayToBlock} from '@jdeighan/coffee-utils/block'
10
- import {indented} from '@jdeighan/coffee-utils/indent'
11
- import {LOG} from '@jdeighan/coffee-utils/log'
9
+ import {toBlock} from '@jdeighan/coffee-utils/block'
12
10
  import {debug} from '@jdeighan/coffee-utils/debug'
13
- import {isTAML, taml} from '@jdeighan/coffee-utils/taml'
11
+ import {isTAML, fromTAML} from '@jdeighan/coffee-utils/taml'
14
12
  import {Section} from '@jdeighan/coffee-utils/section'
15
13
 
16
14
  # ---------------------------------------------------------------------------
@@ -35,7 +33,7 @@ export class SectionMap
35
33
  debug "enter SectionMap()", @lSectionTree
36
34
 
37
35
  if isTAML(@lSectionTree)
38
- @SectionTree = taml(@lSectionTree)
36
+ @SectionTree = fromTAML(@lSectionTree)
39
37
 
40
38
  assert isArray(@lSectionTree), "not an array"
41
39
 
@@ -127,7 +125,7 @@ export class SectionMap
127
125
  else
128
126
  croak "Bad item: #{OL(item)}"
129
127
 
130
- block = arrayToBlock(lBlocks)
128
+ block = toBlock(lBlocks)
131
129
  debug "block is", block
132
130
  if defined(setName)
133
131
  if defined(proc = hReplacers[setName])
package/src/SectionMap.js CHANGED
@@ -3,10 +3,10 @@
3
3
  var isSectionName, isSetName;
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
  pass,
@@ -25,24 +25,16 @@ import {
25
25
  } from '@jdeighan/coffee-utils';
26
26
 
27
27
  import {
28
- arrayToBlock
28
+ toBlock
29
29
  } from '@jdeighan/coffee-utils/block';
30
30
 
31
- import {
32
- indented
33
- } from '@jdeighan/coffee-utils/indent';
34
-
35
- import {
36
- LOG
37
- } from '@jdeighan/coffee-utils/log';
38
-
39
31
  import {
40
32
  debug
41
33
  } from '@jdeighan/coffee-utils/debug';
42
34
 
43
35
  import {
44
36
  isTAML,
45
- taml
37
+ fromTAML
46
38
  } from '@jdeighan/coffee-utils/taml';
47
39
 
48
40
  import {
@@ -66,7 +58,7 @@ export var SectionMap = class SectionMap {
66
58
  // --- lSectionTree is a tree of section/set names
67
59
  debug("enter SectionMap()", this.lSectionTree);
68
60
  if (isTAML(this.lSectionTree)) {
69
- this.SectionTree = taml(this.lSectionTree);
61
+ this.SectionTree = fromTAML(this.lSectionTree);
70
62
  }
71
63
  assert(isArray(this.lSectionTree), "not an array");
72
64
  // --- keys are section names, values are Section objects
@@ -162,7 +154,7 @@ export var SectionMap = class SectionMap {
162
154
  croak(`Bad item: ${OL(item)}`);
163
155
  }
164
156
  }
165
- block = arrayToBlock(lBlocks);
157
+ block = toBlock(lBlocks);
166
158
  debug("block is", block);
167
159
  if (defined(setName)) {
168
160
  if (defined(proc = hReplacers[setName])) {
package/src/arrow.coffee CHANGED
@@ -1,6 +1,6 @@
1
1
  # arrow.coffee
2
2
 
3
- import {assert} from '@jdeighan/unit-tester/utils'
3
+ import {assert} from '@jdeighan/exceptions'
4
4
  import {undef, OL, setCharsAt} from '@jdeighan/coffee-utils'
5
5
 
6
6
  # --- We use spaces here because Windows Terminal handles TAB chars badly
package/src/arrow.js CHANGED
@@ -2,7 +2,7 @@
2
2
  // arrow.coffee
3
3
  import {
4
4
  assert
5
- } from '@jdeighan/unit-tester/utils';
5
+ } from '@jdeighan/exceptions';
6
6
 
7
7
  import {
8
8
  undef,
@@ -1,13 +1,13 @@
1
- # block_utils.coffee
1
+ # block.coffee
2
2
 
3
3
  import fs from 'fs'
4
4
  import readline from 'readline'
5
5
 
6
- import {assert, error, croak} from '@jdeighan/unit-tester/utils'
6
+ import {assert, croak} from '@jdeighan/exceptions'
7
7
  import {
8
8
  undef, pass, defined, notdefined,
9
9
  isEmpty, isString, isArray, nonEmpty, isArrayOfStrings,
10
- escapeStr, rtrim, OL,
10
+ rtrim, OL,
11
11
  } from '@jdeighan/coffee-utils'
12
12
 
13
13
  # ---------------------------------------------------------------------------
@@ -208,7 +208,7 @@ export forEachBlock = (filepath, func, regexp = /^-{16,}$/) ->
208
208
  earlyExit = true
209
209
  return true
210
210
  else if result?
211
- error "forEachBlock() - callback returned '#{result}'"
211
+ croak "forEachBlock() - callback returned '#{result}'"
212
212
  lLines = []
213
213
  firstLineNum = lineNum+1
214
214
  else
@@ -240,7 +240,7 @@ export forEachSetOfBlocks = (filepath, func,
240
240
  earlyExit = true
241
241
  return true
242
242
  else if result?
243
- error "forEachSetOfBlocks() - callback returned '#{result}'"
243
+ croak "forEachSetOfBlocks() - callback returned '#{result}'"
244
244
  lBlocks = []
245
245
  firstLineNum = lineNum+1
246
246
  else if (line.match(block_regexp))
@@ -1,14 +1,13 @@
1
1
  // Generated by CoffeeScript 2.7.0
2
- // block_utils.coffee
2
+ // block.coffee
3
3
  import fs from 'fs';
4
4
 
5
5
  import readline from 'readline';
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,
@@ -20,7 +19,6 @@ import {
20
19
  isArray,
21
20
  nonEmpty,
22
21
  isArrayOfStrings,
23
- escapeStr,
24
22
  rtrim,
25
23
  OL
26
24
  } from '@jdeighan/coffee-utils';
@@ -254,7 +252,7 @@ export var forEachBlock = async function(filepath, func, regexp = /^-{16,}$/) {
254
252
  earlyExit = true;
255
253
  return true;
256
254
  } else if (result != null) {
257
- error(`forEachBlock() - callback returned '${result}'`);
255
+ croak(`forEachBlock() - callback returned '${result}'`);
258
256
  }
259
257
  }
260
258
  lLines = [];
@@ -286,7 +284,7 @@ export var forEachSetOfBlocks = async function(filepath, func, block_regexp = /^
286
284
  earlyExit = true;
287
285
  return true;
288
286
  } else if (result != null) {
289
- error(`forEachSetOfBlocks() - callback returned '${result}'`);
287
+ croak(`forEachSetOfBlocks() - callback returned '${result}'`);
290
288
  }
291
289
  }
292
290
  lBlocks = [];
@@ -1,4 +1,4 @@
1
- # browser_utils.coffee
1
+ # browser.coffee
2
2
 
3
3
  import {undef} from '@jdeighan/coffee-utils'
4
4
 
@@ -1,5 +1,5 @@
1
1
  // Generated by CoffeeScript 2.7.0
2
- // browser_utils.coffee
2
+ // browser.coffee
3
3
  var audio;
4
4
 
5
5
  import {
@@ -1,20 +1,15 @@
1
- # debug_utils.coffee
1
+ # debug.coffee
2
2
 
3
- import {assert, error, croak} from '@jdeighan/unit-tester/utils'
3
+ import {LOG, assert, croak} from '@jdeighan/exceptions'
4
4
  import {
5
- undef, warn, defined,
6
- isString, isFunction, isBoolean, patchStr,
7
- OL, escapeStr, isNumber, isArray, words, pass,
5
+ undef, defined, notdefined,
6
+ isString, isFunction, isBoolean, isArray,
7
+ OL, words, pass,
8
8
  } from '@jdeighan/coffee-utils'
9
- import {blockToArray} from '@jdeighan/coffee-utils/block'
10
- import {untabify} from '@jdeighan/coffee-utils/indent'
11
- import {slurp} from '@jdeighan/coffee-utils/fs'
12
9
  import {CallStack} from '@jdeighan/coffee-utils/stack'
10
+ import {prefix} from '@jdeighan/coffee-utils/arrow'
13
11
  import {
14
- prefix, addArrow, removeLastVbar, vbar,
15
- } from '@jdeighan/coffee-utils/arrow'
16
- import {
17
- log, logItem, logBareItem, LOG, shortEnough,
12
+ log, logItem, logBareItem, shortEnough,
18
13
  } from '@jdeighan/coffee-utils/log'
19
14
 
20
15
  # --- set in resetDebugging() and setDebugging()
@@ -1,58 +1,39 @@
1
1
  // Generated by CoffeeScript 2.7.0
2
- // debug_utils.coffee
2
+ // debug.coffee
3
3
  var lFuncList, reMethod, strFuncList,
4
4
  indexOf = [].indexOf;
5
5
 
6
6
  import {
7
+ LOG,
7
8
  assert,
8
- error,
9
9
  croak
10
- } from '@jdeighan/unit-tester/utils';
10
+ } from '@jdeighan/exceptions';
11
11
 
12
12
  import {
13
13
  undef,
14
- warn,
15
14
  defined,
15
+ notdefined,
16
16
  isString,
17
17
  isFunction,
18
18
  isBoolean,
19
- patchStr,
20
- OL,
21
- escapeStr,
22
- isNumber,
23
19
  isArray,
20
+ OL,
24
21
  words,
25
22
  pass
26
23
  } from '@jdeighan/coffee-utils';
27
24
 
28
- import {
29
- blockToArray
30
- } from '@jdeighan/coffee-utils/block';
31
-
32
- import {
33
- untabify
34
- } from '@jdeighan/coffee-utils/indent';
35
-
36
- import {
37
- slurp
38
- } from '@jdeighan/coffee-utils/fs';
39
-
40
25
  import {
41
26
  CallStack
42
27
  } from '@jdeighan/coffee-utils/stack';
43
28
 
44
29
  import {
45
- prefix,
46
- addArrow,
47
- removeLastVbar,
48
- vbar
30
+ prefix
49
31
  } from '@jdeighan/coffee-utils/arrow';
50
32
 
51
33
  import {
52
34
  log,
53
35
  logItem,
54
36
  logBareItem,
55
- LOG,
56
37
  shortEnough
57
38
  } from '@jdeighan/coffee-utils/log';
58
39