@jdeighan/coffee-utils 8.0.17 → 9.0.1
Sign up to get free protection for your applications and to get access to all the features.
- package/package.json +2 -2
- package/src/DataStores.coffee +2 -3
- package/src/DataStores.js +4 -1
- package/src/Section.coffee +2 -1
- package/src/Section.js +5 -1
- package/src/SectionMap.coffee +2 -1
- package/src/SectionMap.js +5 -1
- package/src/arrow.coffee +2 -1
- package/src/arrow.js +4 -1
- package/src/block_utils.coffee +2 -1
- package/src/block_utils.js +5 -2
- package/src/call_stack.coffee +2 -1
- package/src/call_stack.js +5 -2
- package/src/coffee_utils.coffee +3 -81
- package/src/coffee_utils.js +9 -76
- package/src/debug_utils.coffee +2 -1
- package/src/debug_utils.js +5 -2
- package/src/fs_utils.coffee +3 -2
- package/src/fs_utils.js +5 -2
- package/src/indent_utils.coffee +2 -1
- package/src/indent_utils.js +4 -1
- package/src/log_utils.coffee +2 -1
- package/src/log_utils.js +5 -0
- package/src/placeholders.coffee +2 -1
- package/src/placeholders.js +6 -2
- package/src/svelte_utils.coffee +2 -1
- package/src/svelte_utils.js +5 -0
- package/src/taml.coffee +2 -1
- package/src/taml.js +5 -0
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@jdeighan/coffee-utils",
|
3
3
|
"type": "module",
|
4
|
-
"version": "
|
4
|
+
"version": "9.0.1",
|
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.
|
58
|
+
"@jdeighan/unit-tester": "^2.0.19"
|
59
59
|
}
|
60
60
|
}
|
package/src/DataStores.coffee
CHANGED
@@ -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
|
-
|
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
package/src/Section.coffee
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
# Section.coffee
|
2
2
|
|
3
|
+
import {assert, error, croak} from '@jdeighan/unit-tester/utils'
|
3
4
|
import {
|
4
|
-
|
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
package/src/SectionMap.coffee
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
# SectionMap.coffee
|
2
2
|
|
3
|
+
import {assert, error, croak} from '@jdeighan/unit-tester/utils'
|
3
4
|
import {
|
4
|
-
|
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
package/src/arrow.coffee
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# arrow.coffee
|
2
2
|
|
3
|
-
import {
|
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
package/src/block_utils.coffee
CHANGED
@@ -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,
|
8
|
+
undef, defined, isEmpty, isString, isArray, nonEmpty, rtrim,
|
8
9
|
} from '@jdeighan/coffee-utils'
|
9
10
|
|
10
11
|
# ---------------------------------------------------------------------------
|
package/src/block_utils.js
CHANGED
@@ -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
|
|
package/src/call_stack.coffee
CHANGED
@@ -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,
|
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
package/src/coffee_utils.coffee
CHANGED
@@ -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
|
|
package/src/coffee_utils.js
CHANGED
@@ -1,7 +1,12 @@
|
|
1
1
|
// Generated by CoffeeScript 2.7.0
|
2
|
-
|
3
|
-
var LOG
|
4
|
-
|
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
|
// ---------------------------------------------------------------------------
|
package/src/debug_utils.coffee
CHANGED
@@ -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
|
-
|
5
|
+
undef, warn, defined,
|
5
6
|
isString, isFunction, isBoolean, patchStr,
|
6
7
|
OL, escapeStr, isNumber, isArray, words, pass,
|
7
8
|
} from '@jdeighan/coffee-utils'
|
package/src/debug_utils.js
CHANGED
package/src/fs_utils.coffee
CHANGED
@@ -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
|
-
|
10
|
-
isString, isArray, isHash, isRegExp, isFunction,
|
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
|
|
package/src/indent_utils.coffee
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
# indent_utils.coffee
|
2
2
|
|
3
|
+
import {assert, error} from '@jdeighan/unit-tester/utils'
|
3
4
|
import {
|
4
|
-
|
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'
|
package/src/indent_utils.js
CHANGED
package/src/log_utils.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
|
-
|
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
package/src/placeholders.coffee
CHANGED
package/src/placeholders.js
CHANGED
package/src/svelte_utils.coffee
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# svelte_utils.coffee
|
2
2
|
|
3
|
-
import {assert,
|
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
|
# ---------------------------------------------------------------------------
|
package/src/svelte_utils.js
CHANGED
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
|
-
|
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'
|