@jdeighan/coffee-utils 11.0.3 → 11.0.5
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 +4 -4
- package/src/Section.coffee +1 -1
- package/src/Section.js +4 -4
- package/src/SectionMap.coffee +3 -2
- package/src/SectionMap.js +8 -5
- package/src/block.coffee +2 -32
- package/src/block.js +17 -44
- package/src/fs.coffee +2 -1
- package/src/fs.js +4 -1
- package/src/fsa.coffee +3 -2
- package/src/fsa.js +8 -5
- package/src/svelte.coffee +2 -1
- package/src/svelte.js +5 -2
- package/src/utils.coffee +20 -310
- package/src/utils.js +87 -366
- package/src/arrow.coffee +0 -65
- package/src/arrow.js +0 -83
- package/src/debug.coffee +0 -300
- package/src/debug.js +0 -329
- package/src/log.coffee +0 -186
- package/src/log.js +0 -206
- package/src/stack.coffee +0 -169
- package/src/stack.js +0 -191
package/src/utils.js
CHANGED
@@ -1,53 +1,88 @@
|
|
1
1
|
// Generated by CoffeeScript 2.7.0
|
2
2
|
// utils.coffee
|
3
3
|
import {
|
4
|
-
LOG,
|
5
4
|
assert,
|
6
5
|
croak
|
7
6
|
} from '@jdeighan/exceptions';
|
8
7
|
|
9
|
-
|
10
|
-
|
11
|
-
|
8
|
+
import {
|
9
|
+
LOG,
|
10
|
+
sep_dash,
|
11
|
+
sep_eq
|
12
|
+
} from '@jdeighan/exceptions/log';
|
12
13
|
|
13
|
-
|
14
|
+
import {
|
15
|
+
undef,
|
16
|
+
pass,
|
17
|
+
defined,
|
18
|
+
notdefined,
|
19
|
+
deepCopy,
|
20
|
+
escapeStr,
|
21
|
+
unescapeStr,
|
22
|
+
hasChar,
|
23
|
+
quoted,
|
24
|
+
OL,
|
25
|
+
isString,
|
26
|
+
isNumber,
|
27
|
+
isInteger,
|
28
|
+
isHash,
|
29
|
+
isArray,
|
30
|
+
isBoolean,
|
31
|
+
isConstructor,
|
32
|
+
isFunction,
|
33
|
+
isRegExp,
|
34
|
+
isObject,
|
35
|
+
getClassName,
|
36
|
+
jsType,
|
37
|
+
isEmpty,
|
38
|
+
nonEmpty,
|
39
|
+
chomp,
|
40
|
+
rtrim,
|
41
|
+
setCharsAt,
|
42
|
+
words
|
43
|
+
} from '@jdeighan/exceptions/utils';
|
44
|
+
|
45
|
+
export {
|
46
|
+
undef,
|
47
|
+
pass,
|
48
|
+
defined,
|
49
|
+
notdefined,
|
50
|
+
sep_dash,
|
51
|
+
sep_eq,
|
52
|
+
deepCopy,
|
53
|
+
escapeStr,
|
54
|
+
unescapeStr,
|
55
|
+
hasChar,
|
56
|
+
quoted,
|
57
|
+
OL,
|
58
|
+
isString,
|
59
|
+
isNumber,
|
60
|
+
isInteger,
|
61
|
+
isHash,
|
62
|
+
isArray,
|
63
|
+
isBoolean,
|
64
|
+
isConstructor,
|
65
|
+
isFunction,
|
66
|
+
isRegExp,
|
67
|
+
isObject,
|
68
|
+
getClassName,
|
69
|
+
jsType,
|
70
|
+
isEmpty,
|
71
|
+
nonEmpty,
|
72
|
+
chomp,
|
73
|
+
rtrim,
|
74
|
+
setCharsAt,
|
75
|
+
words
|
76
|
+
};
|
14
77
|
|
15
78
|
// ---------------------------------------------------------------------------
|
16
79
|
// TEMP!!!!!
|
17
|
-
export var isComment =
|
80
|
+
export var isComment = (line) => {
|
18
81
|
var lMatches;
|
19
82
|
lMatches = line.match(/^\s*\#(\s|$)/);
|
20
83
|
return defined(lMatches);
|
21
84
|
};
|
22
85
|
|
23
|
-
// ---------------------------------------------------------------------------
|
24
|
-
export var chomp = function(str) {
|
25
|
-
var len, tail;
|
26
|
-
len = str.length;
|
27
|
-
if (len === 0) {
|
28
|
-
return '';
|
29
|
-
} else if (len === 1) {
|
30
|
-
if ((str === "\r") || (str === "\n")) {
|
31
|
-
return '';
|
32
|
-
} else {
|
33
|
-
return str;
|
34
|
-
}
|
35
|
-
} else {
|
36
|
-
// --- check the last 2 characters
|
37
|
-
tail = str.substring(len - 2);
|
38
|
-
if (tail === "\r\n") {
|
39
|
-
return str.substring(0, len - 2);
|
40
|
-
} else {
|
41
|
-
tail = str.substring(len - 1);
|
42
|
-
if (tail === "\n") {
|
43
|
-
return str.substring(0, len - 1);
|
44
|
-
} else {
|
45
|
-
return str;
|
46
|
-
}
|
47
|
-
}
|
48
|
-
}
|
49
|
-
};
|
50
|
-
|
51
86
|
// ---------------------------------------------------------------------------
|
52
87
|
export var isSubclassOf = function(subClass, superClass) {
|
53
88
|
return (subClass === superClass) || (subClass.prototype instanceof superClass);
|
@@ -59,10 +94,6 @@ export var eval_expr = function(str) {
|
|
59
94
|
return Function('"use strict";return (' + str + ')')();
|
60
95
|
};
|
61
96
|
|
62
|
-
// ---------------------------------------------------------------------------
|
63
|
-
// pass - do nothing
|
64
|
-
export var pass = function() {};
|
65
|
-
|
66
97
|
// ---------------------------------------------------------------------------
|
67
98
|
export var patchStr = function(bigstr, pos, str) {
|
68
99
|
var endpos;
|
@@ -91,68 +122,6 @@ export var oneof = function(word, ...lWords) {
|
|
91
122
|
return lWords.indexOf(word) >= 0;
|
92
123
|
};
|
93
124
|
|
94
|
-
// ---------------------------------------------------------------------------
|
95
|
-
export var isConstructor = function(f) {
|
96
|
-
var err;
|
97
|
-
try {
|
98
|
-
new f();
|
99
|
-
} catch (error) {
|
100
|
-
err = error;
|
101
|
-
if (err.message.indexOf('is not a constructor') >= 0) {
|
102
|
-
return false;
|
103
|
-
}
|
104
|
-
}
|
105
|
-
return true;
|
106
|
-
};
|
107
|
-
|
108
|
-
// ---------------------------------------------------------------------------
|
109
|
-
export var jsType = function(x) {
|
110
|
-
var lKeys;
|
111
|
-
if (notdefined(x)) {
|
112
|
-
return [undef, undef];
|
113
|
-
} else if (isString(x)) {
|
114
|
-
if (x.match(/^\s*$/)) {
|
115
|
-
return ['string', 'empty'];
|
116
|
-
} else {
|
117
|
-
return ['string', undef];
|
118
|
-
}
|
119
|
-
} else if (isNumber(x)) {
|
120
|
-
if (Number.isInteger(x)) {
|
121
|
-
return ['number', 'integer'];
|
122
|
-
} else {
|
123
|
-
return ['number', undef];
|
124
|
-
}
|
125
|
-
} else if (isBoolean(x)) {
|
126
|
-
return ['boolean', undef];
|
127
|
-
} else if (isHash(x)) {
|
128
|
-
lKeys = Object.keys(x);
|
129
|
-
if (lKeys.length === 0) {
|
130
|
-
return ['hash', 'empty'];
|
131
|
-
} else {
|
132
|
-
return ['hash', undef];
|
133
|
-
}
|
134
|
-
} else if (isArray(x)) {
|
135
|
-
if (x.length === 0) {
|
136
|
-
return ['array', 'empty'];
|
137
|
-
} else {
|
138
|
-
return ['array', undef];
|
139
|
-
}
|
140
|
-
} else if (isConstructor(x)) {
|
141
|
-
return ['function', 'constructor'];
|
142
|
-
} else if (isFunction(x)) {
|
143
|
-
return ['function', undef];
|
144
|
-
} else if (isObject(x)) {
|
145
|
-
return ['object', undef];
|
146
|
-
} else {
|
147
|
-
return croak(`Unknown type: ${OL(x)}`);
|
148
|
-
}
|
149
|
-
};
|
150
|
-
|
151
|
-
// ---------------------------------------------------------------------------
|
152
|
-
export var isString = function(x) {
|
153
|
-
return (typeof x === 'string') || (x instanceof String);
|
154
|
-
};
|
155
|
-
|
156
125
|
// ---------------------------------------------------------------------------
|
157
126
|
export var isNonEmptyString = function(x) {
|
158
127
|
if (typeof x !== 'string' && !(x instanceof String)) {
|
@@ -164,67 +133,11 @@ export var isNonEmptyString = function(x) {
|
|
164
133
|
return true;
|
165
134
|
};
|
166
135
|
|
167
|
-
// ---------------------------------------------------------------------------
|
168
|
-
export var isBoolean = function(x) {
|
169
|
-
return typeof x === 'boolean';
|
170
|
-
};
|
171
|
-
|
172
|
-
// ---------------------------------------------------------------------------
|
173
|
-
export var isObject = function(x, lReqKeys = undef) {
|
174
|
-
var i, key, len1, result;
|
175
|
-
result = (typeof x === 'object') && !isString(x) && !isArray(x) && !isHash(x) && !isNumber(x);
|
176
|
-
if (result) {
|
177
|
-
if (defined(lReqKeys)) {
|
178
|
-
assert(isArray(lReqKeys), "lReqKeys is not an array");
|
179
|
-
for (i = 0, len1 = lReqKeys.length; i < len1; i++) {
|
180
|
-
key = lReqKeys[i];
|
181
|
-
if (!x.hasOwnProperty(key)) {
|
182
|
-
return false;
|
183
|
-
}
|
184
|
-
}
|
185
|
-
}
|
186
|
-
return true;
|
187
|
-
} else {
|
188
|
-
return false;
|
189
|
-
}
|
190
|
-
};
|
191
|
-
|
192
|
-
// ---------------------------------------------------------------------------
|
193
|
-
export var getClassName = function(obj) {
|
194
|
-
if (typeof obj !== 'object') {
|
195
|
-
return undef;
|
196
|
-
}
|
197
|
-
return obj.constructor.name;
|
198
|
-
};
|
199
|
-
|
200
|
-
// ---------------------------------------------------------------------------
|
201
|
-
export var isArray = function(x) {
|
202
|
-
return Array.isArray(x);
|
203
|
-
};
|
204
|
-
|
205
136
|
// ---------------------------------------------------------------------------
|
206
137
|
export var isNonEmptyArray = function(x) {
|
207
138
|
return isArray(x) && (x.length > 0);
|
208
139
|
};
|
209
140
|
|
210
|
-
// ---------------------------------------------------------------------------
|
211
|
-
export var isHash = function(x, lKeys) {
|
212
|
-
var i, key, len1;
|
213
|
-
if (!x || (getClassName(x) !== 'Object')) {
|
214
|
-
return false;
|
215
|
-
}
|
216
|
-
if (defined(lKeys)) {
|
217
|
-
assert(isArray(lKeys), "isHash(): lKeys not an array");
|
218
|
-
for (i = 0, len1 = lKeys.length; i < len1; i++) {
|
219
|
-
key = lKeys[i];
|
220
|
-
if (!x.hasOwnProperty(key)) {
|
221
|
-
return false;
|
222
|
-
}
|
223
|
-
}
|
224
|
-
}
|
225
|
-
return true;
|
226
|
-
};
|
227
|
-
|
228
141
|
// ---------------------------------------------------------------------------
|
229
142
|
export var isNonEmptyHash = function(x) {
|
230
143
|
return isHash(x) && (Object.keys(x).length > 0);
|
@@ -237,46 +150,6 @@ export var hashHasKey = function(x, key) {
|
|
237
150
|
return x.hasOwnProperty(key);
|
238
151
|
};
|
239
152
|
|
240
|
-
// ---------------------------------------------------------------------------
|
241
|
-
// isEmpty
|
242
|
-
// - string is whitespace, array has no elements, hash has no keys
|
243
|
-
export var isEmpty = function(x) {
|
244
|
-
if ((x === undef) || (x === null)) {
|
245
|
-
return true;
|
246
|
-
}
|
247
|
-
if (isString(x)) {
|
248
|
-
return x.match(/^\s*$/);
|
249
|
-
}
|
250
|
-
if (isArray(x)) {
|
251
|
-
return x.length === 0;
|
252
|
-
}
|
253
|
-
if (isHash(x)) {
|
254
|
-
return Object.keys(x).length === 0;
|
255
|
-
} else {
|
256
|
-
return false;
|
257
|
-
}
|
258
|
-
};
|
259
|
-
|
260
|
-
// ---------------------------------------------------------------------------
|
261
|
-
// nonEmpty
|
262
|
-
// - string has non-whitespace, array has elements, hash has keys
|
263
|
-
export var nonEmpty = function(x) {
|
264
|
-
if (x == null) {
|
265
|
-
return false;
|
266
|
-
}
|
267
|
-
if (isString(x)) {
|
268
|
-
return !x.match(/^\s*$/);
|
269
|
-
}
|
270
|
-
if (isArray(x)) {
|
271
|
-
return x.length > 0;
|
272
|
-
}
|
273
|
-
if (isHash(x)) {
|
274
|
-
return Object.keys(x).length > 0;
|
275
|
-
} else {
|
276
|
-
return croak("isEmpty(): Invalid parameter");
|
277
|
-
}
|
278
|
-
};
|
279
|
-
|
280
153
|
// ---------------------------------------------------------------------------
|
281
154
|
export var notInArray = function(lItems, item) {
|
282
155
|
return lItems.indexOf(item) === -1;
|
@@ -292,22 +165,13 @@ export var pushCond = function(lItems, item, doPush = notInArray) {
|
|
292
165
|
}
|
293
166
|
};
|
294
167
|
|
295
|
-
// ---------------------------------------------------------------------------
|
296
|
-
export var words = function(str) {
|
297
|
-
str = str.trim();
|
298
|
-
if (str === '') {
|
299
|
-
return [];
|
300
|
-
}
|
301
|
-
return str.split(/\s+/);
|
302
|
-
};
|
303
|
-
|
304
168
|
// ---------------------------------------------------------------------------
|
305
169
|
export var isArrayOfHashes = function(lItems) {
|
306
|
-
var i, item,
|
170
|
+
var i, item, len;
|
307
171
|
if (!isArray(lItems)) {
|
308
172
|
return false;
|
309
173
|
}
|
310
|
-
for (i = 0,
|
174
|
+
for (i = 0, len = lItems.length; i < len; i++) {
|
311
175
|
item = lItems[i];
|
312
176
|
if (!isHash(item)) {
|
313
177
|
return false;
|
@@ -318,11 +182,11 @@ export var isArrayOfHashes = function(lItems) {
|
|
318
182
|
|
319
183
|
// ---------------------------------------------------------------------------
|
320
184
|
export var isArrayOfStrings = function(lItems) {
|
321
|
-
var i, item,
|
185
|
+
var i, item, len;
|
322
186
|
if (!isArray(lItems)) {
|
323
187
|
return false;
|
324
188
|
}
|
325
|
-
for (i = 0,
|
189
|
+
for (i = 0, len = lItems.length; i < len; i++) {
|
326
190
|
item = lItems[i];
|
327
191
|
if (!isString(item)) {
|
328
192
|
return false;
|
@@ -331,57 +195,9 @@ export var isArrayOfStrings = function(lItems) {
|
|
331
195
|
return true;
|
332
196
|
};
|
333
197
|
|
334
|
-
// ---------------------------------------------------------------------------
|
335
|
-
export var isFunction = function(x) {
|
336
|
-
return typeof x === 'function';
|
337
|
-
};
|
338
|
-
|
339
|
-
// ---------------------------------------------------------------------------
|
340
|
-
export var isRegExp = function(x) {
|
341
|
-
return x instanceof RegExp;
|
342
|
-
};
|
343
|
-
|
344
|
-
// ---------------------------------------------------------------------------
|
345
|
-
export var isNumber = function(x, hOptions = undef) {
|
346
|
-
var max, min, result;
|
347
|
-
result = (typeof x === 'number') || (x instanceof Number);
|
348
|
-
if (result && defined(hOptions)) {
|
349
|
-
assert(isHash(hOptions), `2nd arg not a hash: ${OL(hOptions)}`);
|
350
|
-
({min, max} = hOptions);
|
351
|
-
if (defined(min) && (x < min)) {
|
352
|
-
result = false;
|
353
|
-
}
|
354
|
-
if (defined(max) && (x > max)) {
|
355
|
-
result = false;
|
356
|
-
}
|
357
|
-
}
|
358
|
-
return result;
|
359
|
-
};
|
360
|
-
|
361
|
-
// ---------------------------------------------------------------------------
|
362
|
-
export var isInteger = function(x, hOptions = {}) {
|
363
|
-
var result;
|
364
|
-
if (typeof x === 'number') {
|
365
|
-
result = Number.isInteger(x);
|
366
|
-
} else if (x instanceof Number) {
|
367
|
-
result = Number.isInteger(x.valueOf());
|
368
|
-
} else {
|
369
|
-
result = false;
|
370
|
-
}
|
371
|
-
if (result) {
|
372
|
-
if (defined(hOptions.min) && (x < hOptions.min)) {
|
373
|
-
result = false;
|
374
|
-
}
|
375
|
-
if (defined(hOptions.max) && (x > hOptions.max)) {
|
376
|
-
result = false;
|
377
|
-
}
|
378
|
-
}
|
379
|
-
return result;
|
380
|
-
};
|
381
|
-
|
382
198
|
// ---------------------------------------------------------------------------
|
383
199
|
export var isUniqueList = function(lItems, func = undef) {
|
384
|
-
var h, i, item,
|
200
|
+
var h, i, item, len;
|
385
201
|
if (lItems == null) {
|
386
202
|
return true; // empty list is unique
|
387
203
|
}
|
@@ -389,7 +205,7 @@ export var isUniqueList = function(lItems, func = undef) {
|
|
389
205
|
assert(isFunction(func), `Not a function: ${OL(func)}`);
|
390
206
|
}
|
391
207
|
h = {};
|
392
|
-
for (i = 0,
|
208
|
+
for (i = 0, len = lItems.length; i < len; i++) {
|
393
209
|
item = lItems[i];
|
394
210
|
if (defined(func) && !func(item)) {
|
395
211
|
return false;
|
@@ -404,14 +220,14 @@ export var isUniqueList = function(lItems, func = undef) {
|
|
404
220
|
|
405
221
|
// ---------------------------------------------------------------------------
|
406
222
|
export var isUniqueTree = function(lItems, func = undef, hFound = {}) {
|
407
|
-
var i, item,
|
223
|
+
var i, item, len;
|
408
224
|
if (isEmpty(lItems)) {
|
409
225
|
return true; // empty list is unique
|
410
226
|
}
|
411
227
|
if (defined(func)) {
|
412
228
|
assert(isFunction(func), `Not a function: ${OL(func)}`);
|
413
229
|
}
|
414
|
-
for (i = 0,
|
230
|
+
for (i = 0, len = lItems.length; i < len; i++) {
|
415
231
|
item = lItems[i];
|
416
232
|
if (isArray(item)) {
|
417
233
|
if (!isUniqueTree(item, func, hFound)) {
|
@@ -473,20 +289,6 @@ export var titleLine = function(title, char = '=', padding = 2, linelen = 42) {
|
|
473
289
|
return strLeft + strMiddle + strRight;
|
474
290
|
};
|
475
291
|
|
476
|
-
// ---------------------------------------------------------------------------
|
477
|
-
// rtrim - strip trailing whitespace
|
478
|
-
export var rtrim = function(line) {
|
479
|
-
var lMatches, n;
|
480
|
-
assert(isString(line), "rtrim(): line is not a string");
|
481
|
-
lMatches = line.match(/\s+$/);
|
482
|
-
if (lMatches != null) {
|
483
|
-
n = lMatches[0].length; // num chars to remove
|
484
|
-
return line.substring(0, line.length - n);
|
485
|
-
} else {
|
486
|
-
return line;
|
487
|
-
}
|
488
|
-
};
|
489
|
-
|
490
292
|
// ---------------------------------------------------------------------------
|
491
293
|
// rtrunc - strip nChars chars from right of a string
|
492
294
|
export var rtrunc = function(str, nChars) {
|
@@ -499,66 +301,6 @@ export var ltrunc = function(str, nChars) {
|
|
499
301
|
return str.substring(nChars);
|
500
302
|
};
|
501
303
|
|
502
|
-
// ---------------------------------------------------------------------------
|
503
|
-
// deepCopy - deep copy an array or object
|
504
|
-
export var deepCopy = function(obj) {
|
505
|
-
var err, newObj, objStr;
|
506
|
-
if (obj === undef) {
|
507
|
-
return undef;
|
508
|
-
}
|
509
|
-
objStr = JSON.stringify(obj);
|
510
|
-
try {
|
511
|
-
newObj = JSON.parse(objStr);
|
512
|
-
} catch (error) {
|
513
|
-
err = error;
|
514
|
-
croak("ERROR: err.message", objStr);
|
515
|
-
}
|
516
|
-
return newObj;
|
517
|
-
};
|
518
|
-
|
519
|
-
// ---------------------------------------------------------------------------
|
520
|
-
// escapeStr - escape newlines, TAB chars, etc.
|
521
|
-
export var hDefEsc = {
|
522
|
-
"\n": '®',
|
523
|
-
"\t": '→',
|
524
|
-
" ": '˳'
|
525
|
-
};
|
526
|
-
|
527
|
-
export var escapeStr = function(str, hEscape = hDefEsc) {
|
528
|
-
var ch, lParts;
|
529
|
-
assert(isString(str), "escapeStr(): not a string");
|
530
|
-
lParts = (function() {
|
531
|
-
var i, len1, ref, results;
|
532
|
-
ref = str.split('');
|
533
|
-
results = [];
|
534
|
-
for (i = 0, len1 = ref.length; i < len1; i++) {
|
535
|
-
ch = ref[i];
|
536
|
-
if (hEscape[ch] != null) {
|
537
|
-
results.push(hEscape[ch]);
|
538
|
-
} else {
|
539
|
-
results.push(ch);
|
540
|
-
}
|
541
|
-
}
|
542
|
-
return results;
|
543
|
-
})();
|
544
|
-
return lParts.join('');
|
545
|
-
};
|
546
|
-
|
547
|
-
// ---------------------------------------------------------------------------
|
548
|
-
export var oneline = function(obj) {
|
549
|
-
if (obj != null) {
|
550
|
-
if (isString(obj)) {
|
551
|
-
return `'${escapeStr(obj)}'`;
|
552
|
-
} else {
|
553
|
-
return JSON.stringify(obj);
|
554
|
-
}
|
555
|
-
} else {
|
556
|
-
return 'undef';
|
557
|
-
}
|
558
|
-
};
|
559
|
-
|
560
|
-
export var OL = oneline;
|
561
|
-
|
562
304
|
// ---------------------------------------------------------------------------
|
563
305
|
export var removeCR = function(str) {
|
564
306
|
return str.replace(/\r/g, '');
|
@@ -575,9 +317,9 @@ export var extractMatches = function(line, regexp, convertFunc = undef) {
|
|
575
317
|
var lConverted, lStrings, str;
|
576
318
|
lStrings = [...line.matchAll(regexp)];
|
577
319
|
lStrings = (function() {
|
578
|
-
var i,
|
320
|
+
var i, len, results;
|
579
321
|
results = [];
|
580
|
-
for (i = 0,
|
322
|
+
for (i = 0, len = lStrings.length; i < len; i++) {
|
581
323
|
str = lStrings[i];
|
582
324
|
results.push(str[0]);
|
583
325
|
}
|
@@ -585,9 +327,9 @@ export var extractMatches = function(line, regexp, convertFunc = undef) {
|
|
585
327
|
})();
|
586
328
|
if (convertFunc != null) {
|
587
329
|
lConverted = (function() {
|
588
|
-
var i,
|
330
|
+
var i, len, results;
|
589
331
|
results = [];
|
590
|
-
for (i = 0,
|
332
|
+
for (i = 0, len = lStrings.length; i < len; i++) {
|
591
333
|
str = lStrings[i];
|
592
334
|
results.push(convertFunc(str));
|
593
335
|
}
|
@@ -601,14 +343,14 @@ export var extractMatches = function(line, regexp, convertFunc = undef) {
|
|
601
343
|
|
602
344
|
// ---------------------------------------------------------------------------
|
603
345
|
export var envVarsWithPrefix = function(prefix, hOptions = {}) {
|
604
|
-
var h, i, key,
|
346
|
+
var h, i, key, len, plen, ref;
|
605
347
|
// --- valid options:
|
606
348
|
// stripPrefix
|
607
349
|
assert(prefix, "envVarsWithPrefix: empty prefix!");
|
608
350
|
plen = prefix.length;
|
609
351
|
h = {};
|
610
352
|
ref = Object.keys(process.env);
|
611
|
-
for (i = 0,
|
353
|
+
for (i = 0, len = ref.length; i < len; i++) {
|
612
354
|
key = ref[i];
|
613
355
|
if (key.indexOf(prefix) === 0) {
|
614
356
|
if (hOptions.stripPrefix) {
|
@@ -639,9 +381,9 @@ export var getDateStr = function(date = undef) {
|
|
639
381
|
|
640
382
|
// ---------------------------------------------------------------------------
|
641
383
|
export var strcat = function(...lItems) {
|
642
|
-
var i, item,
|
384
|
+
var i, item, len, str;
|
643
385
|
str = '';
|
644
|
-
for (i = 0,
|
386
|
+
for (i = 0, len = lItems.length; i < len; i++) {
|
645
387
|
item = lItems[i];
|
646
388
|
str += item.toString();
|
647
389
|
}
|
@@ -672,16 +414,6 @@ export var replaceVars = function(line, hVars = {}, rx = /__(env\.)?([A-Za-z_]\w
|
|
672
414
|
return line.replace(rx, replacerFunc);
|
673
415
|
};
|
674
416
|
|
675
|
-
// ---------------------------------------------------------------------------
|
676
|
-
export var defined = function(obj) {
|
677
|
-
return (obj !== undef) && (obj !== null);
|
678
|
-
};
|
679
|
-
|
680
|
-
// ---------------------------------------------------------------------------
|
681
|
-
export var notdefined = function(obj) {
|
682
|
-
return (obj === undef) || (obj === null);
|
683
|
-
};
|
684
|
-
|
685
417
|
// ---------------------------------------------------------------------------
|
686
418
|
export var isIterable = function(obj) {
|
687
419
|
if ((obj === undef) || (obj === null)) {
|
@@ -710,25 +442,14 @@ export var range = function(n) {
|
|
710
442
|
}).apply(this);
|
711
443
|
};
|
712
444
|
|
713
|
-
// ---------------------------------------------------------------------------
|
714
|
-
export var setCharsAt = function(str, pos, str2) {
|
715
|
-
assert(pos >= 0, `negative pos ${pos} not allowed`);
|
716
|
-
assert(pos < str.length, `pos ${pos} not in ${OL(str)}`);
|
717
|
-
if (pos + str2.length >= str.length) {
|
718
|
-
return str.substring(0, pos) + str2;
|
719
|
-
} else {
|
720
|
-
return str.substring(0, pos) + str2 + str.substring(pos + str2.length);
|
721
|
-
}
|
722
|
-
};
|
723
|
-
|
724
445
|
// ---------------------------------------------------------------------------
|
725
446
|
export var getOptions = function(hOptions, hDefault = {}) {
|
726
|
-
var h, i,
|
447
|
+
var h, i, len, ref, word;
|
727
448
|
// --- If hOptions is a string, break into words and set each to true
|
728
449
|
if (isString(hOptions)) {
|
729
450
|
h = {};
|
730
451
|
ref = words(hOptions);
|
731
|
-
for (i = 0,
|
452
|
+
for (i = 0, len = ref.length; i < len; i++) {
|
732
453
|
word = ref[i];
|
733
454
|
h[word] = true;
|
734
455
|
}
|
package/src/arrow.coffee
DELETED
@@ -1,65 +0,0 @@
|
|
1
|
-
# arrow.coffee
|
2
|
-
|
3
|
-
import {assert} from '@jdeighan/exceptions'
|
4
|
-
import {undef, OL, setCharsAt} from '@jdeighan/coffee-utils'
|
5
|
-
|
6
|
-
# --- We use spaces here because Windows Terminal handles TAB chars badly
|
7
|
-
|
8
|
-
export vbar = '│' # unicode 2502
|
9
|
-
export hbar = '─' # unicode 2500
|
10
|
-
export corner = '└' # unicode 2514
|
11
|
-
export arrowhead = '>'
|
12
|
-
export space = ' '
|
13
|
-
export dot = '.'
|
14
|
-
|
15
|
-
export oneIndent = vbar + space + space + space
|
16
|
-
export arrow = corner + hbar + arrowhead + space
|
17
|
-
export clearIndent = space + space + space + space
|
18
|
-
export dotIndent = dot + space + space + space
|
19
|
-
|
20
|
-
# ---------------------------------------------------------------------------
|
21
|
-
|
22
|
-
export prefix = (level, option='none') ->
|
23
|
-
|
24
|
-
switch option
|
25
|
-
when 'withArrow'
|
26
|
-
if (level == 0)
|
27
|
-
return arrow
|
28
|
-
else
|
29
|
-
return oneIndent.repeat(level-1) + arrow
|
30
|
-
when 'noLastVbar'
|
31
|
-
assert (level >= 1), "prefix(), noLastVbar but level=#{OL(level)}"
|
32
|
-
return oneIndent.repeat(level-1) + clearIndent
|
33
|
-
when 'noLast2Vbars'
|
34
|
-
assert (level >= 2), "prefix(), noLast2Vbars but level=#{OL(level)}"
|
35
|
-
return oneIndent.repeat(level-2) + clearIndent + clearIndent
|
36
|
-
when 'dotLastVbar'
|
37
|
-
assert (level >= 1), "prefix(), dotLastVbar but level=#{OL(level)}"
|
38
|
-
return oneIndent.repeat(level-1) + dotIndent
|
39
|
-
when 'dotLast2Vbars'
|
40
|
-
assert (level >= 2), "prefix(), dotLast2Vbars but level=#{OL(level)}"
|
41
|
-
return oneIndent.repeat(level-2) + dotIndent + clearIndent
|
42
|
-
else
|
43
|
-
return oneIndent.repeat(level)
|
44
|
-
|
45
|
-
# ---------------------------------------------------------------------------
|
46
|
-
|
47
|
-
export addArrow = (prefix) ->
|
48
|
-
|
49
|
-
pos = prefix.lastIndexOf(vbar)
|
50
|
-
if (pos == -1)
|
51
|
-
result = prefix
|
52
|
-
else
|
53
|
-
result = setCharsAt(prefix, pos, arrow)
|
54
|
-
return result
|
55
|
-
|
56
|
-
# ---------------------------------------------------------------------------
|
57
|
-
|
58
|
-
export removeLastVbar = (prefix) ->
|
59
|
-
|
60
|
-
pos = prefix.lastIndexOf(vbar)
|
61
|
-
if (pos == -1)
|
62
|
-
result = prefix
|
63
|
-
else
|
64
|
-
result = setCharsAt(prefix, pos, ' ')
|
65
|
-
return result
|