@jdeighan/coffee-utils 14.0.5 → 14.0.7
Sign up to get free protection for your applications and to get access to all the features.
- package/package.json +3 -3
- package/src/DataStores.coffee +2 -2
- package/src/DataStores.js +2 -2
- package/src/SectionMap.coffee +2 -2
- package/src/SectionMap.js +2 -2
- package/src/block.coffee +6 -6
- package/src/block.js +6 -6
- package/src/browser.coffee +2 -2
- package/src/browser.js +2 -2
- package/src/fs.coffee +29 -29
- package/src/fs.js +29 -29
- package/src/html.coffee +4 -4
- package/src/html.js +4 -4
- package/src/indent.coffee +28 -22
- package/src/indent.js +27 -24
- package/src/server.coffee +2 -2
- package/src/server.js +2 -2
- package/src/svelte.coffee +3 -3
- package/src/svelte.js +3 -3
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@jdeighan/coffee-utils",
|
3
3
|
"type": "module",
|
4
|
-
"version": "14.0.
|
4
|
+
"version": "14.0.7",
|
5
5
|
"description": "A set of utility functions for CoffeeScript",
|
6
6
|
"main": "coffee_utils.js",
|
7
7
|
"exports": {
|
@@ -49,13 +49,13 @@
|
|
49
49
|
},
|
50
50
|
"homepage": "https://github.com/johndeighan/coffee-utils#readme",
|
51
51
|
"dependencies": {
|
52
|
-
"@jdeighan/base-utils": "^4.0.
|
52
|
+
"@jdeighan/base-utils": "^4.0.3",
|
53
53
|
"cross-env": "^7.0.3",
|
54
54
|
"n-readlines": "^1.0.1",
|
55
55
|
"readline-sync": "^1.4.10",
|
56
56
|
"svelte": "^3.55.0"
|
57
57
|
},
|
58
58
|
"devDependencies": {
|
59
|
-
"@jdeighan/unit-tester": "^3.0.
|
59
|
+
"@jdeighan/unit-tester": "^3.0.20"
|
60
60
|
}
|
61
61
|
}
|
package/src/DataStores.coffee
CHANGED
@@ -218,7 +218,7 @@ export class ToDoDataStore extends BaseDataStore
|
|
218
218
|
# UTILITIES
|
219
219
|
# ---------------------------------------------------------------------------
|
220
220
|
|
221
|
-
export brewTamlStr = (code, stub)
|
221
|
+
export brewTamlStr = (code, stub) =>
|
222
222
|
|
223
223
|
return """
|
224
224
|
import {TAMLDataStore} from '@jdeighan/starbucks/stores';
|
@@ -228,7 +228,7 @@ export brewTamlStr = (code, stub) ->
|
|
228
228
|
|
229
229
|
# ---------------------------------------------------------------------------
|
230
230
|
|
231
|
-
export brewTamlFile = (srcPath, destPath=undef, hOptions={})
|
231
|
+
export brewTamlFile = (srcPath, destPath=undef, hOptions={}) =>
|
232
232
|
# --- taml => js
|
233
233
|
# Valid Options:
|
234
234
|
# force
|
package/src/DataStores.js
CHANGED
@@ -289,14 +289,14 @@ export var ToDoDataStore = class ToDoDataStore extends BaseDataStore {
|
|
289
289
|
// ---------------------------------------------------------------------------
|
290
290
|
// UTILITIES
|
291
291
|
// ---------------------------------------------------------------------------
|
292
|
-
export var brewTamlStr =
|
292
|
+
export var brewTamlStr = (code, stub) => {
|
293
293
|
return `import {TAMLDataStore} from '@jdeighan/starbucks/stores';
|
294
294
|
|
295
295
|
export let ${stub} = new TAMLDataStore(\`${code}\`);`;
|
296
296
|
};
|
297
297
|
|
298
298
|
// ---------------------------------------------------------------------------
|
299
|
-
export var brewTamlFile =
|
299
|
+
export var brewTamlFile = (srcPath, destPath = undef, hOptions = {}) => {
|
300
300
|
var hInfo, jsCode, stub, tamlCode;
|
301
301
|
if (destPath == null) {
|
302
302
|
destPath = withExt(srcPath, '.js', {
|
package/src/SectionMap.coffee
CHANGED
@@ -16,13 +16,13 @@ import {Section} from '@jdeighan/coffee-utils/section'
|
|
16
16
|
|
17
17
|
# ---------------------------------------------------------------------------
|
18
18
|
|
19
|
-
isSectionName = (name)
|
19
|
+
isSectionName = (name) =>
|
20
20
|
|
21
21
|
return isString(name) && name.match(/^[a-z][a-z0-9_]*/)
|
22
22
|
|
23
23
|
# ---------------------------------------------------------------------------
|
24
24
|
|
25
|
-
isSetName = (name)
|
25
|
+
isSetName = (name) =>
|
26
26
|
|
27
27
|
return isString(name) && name.match(/^[A-Z][a-z0-9_]*/)
|
28
28
|
|
package/src/SectionMap.js
CHANGED
@@ -50,12 +50,12 @@ import {
|
|
50
50
|
} from '@jdeighan/coffee-utils/section';
|
51
51
|
|
52
52
|
// ---------------------------------------------------------------------------
|
53
|
-
isSectionName =
|
53
|
+
isSectionName = (name) => {
|
54
54
|
return isString(name) && name.match(/^[a-z][a-z0-9_]*/);
|
55
55
|
};
|
56
56
|
|
57
57
|
// ---------------------------------------------------------------------------
|
58
|
-
isSetName =
|
58
|
+
isSetName = (name) => {
|
59
59
|
return isString(name) && name.match(/^[A-Z][a-z0-9_]*/);
|
60
60
|
};
|
61
61
|
|
package/src/block.coffee
CHANGED
@@ -11,7 +11,7 @@ import {
|
|
11
11
|
|
12
12
|
# ---------------------------------------------------------------------------
|
13
13
|
|
14
|
-
export splitBlock = (block)
|
14
|
+
export splitBlock = (block) =>
|
15
15
|
|
16
16
|
assert isString(block), "not a string"
|
17
17
|
pos = block.indexOf('\n')
|
@@ -23,7 +23,7 @@ export splitBlock = (block) ->
|
|
23
23
|
|
24
24
|
# ---------------------------------------------------------------------------
|
25
25
|
|
26
|
-
export firstLine = (block)
|
26
|
+
export firstLine = (block) =>
|
27
27
|
|
28
28
|
assert isString(block), "not a string"
|
29
29
|
pos = block.indexOf('\n')
|
@@ -34,7 +34,7 @@ export firstLine = (block) ->
|
|
34
34
|
|
35
35
|
# ---------------------------------------------------------------------------
|
36
36
|
|
37
|
-
export remainingLines = (block)
|
37
|
+
export remainingLines = (block) =>
|
38
38
|
|
39
39
|
assert isString(block), "not a string"
|
40
40
|
pos = block.indexOf('\n')
|
@@ -47,7 +47,7 @@ export remainingLines = (block) ->
|
|
47
47
|
# normalizeBlock - remove blank lines, trim each line
|
48
48
|
# - collapse internal whitespace to ' '
|
49
49
|
|
50
|
-
export normalizeBlock = (content)
|
50
|
+
export normalizeBlock = (content) =>
|
51
51
|
|
52
52
|
if typeof content != 'string'
|
53
53
|
throw new Error("normalizeBlock(): not a string")
|
@@ -60,7 +60,7 @@ export normalizeBlock = (content) ->
|
|
60
60
|
# ---------------------------------------------------------------------------
|
61
61
|
# truncateBlock - limit block to a certain number of lines
|
62
62
|
|
63
|
-
export truncateBlock = (str, numLines)
|
63
|
+
export truncateBlock = (str, numLines) =>
|
64
64
|
|
65
65
|
lLines = toArray str
|
66
66
|
lLines.length = numLines
|
@@ -68,7 +68,7 @@ export truncateBlock = (str, numLines) ->
|
|
68
68
|
|
69
69
|
# ---------------------------------------------------------------------------
|
70
70
|
|
71
|
-
export joinBlocks = (lBlocks...)
|
71
|
+
export joinBlocks = (lBlocks...) =>
|
72
72
|
|
73
73
|
lNonEmptyBlocks = []
|
74
74
|
for block in lBlocks.flat(999)
|
package/src/block.js
CHANGED
@@ -26,7 +26,7 @@ import {
|
|
26
26
|
} from '@jdeighan/base-utils';
|
27
27
|
|
28
28
|
// ---------------------------------------------------------------------------
|
29
|
-
export var splitBlock =
|
29
|
+
export var splitBlock = (block) => {
|
30
30
|
var pos;
|
31
31
|
assert(isString(block), "not a string");
|
32
32
|
pos = block.indexOf('\n');
|
@@ -38,7 +38,7 @@ export var splitBlock = function(block) {
|
|
38
38
|
};
|
39
39
|
|
40
40
|
// ---------------------------------------------------------------------------
|
41
|
-
export var firstLine =
|
41
|
+
export var firstLine = (block) => {
|
42
42
|
var pos;
|
43
43
|
assert(isString(block), "not a string");
|
44
44
|
pos = block.indexOf('\n');
|
@@ -50,7 +50,7 @@ export var firstLine = function(block) {
|
|
50
50
|
};
|
51
51
|
|
52
52
|
// ---------------------------------------------------------------------------
|
53
|
-
export var remainingLines =
|
53
|
+
export var remainingLines = (block) => {
|
54
54
|
var pos;
|
55
55
|
assert(isString(block), "not a string");
|
56
56
|
pos = block.indexOf('\n');
|
@@ -64,7 +64,7 @@ export var remainingLines = function(block) {
|
|
64
64
|
// ---------------------------------------------------------------------------
|
65
65
|
// normalizeBlock - remove blank lines, trim each line
|
66
66
|
// - collapse internal whitespace to ' '
|
67
|
-
export var normalizeBlock =
|
67
|
+
export var normalizeBlock = (content) => {
|
68
68
|
var lLines, line;
|
69
69
|
if (typeof content !== 'string') {
|
70
70
|
throw new Error("normalizeBlock(): not a string");
|
@@ -88,7 +88,7 @@ export var normalizeBlock = function(content) {
|
|
88
88
|
|
89
89
|
// ---------------------------------------------------------------------------
|
90
90
|
// truncateBlock - limit block to a certain number of lines
|
91
|
-
export var truncateBlock =
|
91
|
+
export var truncateBlock = (str, numLines) => {
|
92
92
|
var lLines;
|
93
93
|
lLines = toArray(str);
|
94
94
|
lLines.length = numLines;
|
@@ -96,7 +96,7 @@ export var truncateBlock = function(str, numLines) {
|
|
96
96
|
};
|
97
97
|
|
98
98
|
// ---------------------------------------------------------------------------
|
99
|
-
export var joinBlocks =
|
99
|
+
export var joinBlocks = (...lBlocks) => {
|
100
100
|
var block, i, lNonEmptyBlocks, len, ref;
|
101
101
|
lNonEmptyBlocks = [];
|
102
102
|
ref = lBlocks.flat(999);
|
package/src/browser.coffee
CHANGED
@@ -7,7 +7,7 @@ audio = undef # audio context - create only when needed, then keep
|
|
7
7
|
# ---------------------------------------------------------------------------
|
8
8
|
# beep - play a sound
|
9
9
|
|
10
|
-
export beep = (volume=100, freq=520, duration=200)
|
10
|
+
export beep = (volume=100, freq=520, duration=200) =>
|
11
11
|
|
12
12
|
if audio == undef
|
13
13
|
audio = new AudioContext()
|
@@ -24,7 +24,7 @@ export beep = (volume=100, freq=520, duration=200) ->
|
|
24
24
|
|
25
25
|
# ---------------------------------------------------------------------------
|
26
26
|
|
27
|
-
export localStore = (key, value=undef)
|
27
|
+
export localStore = (key, value=undef) =>
|
28
28
|
# --- if value is undef, returns the current value
|
29
29
|
|
30
30
|
if typeof localStorage == 'undefined'
|
package/src/browser.js
CHANGED
@@ -11,7 +11,7 @@ audio = undef; // audio context - create only when needed, then keep
|
|
11
11
|
|
12
12
|
// ---------------------------------------------------------------------------
|
13
13
|
// beep - play a sound
|
14
|
-
export var beep =
|
14
|
+
export var beep = (volume = 100, freq = 520, duration = 200) => {
|
15
15
|
var u, v;
|
16
16
|
if (audio === undef) {
|
17
17
|
audio = new AudioContext();
|
@@ -28,7 +28,7 @@ export var beep = function(volume = 100, freq = 520, duration = 200) {
|
|
28
28
|
};
|
29
29
|
|
30
30
|
// ---------------------------------------------------------------------------
|
31
|
-
export var localStore =
|
31
|
+
export var localStore = (key, value = undef) => {
|
32
32
|
// --- if value is undef, returns the current value
|
33
33
|
if (typeof localStorage === 'undefined') {
|
34
34
|
return;
|
package/src/fs.coffee
CHANGED
@@ -19,7 +19,7 @@ import {fromTAML} from '@jdeighan/base-utils/taml'
|
|
19
19
|
# mydir() - pass argument import.meta.url and it will return
|
20
20
|
# the directory your file is in
|
21
21
|
|
22
|
-
export mydir = (url)
|
22
|
+
export mydir = (url) =>
|
23
23
|
|
24
24
|
path = urllib.fileURLToPath(url)
|
25
25
|
dir = pathlib.dirname(path)
|
@@ -28,7 +28,7 @@ export mydir = (url) ->
|
|
28
28
|
|
29
29
|
# ---------------------------------------------------------------------------
|
30
30
|
|
31
|
-
export projRoot = (url)
|
31
|
+
export projRoot = (url) =>
|
32
32
|
|
33
33
|
dir = mydir(url)
|
34
34
|
rootDir = pathTo('package.json', dir, 'direction=up directory')
|
@@ -39,7 +39,7 @@ export projRoot = (url) ->
|
|
39
39
|
# myfile() - pass argument import.meta.url and it will return
|
40
40
|
# the name of your file
|
41
41
|
|
42
|
-
export myfile = (url)
|
42
|
+
export myfile = (url) =>
|
43
43
|
|
44
44
|
path = urllib.fileURLToPath(url)
|
45
45
|
filename = pathlib.parse(path).base
|
@@ -49,20 +49,20 @@ export myfile = (url) ->
|
|
49
49
|
# myfullpath() - pass argument import.meta.url and it will return
|
50
50
|
# the full path to your file
|
51
51
|
|
52
|
-
export myfullpath = (url)
|
52
|
+
export myfullpath = (url) =>
|
53
53
|
|
54
54
|
path = urllib.fileURLToPath(url)
|
55
55
|
return mkpath(path)
|
56
56
|
|
57
57
|
# ---------------------------------------------------------------------------
|
58
58
|
|
59
|
-
export getStats = (fullpath)
|
59
|
+
export getStats = (fullpath) =>
|
60
60
|
|
61
61
|
return fs.lstatSync(fullpath)
|
62
62
|
|
63
63
|
# ---------------------------------------------------------------------------
|
64
64
|
|
65
|
-
export isFile = (fullpath)
|
65
|
+
export isFile = (fullpath) =>
|
66
66
|
|
67
67
|
try
|
68
68
|
return getStats(fullpath).isFile()
|
@@ -71,7 +71,7 @@ export isFile = (fullpath) ->
|
|
71
71
|
|
72
72
|
# ---------------------------------------------------------------------------
|
73
73
|
|
74
|
-
export isDir = (fullpath)
|
74
|
+
export isDir = (fullpath) =>
|
75
75
|
|
76
76
|
try
|
77
77
|
return getStats(fullpath).isDirectory()
|
@@ -80,14 +80,14 @@ export isDir = (fullpath) ->
|
|
80
80
|
|
81
81
|
# ---------------------------------------------------------------------------
|
82
82
|
|
83
|
-
export isSimpleFileName = (path)
|
83
|
+
export isSimpleFileName = (path) =>
|
84
84
|
|
85
85
|
h = pathlib.parse(path)
|
86
86
|
return ! h.root && ! h.dir && h.base
|
87
87
|
|
88
88
|
# ---------------------------------------------------------------------------
|
89
89
|
|
90
|
-
export fileStub = (path)
|
90
|
+
export fileStub = (path) =>
|
91
91
|
|
92
92
|
assert isString(path), "fileExt(): path not a string"
|
93
93
|
if lMatches = path.match(/^(.*)\.[A-Za-z0-9_]+$/)
|
@@ -97,7 +97,7 @@ export fileStub = (path) ->
|
|
97
97
|
|
98
98
|
# ---------------------------------------------------------------------------
|
99
99
|
|
100
|
-
export fileExt = (path)
|
100
|
+
export fileExt = (path) =>
|
101
101
|
|
102
102
|
assert isString(path), "fileExt(): path not a string"
|
103
103
|
if lMatches = path.match(/\.[A-Za-z0-9_]+$/)
|
@@ -107,7 +107,7 @@ export fileExt = (path) ->
|
|
107
107
|
|
108
108
|
# ---------------------------------------------------------------------------
|
109
109
|
|
110
|
-
export mkpath = (lParts...)
|
110
|
+
export mkpath = (lParts...) =>
|
111
111
|
|
112
112
|
# --- Ignore empty parts
|
113
113
|
lNewParts = []
|
@@ -124,13 +124,13 @@ export mkpath = (lParts...) ->
|
|
124
124
|
|
125
125
|
# ---------------------------------------------------------------------------
|
126
126
|
|
127
|
-
export getFullPath = (filepath)
|
127
|
+
export getFullPath = (filepath) =>
|
128
128
|
|
129
129
|
return mkpath(pathlib.resolve(filepath))
|
130
130
|
|
131
131
|
# ---------------------------------------------------------------------------
|
132
132
|
|
133
|
-
export forEachLine = (filepath, func)
|
133
|
+
export forEachLine = (filepath, func) =>
|
134
134
|
|
135
135
|
reader = new NReadLines(filepath)
|
136
136
|
nLines = 0
|
@@ -146,7 +146,7 @@ export forEachLine = (filepath, func) ->
|
|
146
146
|
|
147
147
|
# ---------------------------------------------------------------------------
|
148
148
|
|
149
|
-
export forEachBlock = (filepath, func, regexp = /^-{16,}$/)
|
149
|
+
export forEachBlock = (filepath, func, regexp = /^-{16,}$/) =>
|
150
150
|
|
151
151
|
lLines = []
|
152
152
|
firstLineNum = 1
|
@@ -175,7 +175,7 @@ export forEachBlock = (filepath, func, regexp = /^-{16,}$/) ->
|
|
175
175
|
|
176
176
|
export forEachSetOfBlocks = (filepath, func,
|
177
177
|
block_regexp = /^-{16,}$/,
|
178
|
-
set_regexp = /^={16,}$/)
|
178
|
+
set_regexp = /^={16,}$/) =>
|
179
179
|
|
180
180
|
lBlocks = []
|
181
181
|
lLines = []
|
@@ -210,7 +210,7 @@ export forEachSetOfBlocks = (filepath, func,
|
|
210
210
|
# ---------------------------------------------------------------------------
|
211
211
|
# slurp - read an entire file into a string
|
212
212
|
|
213
|
-
export slurp = (filepath, maxLines=undef)
|
213
|
+
export slurp = (filepath, maxLines=undef) =>
|
214
214
|
|
215
215
|
if defined(maxLines)
|
216
216
|
lLines = []
|
@@ -226,7 +226,7 @@ export slurp = (filepath, maxLines=undef) ->
|
|
226
226
|
# ---------------------------------------------------------------------------
|
227
227
|
# barf - write a string to a file
|
228
228
|
|
229
|
-
export barf = (filepath, contents)
|
229
|
+
export barf = (filepath, contents) =>
|
230
230
|
|
231
231
|
if isEmpty(contents)
|
232
232
|
return
|
@@ -241,7 +241,7 @@ export barf = (filepath, contents) ->
|
|
241
241
|
# ---------------------------------------------------------------------------
|
242
242
|
# withExt - change file extention in a file name
|
243
243
|
|
244
|
-
export withExt = (path, newExt, hOptions={})
|
244
|
+
export withExt = (path, newExt, hOptions={}) =>
|
245
245
|
# --- Valid options:
|
246
246
|
# removeLeadingUnderScore - boolean
|
247
247
|
|
@@ -257,7 +257,7 @@ export withExt = (path, newExt, hOptions={}) ->
|
|
257
257
|
# ---------------------------------------------------------------------------
|
258
258
|
# removeFileWithExt - remove file with different ext
|
259
259
|
|
260
|
-
export removeFileWithExt = (path, newExt, hOptions={})
|
260
|
+
export removeFileWithExt = (path, newExt, hOptions={}) =>
|
261
261
|
# --- Valid options:
|
262
262
|
# doLog
|
263
263
|
# removeLeadingUnderScore
|
@@ -276,7 +276,7 @@ export removeFileWithExt = (path, newExt, hOptions={}) ->
|
|
276
276
|
# ---------------------------------------------------------------------------
|
277
277
|
# withUnderScore - add '_' to file name
|
278
278
|
|
279
|
-
export withUnderScore = (path)
|
279
|
+
export withUnderScore = (path) =>
|
280
280
|
|
281
281
|
{dir, base} = pathlib.parse(path)
|
282
282
|
return mkpath(dir, "_#{base}")
|
@@ -290,7 +290,7 @@ isSystemDir = (dir) ->
|
|
290
290
|
# ---------------------------------------------------------------------------
|
291
291
|
# Get all subdirectories of a directory
|
292
292
|
|
293
|
-
export getSubDirs = (dir)
|
293
|
+
export getSubDirs = (dir) =>
|
294
294
|
|
295
295
|
return fs.readdirSync(dir, {withFileTypes: true}) \
|
296
296
|
.filter((d) -> d.isDirectory() && !isSystemDir(d.name)) \
|
@@ -300,7 +300,7 @@ export getSubDirs = (dir) ->
|
|
300
300
|
# ---------------------------------------------------------------------------
|
301
301
|
# Get path to parent directory of a directory
|
302
302
|
|
303
|
-
export getParentDir = (dir)
|
303
|
+
export getParentDir = (dir) =>
|
304
304
|
|
305
305
|
hParts = pathlib.parse(dir)
|
306
306
|
if (hParts.dir == hParts.root)
|
@@ -309,7 +309,7 @@ export getParentDir = (dir) ->
|
|
309
309
|
|
310
310
|
# ---------------------------------------------------------------------------
|
311
311
|
|
312
|
-
export forEachFile = (dir, cb, filt=undef, level=0)
|
312
|
+
export forEachFile = (dir, cb, filt=undef, level=0) =>
|
313
313
|
# --- filt can be a regular expression or a function that gets:
|
314
314
|
# (filename, dir, level)
|
315
315
|
# callback will get parms (filename, dir, level)
|
@@ -336,7 +336,7 @@ export forEachFile = (dir, cb, filt=undef, level=0) ->
|
|
336
336
|
|
337
337
|
# ---------------------------------------------------------------------------
|
338
338
|
|
339
|
-
export pathTo = (fname, searchDir, options=undef)
|
339
|
+
export pathTo = (fname, searchDir, options=undef) =>
|
340
340
|
|
341
341
|
{direction, relative, directory} = getOptions(options, {
|
342
342
|
direction: 'down'
|
@@ -388,7 +388,7 @@ export pathTo = (fname, searchDir, options=undef) ->
|
|
388
388
|
|
389
389
|
# ---------------------------------------------------------------------------
|
390
390
|
|
391
|
-
export allPathsTo = (fname, searchDir)
|
391
|
+
export allPathsTo = (fname, searchDir) =>
|
392
392
|
# --- Only searches upward
|
393
393
|
|
394
394
|
if ! searchDir
|
@@ -406,7 +406,7 @@ export allPathsTo = (fname, searchDir) ->
|
|
406
406
|
|
407
407
|
# ---------------------------------------------------------------------------
|
408
408
|
|
409
|
-
export newerDestFileExists = (srcPath, destPath)
|
409
|
+
export newerDestFileExists = (srcPath, destPath) =>
|
410
410
|
|
411
411
|
if ! fs.existsSync(destPath)
|
412
412
|
return false
|
@@ -419,7 +419,7 @@ export newerDestFileExists = (srcPath, destPath) ->
|
|
419
419
|
|
420
420
|
# ---------------------------------------------------------------------------
|
421
421
|
|
422
|
-
export shortenPath = (path)
|
422
|
+
export shortenPath = (path) =>
|
423
423
|
# --- Replace user's home dir with '~'
|
424
424
|
|
425
425
|
str = mkpath(path)
|
@@ -433,7 +433,7 @@ export shortenPath = (path) ->
|
|
433
433
|
|
434
434
|
# ---------------------------------------------------------------------------
|
435
435
|
|
436
|
-
export parseSource = (source)
|
436
|
+
export parseSource = (source) =>
|
437
437
|
# --- returns {
|
438
438
|
# dir
|
439
439
|
# filename
|
@@ -487,7 +487,7 @@ export parseSource = (source) ->
|
|
487
487
|
# ---------------------------------------------------------------------------
|
488
488
|
# slurpTAML - read TAML from a file
|
489
489
|
|
490
|
-
export slurpTAML = (filepath)
|
490
|
+
export slurpTAML = (filepath) =>
|
491
491
|
|
492
492
|
contents = slurp(filepath)
|
493
493
|
return fromTAML(contents)
|
package/src/fs.js
CHANGED
@@ -52,7 +52,7 @@ import {
|
|
52
52
|
// ---------------------------------------------------------------------------
|
53
53
|
// mydir() - pass argument import.meta.url and it will return
|
54
54
|
// the directory your file is in
|
55
|
-
export var mydir =
|
55
|
+
export var mydir = (url) => {
|
56
56
|
var dir, final, path;
|
57
57
|
path = urllib.fileURLToPath(url);
|
58
58
|
dir = pathlib.dirname(path);
|
@@ -61,7 +61,7 @@ export var mydir = function(url) {
|
|
61
61
|
};
|
62
62
|
|
63
63
|
// ---------------------------------------------------------------------------
|
64
|
-
export var projRoot =
|
64
|
+
export var projRoot = (url) => {
|
65
65
|
var dir, rootDir;
|
66
66
|
dir = mydir(url);
|
67
67
|
rootDir = pathTo('package.json', dir, 'direction=up directory');
|
@@ -72,7 +72,7 @@ export var projRoot = function(url) {
|
|
72
72
|
// ---------------------------------------------------------------------------
|
73
73
|
// myfile() - pass argument import.meta.url and it will return
|
74
74
|
// the name of your file
|
75
|
-
export var myfile =
|
75
|
+
export var myfile = (url) => {
|
76
76
|
var filename, path;
|
77
77
|
path = urllib.fileURLToPath(url);
|
78
78
|
filename = pathlib.parse(path).base;
|
@@ -82,19 +82,19 @@ export var myfile = function(url) {
|
|
82
82
|
// ---------------------------------------------------------------------------
|
83
83
|
// myfullpath() - pass argument import.meta.url and it will return
|
84
84
|
// the full path to your file
|
85
|
-
export var myfullpath =
|
85
|
+
export var myfullpath = (url) => {
|
86
86
|
var path;
|
87
87
|
path = urllib.fileURLToPath(url);
|
88
88
|
return mkpath(path);
|
89
89
|
};
|
90
90
|
|
91
91
|
// ---------------------------------------------------------------------------
|
92
|
-
export var getStats =
|
92
|
+
export var getStats = (fullpath) => {
|
93
93
|
return fs.lstatSync(fullpath);
|
94
94
|
};
|
95
95
|
|
96
96
|
// ---------------------------------------------------------------------------
|
97
|
-
export var isFile =
|
97
|
+
export var isFile = (fullpath) => {
|
98
98
|
try {
|
99
99
|
return getStats(fullpath).isFile();
|
100
100
|
} catch (error) {
|
@@ -103,7 +103,7 @@ export var isFile = function(fullpath) {
|
|
103
103
|
};
|
104
104
|
|
105
105
|
// ---------------------------------------------------------------------------
|
106
|
-
export var isDir =
|
106
|
+
export var isDir = (fullpath) => {
|
107
107
|
try {
|
108
108
|
return getStats(fullpath).isDirectory();
|
109
109
|
} catch (error) {
|
@@ -112,14 +112,14 @@ export var isDir = function(fullpath) {
|
|
112
112
|
};
|
113
113
|
|
114
114
|
// ---------------------------------------------------------------------------
|
115
|
-
export var isSimpleFileName =
|
115
|
+
export var isSimpleFileName = (path) => {
|
116
116
|
var h;
|
117
117
|
h = pathlib.parse(path);
|
118
118
|
return !h.root && !h.dir && h.base;
|
119
119
|
};
|
120
120
|
|
121
121
|
// ---------------------------------------------------------------------------
|
122
|
-
export var fileStub =
|
122
|
+
export var fileStub = (path) => {
|
123
123
|
var lMatches;
|
124
124
|
assert(isString(path), "fileExt(): path not a string");
|
125
125
|
if (lMatches = path.match(/^(.*)\.[A-Za-z0-9_]+$/)) {
|
@@ -130,7 +130,7 @@ export var fileStub = function(path) {
|
|
130
130
|
};
|
131
131
|
|
132
132
|
// ---------------------------------------------------------------------------
|
133
|
-
export var fileExt =
|
133
|
+
export var fileExt = (path) => {
|
134
134
|
var lMatches;
|
135
135
|
assert(isString(path), "fileExt(): path not a string");
|
136
136
|
if (lMatches = path.match(/\.[A-Za-z0-9_]+$/)) {
|
@@ -141,7 +141,7 @@ export var fileExt = function(path) {
|
|
141
141
|
};
|
142
142
|
|
143
143
|
// ---------------------------------------------------------------------------
|
144
|
-
export var mkpath =
|
144
|
+
export var mkpath = (...lParts) => {
|
145
145
|
var _, drive, i, lMatches, lNewParts, len, newPath, part, rest;
|
146
146
|
// --- Ignore empty parts
|
147
147
|
lNewParts = [];
|
@@ -161,12 +161,12 @@ export var mkpath = function(...lParts) {
|
|
161
161
|
};
|
162
162
|
|
163
163
|
// ---------------------------------------------------------------------------
|
164
|
-
export var getFullPath =
|
164
|
+
export var getFullPath = (filepath) => {
|
165
165
|
return mkpath(pathlib.resolve(filepath));
|
166
166
|
};
|
167
167
|
|
168
168
|
// ---------------------------------------------------------------------------
|
169
|
-
export var forEachLine =
|
169
|
+
export var forEachLine = (filepath, func) => {
|
170
170
|
var buffer, line, nLines, reader;
|
171
171
|
reader = new NReadLines(filepath);
|
172
172
|
nLines = 0;
|
@@ -182,7 +182,7 @@ export var forEachLine = function(filepath, func) {
|
|
182
182
|
};
|
183
183
|
|
184
184
|
// ---------------------------------------------------------------------------
|
185
|
-
export var forEachBlock =
|
185
|
+
export var forEachBlock = (filepath, func, regexp = /^-{16,}$/) => {
|
186
186
|
var callback, earlyExit, firstLineNum, lLines;
|
187
187
|
lLines = [];
|
188
188
|
firstLineNum = 1;
|
@@ -211,7 +211,7 @@ export var forEachBlock = function(filepath, func, regexp = /^-{16,}$/) {
|
|
211
211
|
};
|
212
212
|
|
213
213
|
// ---------------------------------------------------------------------------
|
214
|
-
export var forEachSetOfBlocks =
|
214
|
+
export var forEachSetOfBlocks = (filepath, func, block_regexp = /^-{16,}$/, set_regexp = /^={16,}$/) => {
|
215
215
|
var callback, earlyExit, firstLineNum, lBlocks, lLines;
|
216
216
|
lBlocks = [];
|
217
217
|
lLines = [];
|
@@ -248,7 +248,7 @@ export var forEachSetOfBlocks = function(filepath, func, block_regexp = /^-{16,}
|
|
248
248
|
|
249
249
|
// ---------------------------------------------------------------------------
|
250
250
|
// slurp - read an entire file into a string
|
251
|
-
export var slurp =
|
251
|
+
export var slurp = (filepath, maxLines = undef) => {
|
252
252
|
var contents, lLines;
|
253
253
|
if (defined(maxLines)) {
|
254
254
|
lLines = [];
|
@@ -266,7 +266,7 @@ export var slurp = function(filepath, maxLines = undef) {
|
|
266
266
|
|
267
267
|
// ---------------------------------------------------------------------------
|
268
268
|
// barf - write a string to a file
|
269
|
-
export var barf =
|
269
|
+
export var barf = (filepath, contents) => {
|
270
270
|
if (isEmpty(contents)) {
|
271
271
|
return;
|
272
272
|
}
|
@@ -283,7 +283,7 @@ export var barf = function(filepath, contents) {
|
|
283
283
|
|
284
284
|
// ---------------------------------------------------------------------------
|
285
285
|
// withExt - change file extention in a file name
|
286
|
-
export var withExt =
|
286
|
+
export var withExt = (path, newExt, hOptions = {}) => {
|
287
287
|
var dir, ext, name;
|
288
288
|
// --- Valid options:
|
289
289
|
// removeLeadingUnderScore - boolean
|
@@ -300,7 +300,7 @@ export var withExt = function(path, newExt, hOptions = {}) {
|
|
300
300
|
|
301
301
|
// ---------------------------------------------------------------------------
|
302
302
|
// removeFileWithExt - remove file with different ext
|
303
|
-
export var removeFileWithExt =
|
303
|
+
export var removeFileWithExt = (path, newExt, hOptions = {}) => {
|
304
304
|
var err, fullpath, success;
|
305
305
|
// --- Valid options:
|
306
306
|
// doLog
|
@@ -322,7 +322,7 @@ export var removeFileWithExt = function(path, newExt, hOptions = {}) {
|
|
322
322
|
|
323
323
|
// ---------------------------------------------------------------------------
|
324
324
|
// withUnderScore - add '_' to file name
|
325
|
-
export var withUnderScore =
|
325
|
+
export var withUnderScore = (path) => {
|
326
326
|
var base, dir;
|
327
327
|
({dir, base} = pathlib.parse(path));
|
328
328
|
return mkpath(dir, `_${base}`);
|
@@ -335,7 +335,7 @@ isSystemDir = function(dir) {
|
|
335
335
|
|
336
336
|
// ---------------------------------------------------------------------------
|
337
337
|
// Get all subdirectories of a directory
|
338
|
-
export var getSubDirs =
|
338
|
+
export var getSubDirs = (dir) => {
|
339
339
|
return fs.readdirSync(dir, {
|
340
340
|
withFileTypes: true
|
341
341
|
}).filter(function(d) {
|
@@ -347,7 +347,7 @@ export var getSubDirs = function(dir) {
|
|
347
347
|
|
348
348
|
// ---------------------------------------------------------------------------
|
349
349
|
// Get path to parent directory of a directory
|
350
|
-
export var getParentDir =
|
350
|
+
export var getParentDir = (dir) => {
|
351
351
|
var hParts;
|
352
352
|
hParts = pathlib.parse(dir);
|
353
353
|
if (hParts.dir === hParts.root) {
|
@@ -357,7 +357,7 @@ export var getParentDir = function(dir) {
|
|
357
357
|
};
|
358
358
|
|
359
359
|
// ---------------------------------------------------------------------------
|
360
|
-
export var forEachFile =
|
360
|
+
export var forEachFile = (dir, cb, filt = undef, level = 0) => {
|
361
361
|
var ent, i, j, lSubDirectories, len, len1, ref, ref1, subdir;
|
362
362
|
// --- filt can be a regular expression or a function that gets:
|
363
363
|
// (filename, dir, level)
|
@@ -396,7 +396,7 @@ export var forEachFile = function(dir, cb, filt = undef, level = 0) {
|
|
396
396
|
};
|
397
397
|
|
398
398
|
// ---------------------------------------------------------------------------
|
399
|
-
export var pathTo =
|
399
|
+
export var pathTo = (fname, searchDir, options = undef) => {
|
400
400
|
var dirPath, direction, directory, filepath, fpath, i, len, nLevels, ref, relative, subdir;
|
401
401
|
({direction, relative, directory} = getOptions(options, {
|
402
402
|
direction: 'down',
|
@@ -458,7 +458,7 @@ export var pathTo = function(fname, searchDir, options = undef) {
|
|
458
458
|
};
|
459
459
|
|
460
460
|
// ---------------------------------------------------------------------------
|
461
|
-
export var allPathsTo =
|
461
|
+
export var allPathsTo = (fname, searchDir) => {
|
462
462
|
var h, lPaths, path;
|
463
463
|
if (!searchDir) {
|
464
464
|
searchDir = process.cwd();
|
@@ -481,7 +481,7 @@ export var allPathsTo = function(fname, searchDir) {
|
|
481
481
|
};
|
482
482
|
|
483
483
|
// ---------------------------------------------------------------------------
|
484
|
-
export var newerDestFileExists =
|
484
|
+
export var newerDestFileExists = (srcPath, destPath) => {
|
485
485
|
var destModTime, srcModTime;
|
486
486
|
if (!fs.existsSync(destPath)) {
|
487
487
|
return false;
|
@@ -496,7 +496,7 @@ export var newerDestFileExists = function(srcPath, destPath) {
|
|
496
496
|
};
|
497
497
|
|
498
498
|
// ---------------------------------------------------------------------------
|
499
|
-
export var shortenPath =
|
499
|
+
export var shortenPath = (path) => {
|
500
500
|
var _, lMatches, str, tail;
|
501
501
|
// --- Replace user's home dir with '~'
|
502
502
|
str = mkpath(path);
|
@@ -509,7 +509,7 @@ export var shortenPath = function(path) {
|
|
509
509
|
};
|
510
510
|
|
511
511
|
// ---------------------------------------------------------------------------
|
512
|
-
export var parseSource =
|
512
|
+
export var parseSource = (source) => {
|
513
513
|
var dir, hInfo, hSourceInfo, lMatches;
|
514
514
|
// --- returns {
|
515
515
|
// dir
|
@@ -562,7 +562,7 @@ export var parseSource = function(source) {
|
|
562
562
|
|
563
563
|
// ---------------------------------------------------------------------------
|
564
564
|
// slurpTAML - read TAML from a file
|
565
|
-
export var slurpTAML =
|
565
|
+
export var slurpTAML = (filepath) => {
|
566
566
|
var contents;
|
567
567
|
contents = slurp(filepath);
|
568
568
|
return fromTAML(contents);
|
package/src/html.coffee
CHANGED
@@ -13,7 +13,7 @@ for tagName in words('area base br col command embed hr img input' \
|
|
13
13
|
|
14
14
|
# ---------------------------------------------------------------------------
|
15
15
|
|
16
|
-
export parsetag = (line)
|
16
|
+
export parsetag = (line) =>
|
17
17
|
|
18
18
|
if lMatches = line.match(///^
|
19
19
|
(?:
|
@@ -159,7 +159,7 @@ export parsetag = (line) ->
|
|
159
159
|
# ---------------------------------------------------------------------------
|
160
160
|
# --- export only for unit testing
|
161
161
|
|
162
|
-
export attrStr = (hAttr)
|
162
|
+
export attrStr = (hAttr) =>
|
163
163
|
|
164
164
|
if ! hAttr
|
165
165
|
return ''
|
@@ -179,7 +179,7 @@ export attrStr = (hAttr) ->
|
|
179
179
|
|
180
180
|
# ---------------------------------------------------------------------------
|
181
181
|
|
182
|
-
export tag2str = (hToken, type='begin')
|
182
|
+
export tag2str = (hToken, type='begin') =>
|
183
183
|
|
184
184
|
{tagName, hAttr} = hToken
|
185
185
|
if (type == 'begin')
|
@@ -199,7 +199,7 @@ export tag2str = (hToken, type='begin') ->
|
|
199
199
|
# ---------------------------------------------------------------------------
|
200
200
|
# elem - indent text, surround with HTML tags
|
201
201
|
|
202
|
-
export elem = (tagName, hAttr=undef, text=undef, oneIndent="\t")
|
202
|
+
export elem = (tagName, hAttr=undef, text=undef, oneIndent="\t") =>
|
203
203
|
|
204
204
|
if isEmpty(text)
|
205
205
|
hToken = {tagName, hAttr}
|
package/src/html.js
CHANGED
@@ -29,7 +29,7 @@ for (i = 0, len = ref.length; i < len; i++) {
|
|
29
29
|
}
|
30
30
|
|
31
31
|
// ---------------------------------------------------------------------------
|
32
|
-
export var parsetag =
|
32
|
+
export var parsetag = (line) => {
|
33
33
|
var _, all, attrName, br_val, className, dq_val, hAttr, hToken, ident, j, lClasses, lMatches, len1, modifiers, prefix, quote, ref1, rest, sq_val, subtype, uq_val, value, varName;
|
34
34
|
if (lMatches = line.match(/^(?:([A-Za-z][A-Za-z0-9_]*)\s*=\s*)?([A-Za-z][A-Za-z0-9_]*)(?:\:([a-z]+))?(\S*)\s*(.*)$/)) { // variable name
|
35
35
|
// variable is optional
|
@@ -155,7 +155,7 @@ export var parsetag = function(line) {
|
|
155
155
|
|
156
156
|
// ---------------------------------------------------------------------------
|
157
157
|
// --- export only for unit testing
|
158
|
-
export var attrStr =
|
158
|
+
export var attrStr = (hAttr) => {
|
159
159
|
var attrName, bquote, equote, j, len1, quote, ref1, shorthand, str, value;
|
160
160
|
if (!hAttr) {
|
161
161
|
return '';
|
@@ -181,7 +181,7 @@ export var attrStr = function(hAttr) {
|
|
181
181
|
};
|
182
182
|
|
183
183
|
// ---------------------------------------------------------------------------
|
184
|
-
export var tag2str =
|
184
|
+
export var tag2str = (hToken, type = 'begin') => {
|
185
185
|
var hAttr, str;
|
186
186
|
({tagName, hAttr} = hToken);
|
187
187
|
if (type === 'begin') {
|
@@ -204,7 +204,7 @@ export var tag2str = function(hToken, type = 'begin') {
|
|
204
204
|
|
205
205
|
// ---------------------------------------------------------------------------
|
206
206
|
// elem - indent text, surround with HTML tags
|
207
|
-
export var elem =
|
207
|
+
export var elem = (tagName, hAttr = undef, text = undef, oneIndent = "\t") => {
|
208
208
|
var hToken;
|
209
209
|
if (isEmpty(text)) {
|
210
210
|
hToken = {tagName, hAttr};
|
package/src/indent.coffee
CHANGED
@@ -8,7 +8,7 @@ import {
|
|
8
8
|
|
9
9
|
# ---------------------------------------------------------------------------
|
10
10
|
|
11
|
-
export getOneIndent = (str)
|
11
|
+
export getOneIndent = (str) =>
|
12
12
|
|
13
13
|
if (lMatches = str.match(/^\t+(?:\S|$)/))
|
14
14
|
return "\t"
|
@@ -19,7 +19,7 @@ export getOneIndent = (str) ->
|
|
19
19
|
|
20
20
|
# ---------------------------------------------------------------------------
|
21
21
|
|
22
|
-
export splitPrefix = (line)
|
22
|
+
export splitPrefix = (line) =>
|
23
23
|
|
24
24
|
assert isString(line), "non-string #{OL(line)}"
|
25
25
|
line = rtrim(line)
|
@@ -29,7 +29,7 @@ export splitPrefix = (line) ->
|
|
29
29
|
# ---------------------------------------------------------------------------
|
30
30
|
# splitLine - separate a line into [level, line]
|
31
31
|
|
32
|
-
export splitLine = (line, oneIndent=undef)
|
32
|
+
export splitLine = (line, oneIndent=undef) =>
|
33
33
|
|
34
34
|
[prefix, str] = splitPrefix(line)
|
35
35
|
return [indentLevel(prefix, oneIndent), str]
|
@@ -38,7 +38,7 @@ export splitLine = (line, oneIndent=undef) ->
|
|
38
38
|
# indentation - return appropriate indentation string for given level
|
39
39
|
# export only to allow unit testing
|
40
40
|
|
41
|
-
export indentation = (level, oneIndent="\t")
|
41
|
+
export indentation = (level, oneIndent="\t") =>
|
42
42
|
|
43
43
|
assert (level >= 0), "indentation(): negative level"
|
44
44
|
return oneIndent.repeat(level)
|
@@ -47,47 +47,53 @@ export indentation = (level, oneIndent="\t") ->
|
|
47
47
|
# indentLevel - determine indent level of a string
|
48
48
|
# it's OK if the string is ONLY indentation
|
49
49
|
|
50
|
-
export indentLevel = (line, oneIndent=undef)
|
50
|
+
export indentLevel = (line, oneIndent=undef) =>
|
51
51
|
|
52
52
|
assert isString(line), "not a string"
|
53
53
|
|
54
54
|
# --- This will always match, and it's greedy
|
55
|
-
if lMatches = line.match(
|
56
|
-
prefix = lMatches[
|
55
|
+
if lMatches = line.match(/^\s*/)
|
56
|
+
prefix = lMatches[0]
|
57
57
|
prefixLen = prefix.length
|
58
58
|
|
59
59
|
if (prefixLen == 0)
|
60
60
|
return 0
|
61
61
|
|
62
62
|
if defined(oneIndent)
|
63
|
+
# --- prefix must be some multiple of oneIndent
|
63
64
|
len = oneIndent.length
|
64
|
-
|
65
|
-
|
66
|
-
len = 1
|
67
|
-
|
68
|
-
if (prefixLen % len != 0)
|
69
|
-
croak "prefix #{OL(prefix)} not a mult of #{OL(oneIndent)}"
|
65
|
+
assert (prefixLen % len == 0),
|
66
|
+
"prefix #{OL(prefix)} not a mult of #{OL(oneIndent)}"
|
70
67
|
|
71
|
-
|
72
|
-
|
73
|
-
|
68
|
+
level = prefixLen / len
|
69
|
+
else
|
70
|
+
ch = prefix.substring(0, 1)
|
71
|
+
if (ch == "\t")
|
72
|
+
oneIndent = "\t"
|
73
|
+
level = prefixLen
|
74
|
+
else if (ch == ' ')
|
75
|
+
oneIndent = ' '.repeat(prefixLen)
|
76
|
+
level = 1
|
77
|
+
else
|
78
|
+
croak "Bad Indentation in #{OL(line)}"
|
74
79
|
|
80
|
+
assert (prefix == oneIndent.repeat(level)),
|
81
|
+
"prefix #{OL(prefix)} not a mult of #{OL(oneIndent)}"
|
75
82
|
return level
|
76
83
|
|
77
84
|
# ---------------------------------------------------------------------------
|
78
85
|
# isUndented - true iff indentLevel(line) == 0
|
79
86
|
|
80
|
-
export isUndented = (line)
|
87
|
+
export isUndented = (line) =>
|
81
88
|
|
82
89
|
assert isString(line), "non-string #{OL(line)}"
|
83
|
-
|
84
|
-
return (lMatches[0].length == 0)
|
90
|
+
return notdefined(line.match(/^\s/))
|
85
91
|
|
86
92
|
# ---------------------------------------------------------------------------
|
87
93
|
# indented - add indentation to each string in a block or array
|
88
94
|
# - returns the same type as input, i.e. array or string
|
89
95
|
|
90
|
-
export indented = (input, level=1, oneIndent="\t")
|
96
|
+
export indented = (input, level=1, oneIndent="\t") =>
|
91
97
|
|
92
98
|
# --- level can be a string, in which case it is
|
93
99
|
# pre-pended to each line of input
|
@@ -125,7 +131,7 @@ export indented = (input, level=1, oneIndent="\t") ->
|
|
125
131
|
# indentation is removed
|
126
132
|
# - returns same type as text, i.e. either string or array
|
127
133
|
|
128
|
-
export undented = (input, level=undef, oneIndent="\t")
|
134
|
+
export undented = (input, level=undef, oneIndent="\t") =>
|
129
135
|
|
130
136
|
if defined(level) && (level==0)
|
131
137
|
return input
|
@@ -163,7 +169,7 @@ export undented = (input, level=undef, oneIndent="\t") ->
|
|
163
169
|
# ---------------------------------------------------------------------------
|
164
170
|
# enclose - indent text, surround with pre and post
|
165
171
|
|
166
|
-
export enclose = (text, pre, post, oneIndent="\t")
|
172
|
+
export enclose = (text, pre, post, oneIndent="\t") =>
|
167
173
|
|
168
174
|
return toBlock([
|
169
175
|
pre
|
package/src/indent.js
CHANGED
@@ -20,7 +20,7 @@ import {
|
|
20
20
|
} from '@jdeighan/base-utils';
|
21
21
|
|
22
22
|
// ---------------------------------------------------------------------------
|
23
|
-
export var getOneIndent =
|
23
|
+
export var getOneIndent = (str) => {
|
24
24
|
var lMatches;
|
25
25
|
if ((lMatches = str.match(/^\t+(?:\S|$)/))) {
|
26
26
|
return "\t";
|
@@ -32,7 +32,7 @@ export var getOneIndent = function(str) {
|
|
32
32
|
};
|
33
33
|
|
34
34
|
// ---------------------------------------------------------------------------
|
35
|
-
export var splitPrefix =
|
35
|
+
export var splitPrefix = (line) => {
|
36
36
|
var lMatches;
|
37
37
|
assert(isString(line), `non-string ${OL(line)}`);
|
38
38
|
line = rtrim(line);
|
@@ -42,7 +42,7 @@ export var splitPrefix = function(line) {
|
|
42
42
|
|
43
43
|
// ---------------------------------------------------------------------------
|
44
44
|
// splitLine - separate a line into [level, line]
|
45
|
-
export var splitLine =
|
45
|
+
export var splitLine = (line, oneIndent = undef) => {
|
46
46
|
var prefix, str;
|
47
47
|
[prefix, str] = splitPrefix(line);
|
48
48
|
return [indentLevel(prefix, oneIndent), str];
|
@@ -51,7 +51,7 @@ export var splitLine = function(line, oneIndent = undef) {
|
|
51
51
|
// ---------------------------------------------------------------------------
|
52
52
|
// indentation - return appropriate indentation string for given level
|
53
53
|
// export only to allow unit testing
|
54
|
-
export var indentation =
|
54
|
+
export var indentation = (level, oneIndent = "\t") => {
|
55
55
|
assert(level >= 0, "indentation(): negative level");
|
56
56
|
return oneIndent.repeat(level);
|
57
57
|
};
|
@@ -59,46 +59,49 @@ export var indentation = function(level, oneIndent = "\t") {
|
|
59
59
|
// ---------------------------------------------------------------------------
|
60
60
|
// indentLevel - determine indent level of a string
|
61
61
|
// it's OK if the string is ONLY indentation
|
62
|
-
export var indentLevel =
|
63
|
-
var lMatches, len, level, prefix, prefixLen;
|
62
|
+
export var indentLevel = (line, oneIndent = undef) => {
|
63
|
+
var ch, lMatches, len, level, prefix, prefixLen;
|
64
64
|
assert(isString(line), "not a string");
|
65
65
|
// --- This will always match, and it's greedy
|
66
|
-
if (lMatches = line.match(
|
67
|
-
prefix = lMatches[
|
66
|
+
if (lMatches = line.match(/^\s*/)) {
|
67
|
+
prefix = lMatches[0];
|
68
68
|
prefixLen = prefix.length;
|
69
69
|
}
|
70
70
|
if (prefixLen === 0) {
|
71
71
|
return 0;
|
72
72
|
}
|
73
73
|
if (defined(oneIndent)) {
|
74
|
+
// --- prefix must be some multiple of oneIndent
|
74
75
|
len = oneIndent.length;
|
76
|
+
assert(prefixLen % len === 0, `prefix ${OL(prefix)} not a mult of ${OL(oneIndent)}`);
|
77
|
+
level = prefixLen / len;
|
75
78
|
} else {
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
79
|
+
ch = prefix.substring(0, 1);
|
80
|
+
if (ch === "\t") {
|
81
|
+
oneIndent = "\t";
|
82
|
+
level = prefixLen;
|
83
|
+
} else if (ch === ' ') {
|
84
|
+
oneIndent = ' '.repeat(prefixLen);
|
85
|
+
level = 1;
|
86
|
+
} else {
|
87
|
+
croak(`Bad Indentation in ${OL(line)}`);
|
88
|
+
}
|
85
89
|
}
|
90
|
+
assert(prefix === oneIndent.repeat(level), `prefix ${OL(prefix)} not a mult of ${OL(oneIndent)}`);
|
86
91
|
return level;
|
87
92
|
};
|
88
93
|
|
89
94
|
// ---------------------------------------------------------------------------
|
90
95
|
// isUndented - true iff indentLevel(line) == 0
|
91
|
-
export var isUndented =
|
92
|
-
var lMatches;
|
96
|
+
export var isUndented = (line) => {
|
93
97
|
assert(isString(line), `non-string ${OL(line)}`);
|
94
|
-
|
95
|
-
return lMatches[0].length === 0;
|
98
|
+
return notdefined(line.match(/^\s/));
|
96
99
|
};
|
97
100
|
|
98
101
|
// ---------------------------------------------------------------------------
|
99
102
|
// indented - add indentation to each string in a block or array
|
100
103
|
// - returns the same type as input, i.e. array or string
|
101
|
-
export var indented =
|
104
|
+
export var indented = (input, level = 1, oneIndent = "\t") => {
|
102
105
|
var i, lLines, len1, line, ref, toAdd;
|
103
106
|
// --- level can be a string, in which case it is
|
104
107
|
// pre-pended to each line of input
|
@@ -142,7 +145,7 @@ export var indented = function(input, level = 1, oneIndent = "\t") {
|
|
142
145
|
// - unless level is set, in which case exactly that
|
143
146
|
// indentation is removed
|
144
147
|
// - returns same type as text, i.e. either string or array
|
145
|
-
export var undented =
|
148
|
+
export var undented = (input, level = undef, oneIndent = "\t") => {
|
146
149
|
var i, lLines, lMatches, lNewLines, len1, line, nToRemove, toRemove;
|
147
150
|
if (defined(level) && (level === 0)) {
|
148
151
|
return input;
|
@@ -185,6 +188,6 @@ export var undented = function(input, level = undef, oneIndent = "\t") {
|
|
185
188
|
|
186
189
|
// ---------------------------------------------------------------------------
|
187
190
|
// enclose - indent text, surround with pre and post
|
188
|
-
export var enclose =
|
191
|
+
export var enclose = (text, pre, post, oneIndent = "\t") => {
|
189
192
|
return toBlock([pre, indented(text, 1, oneIndent), post]);
|
190
193
|
};
|
package/src/server.coffee
CHANGED
@@ -6,7 +6,7 @@ import {execSync} from 'child_process'
|
|
6
6
|
# ---------------------------------------------------------------------------
|
7
7
|
# exec - run external commands
|
8
8
|
|
9
|
-
export exec = (cmd)
|
9
|
+
export exec = (cmd) =>
|
10
10
|
|
11
11
|
buffer = execSync cmd, {
|
12
12
|
windowsHide: true
|
@@ -17,7 +17,7 @@ export exec = (cmd) ->
|
|
17
17
|
# ask - ask a question
|
18
18
|
# later, on a web page, prompt the user for answer to question
|
19
19
|
|
20
|
-
export ask = (prompt)
|
20
|
+
export ask = (prompt) =>
|
21
21
|
|
22
22
|
answer = getline.question("{prompt}? ")
|
23
23
|
return answer
|
package/src/server.js
CHANGED
@@ -8,7 +8,7 @@ import {
|
|
8
8
|
|
9
9
|
// ---------------------------------------------------------------------------
|
10
10
|
// exec - run external commands
|
11
|
-
export var exec =
|
11
|
+
export var exec = (cmd) => {
|
12
12
|
var buffer;
|
13
13
|
buffer = execSync(cmd, {
|
14
14
|
windowsHide: true
|
@@ -19,7 +19,7 @@ export var exec = function(cmd) {
|
|
19
19
|
// ---------------------------------------------------------------------------
|
20
20
|
// ask - ask a question
|
21
21
|
// later, on a web page, prompt the user for answer to question
|
22
|
-
export var ask =
|
22
|
+
export var ask = (prompt) => {
|
23
23
|
var answer;
|
24
24
|
answer = getline.question("{prompt}? ");
|
25
25
|
return answer;
|
package/src/svelte.coffee
CHANGED
@@ -7,7 +7,7 @@ import {isFunction} from '@jdeighan/base-utils'
|
|
7
7
|
# ---------------------------------------------------------------------------
|
8
8
|
# svelteSourceCodeEsc - to display source code for a *.starbucks page
|
9
9
|
|
10
|
-
export svelteSourceCodeEsc = (str)
|
10
|
+
export svelteSourceCodeEsc = (str) =>
|
11
11
|
|
12
12
|
return str \
|
13
13
|
.replace(/\</g, '<') \
|
@@ -19,7 +19,7 @@ export svelteSourceCodeEsc = (str) ->
|
|
19
19
|
# ---------------------------------------------------------------------------
|
20
20
|
# svelteHtmlEsc - after converting markdown
|
21
21
|
|
22
|
-
export svelteHtmlEsc = (str)
|
22
|
+
export svelteHtmlEsc = (str) =>
|
23
23
|
|
24
24
|
return str \
|
25
25
|
.replace(/\{/g, '{') \
|
@@ -28,7 +28,7 @@ export svelteHtmlEsc = (str) ->
|
|
28
28
|
|
29
29
|
# ---------------------------------------------------------------------------
|
30
30
|
|
31
|
-
export onInterval = (func, secs, doLog=false)
|
31
|
+
export onInterval = (func, secs, doLog=false) =>
|
32
32
|
|
33
33
|
assert isFunction(func), "onInterval(): 1st arg not a function"
|
34
34
|
ms = Math.floor(1000 * secs)
|
package/src/svelte.js
CHANGED
@@ -15,18 +15,18 @@ import {
|
|
15
15
|
|
16
16
|
// ---------------------------------------------------------------------------
|
17
17
|
// svelteSourceCodeEsc - to display source code for a *.starbucks page
|
18
|
-
export var svelteSourceCodeEsc =
|
18
|
+
export var svelteSourceCodeEsc = (str) => {
|
19
19
|
return str.replace(/\</g, '<').replace(/\>/g, '>').replace(/\{/g, '{').replace(/\}/g, '}').replace(/\$/g, '$');
|
20
20
|
};
|
21
21
|
|
22
22
|
// ---------------------------------------------------------------------------
|
23
23
|
// svelteHtmlEsc - after converting markdown
|
24
|
-
export var svelteHtmlEsc =
|
24
|
+
export var svelteHtmlEsc = (str) => {
|
25
25
|
return str.replace(/\{/g, '{').replace(/\}/g, '}').replace(/\$/g, '$');
|
26
26
|
};
|
27
27
|
|
28
28
|
// ---------------------------------------------------------------------------
|
29
|
-
export var onInterval =
|
29
|
+
export var onInterval = (func, secs, doLog = false) => {
|
30
30
|
var interval, ms;
|
31
31
|
assert(isFunction(func), "onInterval(): 1st arg not a function");
|
32
32
|
ms = Math.floor(1000 * secs);
|