@jdeighan/coffee-utils 8.0.17 → 8.0.18

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": "8.0.17",
4
+ "version": "8.0.18",
5
5
  "description": "A set of utility functions for CoffeeScript",
6
6
  "main": "coffee_utils.js",
7
7
  "exports": {
@@ -55,6 +55,6 @@
55
55
  "svelte": "^3.49.0"
56
56
  },
57
57
  "devDependencies": {
58
- "@jdeighan/unit-tester": "^2.0.16"
58
+ "@jdeighan/unit-tester": "^2.0.17"
59
59
  }
60
60
  }
@@ -4,9 +4,8 @@ import pathlib from 'path'
4
4
  import yaml from 'js-yaml'
5
5
  import {writable, readable, get} from 'svelte/store'
6
6
 
7
- import {
8
- assert, undef, pass, error, isEmpty,
9
- } from '@jdeighan/coffee-utils'
7
+ import {assert, error} from '@jdeighan/unit-tester/utils'
8
+ import {undef, pass, isEmpty} from '@jdeighan/coffee-utils'
10
9
  import {localStore} from '@jdeighan/coffee-utils/browser'
11
10
  import {
12
11
  withExt, slurp, barf, newerDestFileExists,
package/src/DataStores.js CHANGED
@@ -12,9 +12,12 @@ import {
12
12
 
13
13
  import {
14
14
  assert,
15
+ error
16
+ } from '@jdeighan/unit-tester/utils';
17
+
18
+ import {
15
19
  undef,
16
20
  pass,
17
- error,
18
21
  isEmpty
19
22
  } from '@jdeighan/coffee-utils';
20
23
 
@@ -1,7 +1,8 @@
1
1
  # Section.coffee
2
2
 
3
+ import {assert, error, croak} from '@jdeighan/unit-tester/utils'
3
4
  import {
4
- assert, pass, undef, defined, croak, isArray,
5
+ pass, undef, defined, isArray,
5
6
  } from '@jdeighan/coffee-utils'
6
7
  import {arrayToBlock} from '@jdeighan/coffee-utils/block'
7
8
  import {indented} from '@jdeighan/coffee-utils/indent'
package/src/Section.js CHANGED
@@ -2,10 +2,14 @@
2
2
  // Section.coffee
3
3
  import {
4
4
  assert,
5
+ error,
6
+ croak
7
+ } from '@jdeighan/unit-tester/utils';
8
+
9
+ import {
5
10
  pass,
6
11
  undef,
7
12
  defined,
8
- croak,
9
13
  isArray
10
14
  } from '@jdeighan/coffee-utils';
11
15
 
@@ -1,7 +1,8 @@
1
1
  # SectionMap.coffee
2
2
 
3
+ import {assert, error, croak} from '@jdeighan/unit-tester/utils'
3
4
  import {
4
- assert, pass, undef, defined, croak, OL, isEmpty, nonEmpty,
5
+ pass, undef, defined, OL, isEmpty, nonEmpty,
5
6
  isString, isHash, isArray, isUniqueTree, isNonEmptyString,
6
7
  isNonEmptyArray,
7
8
  } from '@jdeighan/coffee-utils'
package/src/SectionMap.js CHANGED
@@ -4,10 +4,14 @@ var isSectionName, isSetName;
4
4
 
5
5
  import {
6
6
  assert,
7
+ error,
8
+ croak
9
+ } from '@jdeighan/unit-tester/utils';
10
+
11
+ import {
7
12
  pass,
8
13
  undef,
9
14
  defined,
10
- croak,
11
15
  OL,
12
16
  isEmpty,
13
17
  nonEmpty,
package/src/arrow.coffee CHANGED
@@ -1,6 +1,7 @@
1
1
  # arrow.coffee
2
2
 
3
- import {undef, assert, OL, setCharsAt} from '@jdeighan/coffee-utils'
3
+ import {assert} from '@jdeighan/unit-tester/utils'
4
+ import {undef, OL, setCharsAt} from '@jdeighan/coffee-utils'
4
5
 
5
6
  # --- We use spaces here because Windows Terminal handles TAB chars badly
6
7
 
package/src/arrow.js CHANGED
@@ -1,8 +1,11 @@
1
1
  // Generated by CoffeeScript 2.7.0
2
2
  // arrow.coffee
3
+ import {
4
+ assert
5
+ } from '@jdeighan/unit-tester/utils';
6
+
3
7
  import {
4
8
  undef,
5
- assert,
6
9
  OL,
7
10
  setCharsAt
8
11
  } from '@jdeighan/coffee-utils';
@@ -3,8 +3,9 @@
3
3
  import fs from 'fs'
4
4
  import readline from 'readline'
5
5
 
6
+ import {assert, error} from '@jdeighan/unit-tester/utils'
6
7
  import {
7
- undef, assert, defined, isEmpty, isString, isArray, nonEmpty, error, rtrim,
8
+ undef, defined, isEmpty, isString, isArray, nonEmpty, rtrim,
8
9
  } from '@jdeighan/coffee-utils'
9
10
 
10
11
  # ---------------------------------------------------------------------------
@@ -5,14 +5,17 @@ import fs from 'fs';
5
5
  import readline from 'readline';
6
6
 
7
7
  import {
8
- undef,
9
8
  assert,
9
+ error
10
+ } from '@jdeighan/unit-tester/utils';
11
+
12
+ import {
13
+ undef,
10
14
  defined,
11
15
  isEmpty,
12
16
  isString,
13
17
  isArray,
14
18
  nonEmpty,
15
- error,
16
19
  rtrim
17
20
  } from '@jdeighan/coffee-utils';
18
21
 
@@ -1,7 +1,8 @@
1
1
  # call_stack.coffee
2
2
 
3
+ import {assert, croak} from '@jdeighan/unit-tester/utils'
3
4
  import {
4
- undef, defined, croak, assert, OL, escapeStr, deepCopy,
5
+ undef, defined, OL, escapeStr, deepCopy,
5
6
  isArray, isBoolean,
6
7
  } from '@jdeighan/coffee-utils'
7
8
  import {LOG} from '@jdeighan/coffee-utils/log'
package/src/call_stack.js CHANGED
@@ -2,11 +2,14 @@
2
2
  // call_stack.coffee
3
3
  var doDebugStack;
4
4
 
5
+ import {
6
+ assert,
7
+ croak
8
+ } from '@jdeighan/unit-tester/utils';
9
+
5
10
  import {
6
11
  undef,
7
12
  defined,
8
- croak,
9
- assert,
10
13
  OL,
11
14
  escapeStr,
12
15
  deepCopy,
@@ -1,12 +1,12 @@
1
1
  # coffee_utils.coffee
2
2
 
3
+ import {assert, error, croak} from '@jdeighan/unit-tester/utils'
4
+
3
5
  export sep_dash = '-'.repeat(42)
4
6
  export sep_eq = '='.repeat(42)
5
7
  `export const undef = undefined`
6
8
  LOG = (lArgs...) -> console.log lArgs... # synonym for console.log()
7
9
 
8
- export doHaltOnError = false
9
-
10
10
  # ---------------------------------------------------------------------------
11
11
  # TEMP!!!!!
12
12
 
@@ -26,89 +26,11 @@ export eval_expr = (str) ->
26
26
  str = str.replace(/\bundef\b/g, 'undefined')
27
27
  return Function('"use strict";return (' + str + ')')();
28
28
 
29
- # ---------------------------------------------------------------------------
30
-
31
- export haltOnError = () ->
32
-
33
- doHaltOnError = true
34
-
35
29
  # ---------------------------------------------------------------------------
36
30
  # pass - do nothing
37
31
 
38
32
  export pass = () ->
39
33
 
40
- # ---------------------------------------------------------------------------
41
- # error - throw an error
42
-
43
- export error = (message) ->
44
-
45
- if doHaltOnError
46
- console.trace("ERROR: #{message}")
47
- process.exit()
48
- throw new Error(message)
49
-
50
- # ---------------------------------------------------------------------------
51
-
52
- getCallers = (stackTrace, lExclude=[]) ->
53
-
54
- iter = stackTrace.matchAll(///
55
- at
56
- \s+
57
- (?:
58
- async
59
- \s+
60
- )?
61
- ([^\s(]+)
62
- ///g)
63
- if !iter
64
- return ["<unknown>"]
65
-
66
- lCallers = []
67
- for lMatches from iter
68
- [_, caller] = lMatches
69
- if (caller.indexOf('file://') == 0)
70
- break
71
- if caller not in lExclude
72
- lCallers.push caller
73
-
74
- return lCallers
75
-
76
- # ---------------------------------------------------------------------------
77
- # assert - mimic nodejs's assert
78
- # return true so we can use it in boolean expressions
79
-
80
- export assert = (cond, msg) ->
81
-
82
- if ! cond
83
- stackTrace = new Error().stack
84
- lCallers = getCallers(stackTrace, ['assert'])
85
-
86
- console.log '--------------------'
87
- console.log 'JavaScript CALL STACK:'
88
- for caller in lCallers
89
- console.log " #{caller}"
90
- console.log '--------------------'
91
- console.log "ERROR: #{msg} (in #{lCallers[0]}())"
92
- if doHaltOnError
93
- process.exit()
94
- error msg
95
- return true
96
-
97
- # ---------------------------------------------------------------------------
98
- # croak - throws an error after possibly printing useful info
99
-
100
- export croak = (err, label, obj) ->
101
-
102
- curmsg = if isString(err) then err else err.message
103
- newmsg = """
104
- ERROR (croak): #{curmsg}
105
- #{label}:
106
- #{JSON.stringify(obj)}
107
- """
108
-
109
- # --- re-throw the error
110
- throw new Error(newmsg)
111
-
112
34
  # ---------------------------------------------------------------------------
113
35
 
114
36
  export getClassName = (obj) ->
@@ -131,7 +53,7 @@ export patchStr = (bigstr, pos, str) ->
131
53
 
132
54
  export isString = (x) ->
133
55
 
134
- return typeof x == 'string' || x instanceof String
56
+ return (typeof x == 'string') || (x instanceof String)
135
57
 
136
58
  # ---------------------------------------------------------------------------
137
59
 
@@ -1,7 +1,12 @@
1
1
  // Generated by CoffeeScript 2.7.0
2
- // coffee_utils.coffee
3
- var LOG, getCallers,
4
- indexOf = [].indexOf;
2
+ // coffee_utils.coffee
3
+ var LOG;
4
+
5
+ import {
6
+ assert,
7
+ error,
8
+ croak
9
+ } from '@jdeighan/unit-tester/utils';
5
10
 
6
11
  export var sep_dash = '-'.repeat(42);
7
12
 
@@ -13,7 +18,6 @@ LOG = function(...lArgs) {
13
18
  return console.log(...lArgs); // synonym for console.log()
14
19
  };
15
20
 
16
- export var doHaltOnError = false;
17
21
 
18
22
  // ---------------------------------------------------------------------------
19
23
  // TEMP!!!!!
@@ -29,81 +33,10 @@ export var eval_expr = function(str) {
29
33
  return Function('"use strict";return (' + str + ')')();
30
34
  };
31
35
 
32
- // ---------------------------------------------------------------------------
33
- export var haltOnError = function() {
34
- return doHaltOnError = true;
35
- };
36
-
37
36
  // ---------------------------------------------------------------------------
38
37
  // pass - do nothing
39
38
  export var pass = function() {};
40
39
 
41
- // ---------------------------------------------------------------------------
42
- // error - throw an error
43
- export var error = function(message) {
44
- if (doHaltOnError) {
45
- console.trace(`ERROR: ${message}`);
46
- process.exit();
47
- }
48
- throw new Error(message);
49
- };
50
-
51
- // ---------------------------------------------------------------------------
52
- getCallers = function(stackTrace, lExclude = []) {
53
- var _, caller, iter, lCallers, lMatches;
54
- iter = stackTrace.matchAll(/at\s+(?:async\s+)?([^\s(]+)/g);
55
- if (!iter) {
56
- return ["<unknown>"];
57
- }
58
- lCallers = [];
59
- for (lMatches of iter) {
60
- [_, caller] = lMatches;
61
- if (caller.indexOf('file://') === 0) {
62
- break;
63
- }
64
- if (indexOf.call(lExclude, caller) < 0) {
65
- lCallers.push(caller);
66
- }
67
- }
68
- return lCallers;
69
- };
70
-
71
- // ---------------------------------------------------------------------------
72
- // assert - mimic nodejs's assert
73
- // return true so we can use it in boolean expressions
74
- export var assert = function(cond, msg) {
75
- var caller, i, lCallers, len, stackTrace;
76
- if (!cond) {
77
- stackTrace = new Error().stack;
78
- lCallers = getCallers(stackTrace, ['assert']);
79
- console.log('--------------------');
80
- console.log('JavaScript CALL STACK:');
81
- for (i = 0, len = lCallers.length; i < len; i++) {
82
- caller = lCallers[i];
83
- console.log(` ${caller}`);
84
- }
85
- console.log('--------------------');
86
- console.log(`ERROR: ${msg} (in ${lCallers[0]}())`);
87
- if (doHaltOnError) {
88
- process.exit();
89
- }
90
- error(msg);
91
- }
92
- return true;
93
- };
94
-
95
- // ---------------------------------------------------------------------------
96
- // croak - throws an error after possibly printing useful info
97
- export var croak = function(err, label, obj) {
98
- var curmsg, newmsg;
99
- curmsg = isString(err) ? err : err.message;
100
- newmsg = `ERROR (croak): ${curmsg}
101
- ${label}:
102
- ${JSON.stringify(obj)}`;
103
- // --- re-throw the error
104
- throw new Error(newmsg);
105
- };
106
-
107
40
  // ---------------------------------------------------------------------------
108
41
  export var getClassName = function(obj) {
109
42
  if (typeof obj !== 'object') {
@@ -125,7 +58,7 @@ export var patchStr = function(bigstr, pos, str) {
125
58
 
126
59
  // ---------------------------------------------------------------------------
127
60
  export var isString = function(x) {
128
- return typeof x === 'string' || x instanceof String;
61
+ return (typeof x === 'string') || (x instanceof String);
129
62
  };
130
63
 
131
64
  // ---------------------------------------------------------------------------
@@ -1,7 +1,8 @@
1
1
  # debug_utils.coffee
2
2
 
3
+ import {assert, error, croak} from '@jdeighan/unit-tester/utils'
3
4
  import {
4
- assert, undef, error, croak, warn, defined,
5
+ undef, warn, defined,
5
6
  isString, isFunction, isBoolean, patchStr,
6
7
  OL, escapeStr, isNumber, isArray, words, pass,
7
8
  } from '@jdeighan/coffee-utils'
@@ -5,9 +5,12 @@ var lFuncList, reMethod, strFuncList,
5
5
 
6
6
  import {
7
7
  assert,
8
- undef,
9
8
  error,
10
- croak,
9
+ croak
10
+ } from '@jdeighan/unit-tester/utils';
11
+
12
+ import {
13
+ undef,
11
14
  warn,
12
15
  defined,
13
16
  isString,
@@ -5,9 +5,10 @@ import urllib from 'url'
5
5
  import fs from 'fs'
6
6
  import NReadLines from 'n-readlines'
7
7
 
8
+ import {assert, error, croak} from '@jdeighan/unit-tester/utils'
8
9
  import {
9
- assert, undef, pass, defined, rtrim, error, isEmpty, nonEmpty,
10
- isString, isArray, isHash, isRegExp, isFunction, croak, OL,
10
+ undef, pass, defined, rtrim, isEmpty, nonEmpty,
11
+ isString, isArray, isHash, isRegExp, isFunction, OL,
11
12
  } from '@jdeighan/coffee-utils'
12
13
  import {log, LOG} from '@jdeighan/coffee-utils/log'
13
14
  import {debug} from '@jdeighan/coffee-utils/debug'
package/src/fs_utils.js CHANGED
@@ -12,11 +12,15 @@ import NReadLines from 'n-readlines';
12
12
 
13
13
  import {
14
14
  assert,
15
+ error,
16
+ croak
17
+ } from '@jdeighan/unit-tester/utils';
18
+
19
+ import {
15
20
  undef,
16
21
  pass,
17
22
  defined,
18
23
  rtrim,
19
- error,
20
24
  isEmpty,
21
25
  nonEmpty,
22
26
  isString,
@@ -24,7 +28,6 @@ import {
24
28
  isHash,
25
29
  isRegExp,
26
30
  isFunction,
27
- croak,
28
31
  OL
29
32
  } from '@jdeighan/coffee-utils';
30
33
 
@@ -1,7 +1,8 @@
1
1
  # indent_utils.coffee
2
2
 
3
+ import {assert, error} from '@jdeighan/unit-tester/utils'
3
4
  import {
4
- assert, undef, error, escapeStr, defined,
5
+ undef, escapeStr, defined,
5
6
  OL, isInteger, isString, isArray, isEmpty, rtrim,
6
7
  } from '@jdeighan/coffee-utils'
7
8
  import {arrayToBlock, blockToArray} from '@jdeighan/coffee-utils/block'
@@ -2,8 +2,11 @@
2
2
  // indent_utils.coffee
3
3
  import {
4
4
  assert,
5
+ error
6
+ } from '@jdeighan/unit-tester/utils';
7
+
8
+ import {
5
9
  undef,
6
- error,
7
10
  escapeStr,
8
11
  defined,
9
12
  OL,
@@ -2,8 +2,9 @@
2
2
 
3
3
  import yaml from 'js-yaml'
4
4
 
5
+ import {assert, error, croak} from '@jdeighan/unit-tester/utils'
5
6
  import {
6
- assert, undef, isNumber, isInteger, isString, isHash, isFunction,
7
+ undef, isNumber, isInteger, isString, isHash, isFunction,
7
8
  escapeStr, sep_eq, sep_dash, pass, OL,
8
9
  } from '@jdeighan/coffee-utils'
9
10
  import {blockToArray} from '@jdeighan/coffee-utils/block'
package/src/log_utils.js CHANGED
@@ -6,6 +6,11 @@ import yaml from 'js-yaml';
6
6
 
7
7
  import {
8
8
  assert,
9
+ error,
10
+ croak
11
+ } from '@jdeighan/unit-tester/utils';
12
+
13
+ import {
9
14
  undef,
10
15
  isNumber,
11
16
  isInteger,
@@ -1,6 +1,7 @@
1
1
  # placeholders.coffee
2
2
 
3
- import {assert, undef, defined, croak} from '@jdeighan/coffee-utils'
3
+ import {assert, error, croak} from '@jdeighan/unit-tester/utils'
4
+ import {undef, defined} from '@jdeighan/coffee-utils'
4
5
 
5
6
  hDefOptions = {
6
7
  pre: '__'
@@ -4,9 +4,13 @@ var hDefOptions;
4
4
 
5
5
  import {
6
6
  assert,
7
- undef,
8
- defined,
7
+ error,
9
8
  croak
9
+ } from '@jdeighan/unit-tester/utils';
10
+
11
+ import {
12
+ undef,
13
+ defined
10
14
  } from '@jdeighan/coffee-utils';
11
15
 
12
16
  hDefOptions = {
@@ -1,6 +1,7 @@
1
1
  # svelte_utils.coffee
2
2
 
3
- import {assert, isFunction} from '@jdeighan/coffee-utils'
3
+ import {assert, error, croak} from '@jdeighan/unit-tester/utils'
4
+ import {isFunction} from '@jdeighan/coffee-utils'
4
5
  import {log} from '@jdeighan/coffee-utils/log'
5
6
 
6
7
  # ---------------------------------------------------------------------------
@@ -2,6 +2,11 @@
2
2
  // svelte_utils.coffee
3
3
  import {
4
4
  assert,
5
+ error,
6
+ croak
7
+ } from '@jdeighan/unit-tester/utils';
8
+
9
+ import {
5
10
  isFunction
6
11
  } from '@jdeighan/coffee-utils';
7
12
 
package/src/taml.coffee CHANGED
@@ -2,8 +2,9 @@
2
2
 
3
3
  import yaml from 'js-yaml'
4
4
 
5
+ import {assert, error, croak} from '@jdeighan/unit-tester/utils'
5
6
  import {
6
- assert, undef, oneline, isString,
7
+ undef, oneline, isString,
7
8
  } from '@jdeighan/coffee-utils'
8
9
  import {untabify, tabify, splitLine} from '@jdeighan/coffee-utils/indent'
9
10
  import {slurp} from '@jdeighan/coffee-utils/fs'
package/src/taml.js CHANGED
@@ -6,6 +6,11 @@ import yaml from 'js-yaml';
6
6
 
7
7
  import {
8
8
  assert,
9
+ error,
10
+ croak
11
+ } from '@jdeighan/unit-tester/utils';
12
+
13
+ import {
9
14
  undef,
10
15
  oneline,
11
16
  isString