@jdeighan/coffee-utils 4.1.7 → 4.1.8
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 +1 -1
- package/src/coffee_utils.coffee +18 -0
- package/src/coffee_utils.js +22 -0
- package/.save/block.test.coffee +0 -185
- package/.save/block.test.js +0 -129
- package/.save/block2.test.coffee +0 -47
- package/.save/block2.test.js +0 -64
- package/.save/debug.test.coffee +0 -290
- package/.save/debug.test.js +0 -242
- package/.save/fs.test.coffee +0 -148
- package/.save/fs.test.js +0 -191
- package/.save/indent.test.coffee +0 -130
- package/.save/indent.test.js +0 -136
- package/.save/log.test.coffee +0 -315
- package/.save/log.test.js +0 -336
- package/.save/privenv.test.coffee +0 -38
- package/.save/privenv.test.js +0 -54
- package/.save/temp.coffee +0 -19
- package/.save/temp.js +0 -28
- package/.save/tester.test.coffee +0 -75
- package/.save/tester.test.js +0 -93
- package/.save/utils.test.coffee +0 -214
- package/.save/utils.test.js +0 -319
package/package.json
CHANGED
package/src/coffee_utils.coffee
CHANGED
|
@@ -357,3 +357,21 @@ export extractMatches = (line, regexp, convertFunc=undef) ->
|
|
|
357
357
|
return lStrings
|
|
358
358
|
|
|
359
359
|
# ---------------------------------------------------------------------------
|
|
360
|
+
|
|
361
|
+
export envVarsWithPrefix = (prefix, hOptions={}) ->
|
|
362
|
+
# --- valid options:
|
|
363
|
+
# stripPrefix
|
|
364
|
+
|
|
365
|
+
assert prefix, "envVarsWithPrefix: empty prefix!"
|
|
366
|
+
plen = prefix.length
|
|
367
|
+
h = {}
|
|
368
|
+
for key in Object.keys(process.env)
|
|
369
|
+
if key.indexOf(prefix) == 0
|
|
370
|
+
if hOptions.stripPrefix
|
|
371
|
+
h[key.substr(plen)] = process.env[key]
|
|
372
|
+
else
|
|
373
|
+
h[key] = process.env[key]
|
|
374
|
+
return h
|
|
375
|
+
|
|
376
|
+
# ---------------------------------------------------------------------------
|
|
377
|
+
|
package/src/coffee_utils.js
CHANGED
|
@@ -392,3 +392,25 @@ export var extractMatches = function(line, regexp, convertFunc = undef) {
|
|
|
392
392
|
};
|
|
393
393
|
|
|
394
394
|
// ---------------------------------------------------------------------------
|
|
395
|
+
export var envVarsWithPrefix = function(prefix, hOptions = {}) {
|
|
396
|
+
var h, i, key, len, plen, ref;
|
|
397
|
+
// --- valid options:
|
|
398
|
+
// stripPrefix
|
|
399
|
+
assert(prefix, "envVarsWithPrefix: empty prefix!");
|
|
400
|
+
plen = prefix.length;
|
|
401
|
+
h = {};
|
|
402
|
+
ref = Object.keys(process.env);
|
|
403
|
+
for (i = 0, len = ref.length; i < len; i++) {
|
|
404
|
+
key = ref[i];
|
|
405
|
+
if (key.indexOf(prefix) === 0) {
|
|
406
|
+
if (hOptions.stripPrefix) {
|
|
407
|
+
h[key.substr(plen)] = process.env[key];
|
|
408
|
+
} else {
|
|
409
|
+
h[key] = process.env[key];
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
return h;
|
|
414
|
+
};
|
|
415
|
+
|
|
416
|
+
// ---------------------------------------------------------------------------
|
package/.save/block.test.coffee
DELETED
|
@@ -1,185 +0,0 @@
|
|
|
1
|
-
# block.test.coffee
|
|
2
|
-
|
|
3
|
-
import assert from 'assert'
|
|
4
|
-
|
|
5
|
-
import {UnitTester} from '@jdeighan/coffee-utils/test'
|
|
6
|
-
import {
|
|
7
|
-
blockToArray, arrayToBlock, firstLine, remainingLines,
|
|
8
|
-
normalizeBlock, truncateBlock,
|
|
9
|
-
joinBlocks, forEachLine, forEachBlock, forEachSetOfBlocks,
|
|
10
|
-
} from '@jdeighan/coffee-utils/block'
|
|
11
|
-
|
|
12
|
-
simple = new UnitTester()
|
|
13
|
-
|
|
14
|
-
# ---------------------------------------------------------------------------
|
|
15
|
-
|
|
16
|
-
simple.equal 108, blockToArray("abc\nxyz\n"), [
|
|
17
|
-
'abc'
|
|
18
|
-
'xyz'
|
|
19
|
-
]
|
|
20
|
-
|
|
21
|
-
simple.equal 113, blockToArray("abc\nxyz\n\n\n\n"), [
|
|
22
|
-
'abc'
|
|
23
|
-
'xyz'
|
|
24
|
-
]
|
|
25
|
-
|
|
26
|
-
simple.equal 118, blockToArray("abc\n\nxyz\n"), [
|
|
27
|
-
'abc'
|
|
28
|
-
''
|
|
29
|
-
'xyz'
|
|
30
|
-
]
|
|
31
|
-
|
|
32
|
-
# ---------------------------------------------------------------------------
|
|
33
|
-
|
|
34
|
-
simple.equal 126, arrayToBlock(['a','b','c']), "a\nb\nc\n"
|
|
35
|
-
|
|
36
|
-
# ---------------------------------------------------------------------------
|
|
37
|
-
|
|
38
|
-
simple.equal 225, firstLine("""
|
|
39
|
-
#starbucks
|
|
40
|
-
do this
|
|
41
|
-
do that
|
|
42
|
-
"""), '#starbucks'
|
|
43
|
-
|
|
44
|
-
# ---------------------------------------------------------------------------
|
|
45
|
-
|
|
46
|
-
simple.equal 225, remainingLines("""
|
|
47
|
-
#starbucks
|
|
48
|
-
do this
|
|
49
|
-
do that
|
|
50
|
-
"""), """
|
|
51
|
-
do this
|
|
52
|
-
do that
|
|
53
|
-
"""
|
|
54
|
-
|
|
55
|
-
# ---------------------------------------------------------------------------
|
|
56
|
-
|
|
57
|
-
(() ->
|
|
58
|
-
str = joinBlocks('import me', '', 'do this\ndo that')
|
|
59
|
-
simple.equal 17, str, """
|
|
60
|
-
import me
|
|
61
|
-
do this
|
|
62
|
-
do that
|
|
63
|
-
"""
|
|
64
|
-
)()
|
|
65
|
-
|
|
66
|
-
# ---------------------------------------------------------------------------
|
|
67
|
-
|
|
68
|
-
simple.equal 49, normalizeBlock("""
|
|
69
|
-
line 1
|
|
70
|
-
line 2
|
|
71
|
-
"""), """
|
|
72
|
-
line 1
|
|
73
|
-
line 2
|
|
74
|
-
""" + '\n'
|
|
75
|
-
|
|
76
|
-
simple.equal 57, normalizeBlock("""
|
|
77
|
-
line 1
|
|
78
|
-
|
|
79
|
-
line 2
|
|
80
|
-
"""), """
|
|
81
|
-
line 1
|
|
82
|
-
line 2
|
|
83
|
-
""" + '\n'
|
|
84
|
-
|
|
85
|
-
simple.equal 66, normalizeBlock("""
|
|
86
|
-
|
|
87
|
-
line 1
|
|
88
|
-
|
|
89
|
-
line 2
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
"""), """
|
|
93
|
-
line 1
|
|
94
|
-
line 2
|
|
95
|
-
""" + '\n'
|
|
96
|
-
|
|
97
|
-
# ---------------------------------------------------------------------------
|
|
98
|
-
|
|
99
|
-
simple.equal 96, truncateBlock("""
|
|
100
|
-
line 1
|
|
101
|
-
line 2
|
|
102
|
-
line 3
|
|
103
|
-
line 4
|
|
104
|
-
""", 2), """
|
|
105
|
-
line 1
|
|
106
|
-
line 2
|
|
107
|
-
""" + '\n'
|
|
108
|
-
|
|
109
|
-
# ---------------------------------------------------------------------------
|
|
110
|
-
|
|
111
|
-
(() ->
|
|
112
|
-
lBlocks = [
|
|
113
|
-
"import {say} from '@jdeighan/coffee-utils'",
|
|
114
|
-
"",
|
|
115
|
-
"<script>\n\tx = 42\n</script>",
|
|
116
|
-
"",
|
|
117
|
-
]
|
|
118
|
-
str = joinBlocks(lBlocks...)
|
|
119
|
-
simple.equal 34, str, """
|
|
120
|
-
import {say} from '@jdeighan/coffee-utils'
|
|
121
|
-
<script>
|
|
122
|
-
x = 42
|
|
123
|
-
</script>
|
|
124
|
-
"""
|
|
125
|
-
)()
|
|
126
|
-
|
|
127
|
-
# ---------------------------------------------------------------------------
|
|
128
|
-
|
|
129
|
-
(() ->
|
|
130
|
-
lImports = [
|
|
131
|
-
"import {say} from '@jdeighan/coffee-utils'",
|
|
132
|
-
]
|
|
133
|
-
code = """
|
|
134
|
-
if (x==42)
|
|
135
|
-
log "line 2 in unit test"
|
|
136
|
-
"""
|
|
137
|
-
str = joinBlocks(lImports..., code)
|
|
138
|
-
simple.equal 34, str, """
|
|
139
|
-
|
|
140
|
-
import {say} from '@jdeighan/coffee-utils'
|
|
141
|
-
if (x==42)
|
|
142
|
-
log "line 2 in unit test"
|
|
143
|
-
"""
|
|
144
|
-
)()
|
|
145
|
-
|
|
146
|
-
# ---------------------------------------------------------------------------
|
|
147
|
-
# test forEachLine()
|
|
148
|
-
|
|
149
|
-
(() ->
|
|
150
|
-
lLines = []
|
|
151
|
-
|
|
152
|
-
callback = (line) ->
|
|
153
|
-
lLines.push line
|
|
154
|
-
return
|
|
155
|
-
|
|
156
|
-
filepath = "c:/Users/johnd/coffee-utils/test/data/file2.txt"
|
|
157
|
-
await forEachLine filepath, callback
|
|
158
|
-
|
|
159
|
-
simple.equal 55, lLines, [
|
|
160
|
-
"abc",
|
|
161
|
-
"def",
|
|
162
|
-
"ghi",
|
|
163
|
-
"jkl",
|
|
164
|
-
]
|
|
165
|
-
)()
|
|
166
|
-
|
|
167
|
-
# ---------------------------------------------------------------------------
|
|
168
|
-
# test forEachBlock()
|
|
169
|
-
|
|
170
|
-
(() ->
|
|
171
|
-
lBlocks = []
|
|
172
|
-
|
|
173
|
-
callback = (block) ->
|
|
174
|
-
lBlocks.push block
|
|
175
|
-
return
|
|
176
|
-
|
|
177
|
-
filepath = "c:/Users/johnd/coffee-utils/test/data/file3.txt"
|
|
178
|
-
await forEachBlock filepath, callback
|
|
179
|
-
|
|
180
|
-
simple.equal 76, lBlocks, [
|
|
181
|
-
"abc\ndef",
|
|
182
|
-
"abc\ndef\nghi",
|
|
183
|
-
"abc\ndef\nghi\njkl",
|
|
184
|
-
]
|
|
185
|
-
)()
|
package/.save/block.test.js
DELETED
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
// Generated by CoffeeScript 2.6.1
|
|
2
|
-
// block.test.coffee
|
|
3
|
-
var simple;
|
|
4
|
-
|
|
5
|
-
import assert from 'assert';
|
|
6
|
-
|
|
7
|
-
import {
|
|
8
|
-
UnitTester
|
|
9
|
-
} from '@jdeighan/coffee-utils/test';
|
|
10
|
-
|
|
11
|
-
import {
|
|
12
|
-
blockToArray,
|
|
13
|
-
arrayToBlock,
|
|
14
|
-
firstLine,
|
|
15
|
-
remainingLines,
|
|
16
|
-
normalizeBlock,
|
|
17
|
-
truncateBlock,
|
|
18
|
-
joinBlocks,
|
|
19
|
-
forEachLine,
|
|
20
|
-
forEachBlock,
|
|
21
|
-
forEachSetOfBlocks
|
|
22
|
-
} from '@jdeighan/coffee-utils/block';
|
|
23
|
-
|
|
24
|
-
simple = new UnitTester();
|
|
25
|
-
|
|
26
|
-
// ---------------------------------------------------------------------------
|
|
27
|
-
simple.equal(108, blockToArray("abc\nxyz\n"), ['abc', 'xyz']);
|
|
28
|
-
|
|
29
|
-
simple.equal(113, blockToArray("abc\nxyz\n\n\n\n"), ['abc', 'xyz']);
|
|
30
|
-
|
|
31
|
-
simple.equal(118, blockToArray("abc\n\nxyz\n"), ['abc', '', 'xyz']);
|
|
32
|
-
|
|
33
|
-
// ---------------------------------------------------------------------------
|
|
34
|
-
simple.equal(126, arrayToBlock(['a', 'b', 'c']), "a\nb\nc\n");
|
|
35
|
-
|
|
36
|
-
// ---------------------------------------------------------------------------
|
|
37
|
-
simple.equal(225, firstLine(`#starbucks
|
|
38
|
-
do this
|
|
39
|
-
do that`), '#starbucks');
|
|
40
|
-
|
|
41
|
-
// ---------------------------------------------------------------------------
|
|
42
|
-
simple.equal(225, remainingLines(`#starbucks
|
|
43
|
-
do this
|
|
44
|
-
do that`), `do this
|
|
45
|
-
do that`);
|
|
46
|
-
|
|
47
|
-
// ---------------------------------------------------------------------------
|
|
48
|
-
(function() {
|
|
49
|
-
var str;
|
|
50
|
-
str = joinBlocks('import me', '', 'do this\ndo that');
|
|
51
|
-
return simple.equal(17, str, `import me
|
|
52
|
-
do this
|
|
53
|
-
do that`);
|
|
54
|
-
})();
|
|
55
|
-
|
|
56
|
-
// ---------------------------------------------------------------------------
|
|
57
|
-
simple.equal(49, normalizeBlock(`line 1
|
|
58
|
-
line 2`), `line 1
|
|
59
|
-
line 2` + '\n');
|
|
60
|
-
|
|
61
|
-
simple.equal(57, normalizeBlock(`line 1
|
|
62
|
-
|
|
63
|
-
line 2`), `line 1
|
|
64
|
-
line 2` + '\n');
|
|
65
|
-
|
|
66
|
-
simple.equal(66, normalizeBlock(`
|
|
67
|
-
line 1
|
|
68
|
-
|
|
69
|
-
line 2
|
|
70
|
-
|
|
71
|
-
`), `line 1
|
|
72
|
-
line 2` + '\n');
|
|
73
|
-
|
|
74
|
-
// ---------------------------------------------------------------------------
|
|
75
|
-
simple.equal(96, truncateBlock(`line 1
|
|
76
|
-
line 2
|
|
77
|
-
line 3
|
|
78
|
-
line 4`, 2), `line 1
|
|
79
|
-
line 2` + '\n');
|
|
80
|
-
|
|
81
|
-
// ---------------------------------------------------------------------------
|
|
82
|
-
(function() {
|
|
83
|
-
var lBlocks, str;
|
|
84
|
-
lBlocks = ["import {say} from '@jdeighan/coffee-utils'", "", "<script>\n\tx = 42\n</script>", ""];
|
|
85
|
-
str = joinBlocks(...lBlocks);
|
|
86
|
-
return simple.equal(34, str, `import {say} from '@jdeighan/coffee-utils'
|
|
87
|
-
<script>
|
|
88
|
-
x = 42
|
|
89
|
-
</script>`);
|
|
90
|
-
})();
|
|
91
|
-
|
|
92
|
-
// ---------------------------------------------------------------------------
|
|
93
|
-
(function() {
|
|
94
|
-
var code, lImports, str;
|
|
95
|
-
lImports = ["import {say} from '@jdeighan/coffee-utils'"];
|
|
96
|
-
code = `if (x==42)
|
|
97
|
-
log "line 2 in unit test"`;
|
|
98
|
-
str = joinBlocks(...lImports, code);
|
|
99
|
-
return simple.equal(34, str, `
|
|
100
|
-
import {say} from '@jdeighan/coffee-utils'
|
|
101
|
-
if (x==42)
|
|
102
|
-
log "line 2 in unit test"`);
|
|
103
|
-
})();
|
|
104
|
-
|
|
105
|
-
// ---------------------------------------------------------------------------
|
|
106
|
-
// test forEachLine()
|
|
107
|
-
(async function() {
|
|
108
|
-
var callback, filepath, lLines;
|
|
109
|
-
lLines = [];
|
|
110
|
-
callback = function(line) {
|
|
111
|
-
lLines.push(line);
|
|
112
|
-
};
|
|
113
|
-
filepath = "c:/Users/johnd/coffee-utils/test/data/file2.txt";
|
|
114
|
-
await forEachLine(filepath, callback);
|
|
115
|
-
return simple.equal(55, lLines, ["abc", "def", "ghi", "jkl"]);
|
|
116
|
-
})();
|
|
117
|
-
|
|
118
|
-
// ---------------------------------------------------------------------------
|
|
119
|
-
// test forEachBlock()
|
|
120
|
-
(async function() {
|
|
121
|
-
var callback, filepath, lBlocks;
|
|
122
|
-
lBlocks = [];
|
|
123
|
-
callback = function(block) {
|
|
124
|
-
lBlocks.push(block);
|
|
125
|
-
};
|
|
126
|
-
filepath = "c:/Users/johnd/coffee-utils/test/data/file3.txt";
|
|
127
|
-
await forEachBlock(filepath, callback);
|
|
128
|
-
return simple.equal(76, lBlocks, ["abc\ndef", "abc\ndef\nghi", "abc\ndef\nghi\njkl"]);
|
|
129
|
-
})();
|
package/.save/block2.test.coffee
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
# block2.test.coffee
|
|
2
|
-
|
|
3
|
-
import assert from 'assert'
|
|
4
|
-
import test from 'ava'
|
|
5
|
-
|
|
6
|
-
import {
|
|
7
|
-
undef, say, isString, isHash, isEmpty, nonEmpty,
|
|
8
|
-
} from '@jdeighan/coffee-utils'
|
|
9
|
-
import {mydir, mkpath} from '@jdeighan/coffee-utils/fs'
|
|
10
|
-
import {UnitTester} from '@jdeighan/coffee-utils/test'
|
|
11
|
-
import {
|
|
12
|
-
forEachLine, forEachBlock, forEachSetOfBlocks,
|
|
13
|
-
} from '@jdeighan/coffee-utils/block'
|
|
14
|
-
|
|
15
|
-
testDir = mydir(`import.meta.url`)
|
|
16
|
-
simple = new UnitTester()
|
|
17
|
-
|
|
18
|
-
filepath = mkpath(testDir, 'code2.test.txt')
|
|
19
|
-
|
|
20
|
-
# ----------------------------------------------------------------------------
|
|
21
|
-
|
|
22
|
-
(() ->
|
|
23
|
-
lFirstBlocks = undef
|
|
24
|
-
callback = (lBlocks) ->
|
|
25
|
-
lFirstBlocks = lBlocks
|
|
26
|
-
return true # we're only interested in the first set
|
|
27
|
-
|
|
28
|
-
test "line 29", (t) ->
|
|
29
|
-
await forEachSetOfBlocks filepath, callback
|
|
30
|
-
t.deepEqual lFirstBlocks, ["f()", "f"]
|
|
31
|
-
)()
|
|
32
|
-
|
|
33
|
-
# ----------------------------------------------------------------------------
|
|
34
|
-
|
|
35
|
-
(() ->
|
|
36
|
-
lAllBlockSets = []
|
|
37
|
-
callback = (lBlocks) ->
|
|
38
|
-
lAllBlockSets.push(lBlocks)
|
|
39
|
-
return
|
|
40
|
-
|
|
41
|
-
test "line 44", (t) ->
|
|
42
|
-
await forEachSetOfBlocks filepath, callback
|
|
43
|
-
t.deepEqual lAllBlockSets, [
|
|
44
|
-
["f()", "f"],
|
|
45
|
-
["f = (key=undef) ->\n\tswitch key\n\t\twhen 'ok'\n\t\t\tsay 'all is OK'", "f,say,mkpath"],
|
|
46
|
-
]
|
|
47
|
-
)()
|
package/.save/block2.test.js
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
// Generated by CoffeeScript 2.6.1
|
|
2
|
-
// block2.test.coffee
|
|
3
|
-
var filepath, simple, testDir;
|
|
4
|
-
|
|
5
|
-
import assert from 'assert';
|
|
6
|
-
|
|
7
|
-
import test from 'ava';
|
|
8
|
-
|
|
9
|
-
import {
|
|
10
|
-
undef,
|
|
11
|
-
say,
|
|
12
|
-
isString,
|
|
13
|
-
isHash,
|
|
14
|
-
isEmpty,
|
|
15
|
-
nonEmpty
|
|
16
|
-
} from '@jdeighan/coffee-utils';
|
|
17
|
-
|
|
18
|
-
import {
|
|
19
|
-
mydir,
|
|
20
|
-
mkpath
|
|
21
|
-
} from '@jdeighan/coffee-utils/fs';
|
|
22
|
-
|
|
23
|
-
import {
|
|
24
|
-
UnitTester
|
|
25
|
-
} from '@jdeighan/coffee-utils/test';
|
|
26
|
-
|
|
27
|
-
import {
|
|
28
|
-
forEachLine,
|
|
29
|
-
forEachBlock,
|
|
30
|
-
forEachSetOfBlocks
|
|
31
|
-
} from '@jdeighan/coffee-utils/block';
|
|
32
|
-
|
|
33
|
-
testDir = mydir(import.meta.url);
|
|
34
|
-
|
|
35
|
-
simple = new UnitTester();
|
|
36
|
-
|
|
37
|
-
filepath = mkpath(testDir, 'code2.test.txt');
|
|
38
|
-
|
|
39
|
-
// ----------------------------------------------------------------------------
|
|
40
|
-
(function() {
|
|
41
|
-
var callback, lFirstBlocks;
|
|
42
|
-
lFirstBlocks = undef;
|
|
43
|
-
callback = function(lBlocks) {
|
|
44
|
-
lFirstBlocks = lBlocks;
|
|
45
|
-
return true; // we're only interested in the first set
|
|
46
|
-
};
|
|
47
|
-
return test("line 29", async function(t) {
|
|
48
|
-
await forEachSetOfBlocks(filepath, callback);
|
|
49
|
-
return t.deepEqual(lFirstBlocks, ["f()", "f"]);
|
|
50
|
-
});
|
|
51
|
-
})();
|
|
52
|
-
|
|
53
|
-
// ----------------------------------------------------------------------------
|
|
54
|
-
(function() {
|
|
55
|
-
var callback, lAllBlockSets;
|
|
56
|
-
lAllBlockSets = [];
|
|
57
|
-
callback = function(lBlocks) {
|
|
58
|
-
lAllBlockSets.push(lBlocks);
|
|
59
|
-
};
|
|
60
|
-
return test("line 44", async function(t) {
|
|
61
|
-
await forEachSetOfBlocks(filepath, callback);
|
|
62
|
-
return t.deepEqual(lAllBlockSets, [["f()", "f"], ["f = (key=undef) ->\n\tswitch key\n\t\twhen 'ok'\n\t\t\tsay 'all is OK'", "f,say,mkpath"]]);
|
|
63
|
-
});
|
|
64
|
-
})();
|