@jdeighan/coffee-utils 7.0.24 → 7.0.27
Sign up to get free protection for your applications and to get access to all the features.
- package/package.json +1 -1
- package/src/block_utils.coffee +3 -3
- package/src/block_utils.js +5 -5
- package/src/coffee_utils.coffee +20 -18
- package/src/coffee_utils.js +19 -19
package/package.json
CHANGED
package/src/block_utils.coffee
CHANGED
@@ -4,7 +4,7 @@ import fs from 'fs'
|
|
4
4
|
import readline from 'readline'
|
5
5
|
|
6
6
|
import {
|
7
|
-
assert, isEmpty, isString, nonEmpty, error,
|
7
|
+
assert, isEmpty, isString, nonEmpty, error, rtrim,
|
8
8
|
} from '@jdeighan/coffee-utils'
|
9
9
|
|
10
10
|
# ---------------------------------------------------------------------------
|
@@ -84,7 +84,7 @@ export truncateBlock = (str, numLines) ->
|
|
84
84
|
export joinBlocks = (lBlocks...) ->
|
85
85
|
|
86
86
|
lNonEmptyBlocks = []
|
87
|
-
for block in lBlocks
|
87
|
+
for block in lBlocks.flat(999)
|
88
88
|
assert isString(block), "joinBlocks(): #{block} is not a string"
|
89
89
|
if nonEmpty(block)
|
90
90
|
lNonEmptyBlocks.push block
|
@@ -108,7 +108,7 @@ var lineNum = 0
|
|
108
108
|
for await (const line of rl) {
|
109
109
|
lineNum += 1
|
110
110
|
// Each line will be successively available here as 'line'
|
111
|
-
if (
|
111
|
+
if (func(line, lineNum)) {
|
112
112
|
rl.close(); // close if true return value
|
113
113
|
return;
|
114
114
|
}
|
package/src/block_utils.js
CHANGED
@@ -10,7 +10,6 @@ import {
|
|
10
10
|
isString,
|
11
11
|
nonEmpty,
|
12
12
|
error,
|
13
|
-
isComment,
|
14
13
|
rtrim
|
15
14
|
} from '@jdeighan/coffee-utils';
|
16
15
|
|
@@ -102,10 +101,11 @@ export var truncateBlock = function(str, numLines) {
|
|
102
101
|
|
103
102
|
// ---------------------------------------------------------------------------
|
104
103
|
export var joinBlocks = function(...lBlocks) {
|
105
|
-
var block, i, lNonEmptyBlocks, len1;
|
104
|
+
var block, i, lNonEmptyBlocks, len1, ref;
|
106
105
|
lNonEmptyBlocks = [];
|
107
|
-
|
108
|
-
|
106
|
+
ref = lBlocks.flat(999);
|
107
|
+
for (i = 0, len1 = ref.length; i < len1; i++) {
|
108
|
+
block = ref[i];
|
109
109
|
assert(isString(block), `joinBlocks(): ${block} is not a string`);
|
110
110
|
if (nonEmpty(block)) {
|
111
111
|
lNonEmptyBlocks.push(block);
|
@@ -130,7 +130,7 @@ var lineNum = 0
|
|
130
130
|
for await (const line of rl) {
|
131
131
|
lineNum += 1
|
132
132
|
// Each line will be successively available here as 'line'
|
133
|
-
if (
|
133
|
+
if (func(line, lineNum)) {
|
134
134
|
rl.close(); // close if true return value
|
135
135
|
return;
|
136
136
|
}
|
package/src/coffee_utils.coffee
CHANGED
@@ -133,24 +133,6 @@ export nonEmpty = (x) ->
|
|
133
133
|
|
134
134
|
# ---------------------------------------------------------------------------
|
135
135
|
|
136
|
-
commentRegExp = /^\s*\#+(?:\s|$)/
|
137
|
-
|
138
|
-
# ---------------------------------------------------------------------------
|
139
|
-
|
140
|
-
export setCommentRegexp = (regexp) ->
|
141
|
-
|
142
|
-
commentRegExp = regexp
|
143
|
-
return
|
144
|
-
|
145
|
-
# ---------------------------------------------------------------------------
|
146
|
-
|
147
|
-
export isComment = (str) ->
|
148
|
-
|
149
|
-
assert isString(str), "isComment(): not a string"
|
150
|
-
return if str.match(commentRegExp) then true else false
|
151
|
-
|
152
|
-
# ---------------------------------------------------------------------------
|
153
|
-
|
154
136
|
export words = (str) ->
|
155
137
|
|
156
138
|
return str.trim().split(/\s+/)
|
@@ -411,3 +393,23 @@ export replaceVars = (line, hVars={}, rx=/__(env\.)?([A-Za-z_]\w*)__/g) ->
|
|
411
393
|
return result
|
412
394
|
|
413
395
|
return line.replace(rx, replacerFunc)
|
396
|
+
|
397
|
+
# ---------------------------------------------------------------------------
|
398
|
+
|
399
|
+
export defined = (obj) ->
|
400
|
+
|
401
|
+
return (obj != undef) && (obj != null)
|
402
|
+
|
403
|
+
# ---------------------------------------------------------------------------
|
404
|
+
|
405
|
+
export notdefined = (obj) ->
|
406
|
+
|
407
|
+
return (obj == undef) || (obj == null)
|
408
|
+
|
409
|
+
# ---------------------------------------------------------------------------
|
410
|
+
|
411
|
+
export isIterable = (obj) ->
|
412
|
+
|
413
|
+
if (obj == undef) || (obj == null)
|
414
|
+
return false
|
415
|
+
return typeof obj[Symbol.iterator] == 'function'
|
package/src/coffee_utils.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
// Generated by CoffeeScript 2.6.1
|
2
2
|
// coffee_utils.coffee
|
3
|
-
var LOG
|
3
|
+
var LOG;
|
4
4
|
|
5
5
|
export var sep_dash = '-'.repeat(42);
|
6
6
|
|
@@ -128,24 +128,6 @@ export var nonEmpty = function(x) {
|
|
128
128
|
}
|
129
129
|
};
|
130
130
|
|
131
|
-
// ---------------------------------------------------------------------------
|
132
|
-
commentRegExp = /^\s*\#+(?:\s|$)/;
|
133
|
-
|
134
|
-
// ---------------------------------------------------------------------------
|
135
|
-
export var setCommentRegexp = function(regexp) {
|
136
|
-
commentRegExp = regexp;
|
137
|
-
};
|
138
|
-
|
139
|
-
// ---------------------------------------------------------------------------
|
140
|
-
export var isComment = function(str) {
|
141
|
-
assert(isString(str), "isComment(): not a string");
|
142
|
-
if (str.match(commentRegExp)) {
|
143
|
-
return true;
|
144
|
-
} else {
|
145
|
-
return false;
|
146
|
-
}
|
147
|
-
};
|
148
|
-
|
149
131
|
// ---------------------------------------------------------------------------
|
150
132
|
export var words = function(str) {
|
151
133
|
return str.trim().split(/\s+/);
|
@@ -446,3 +428,21 @@ export var replaceVars = function(line, hVars = {}, rx = /__(env\.)?([A-Za-z_]\w
|
|
446
428
|
};
|
447
429
|
return line.replace(rx, replacerFunc);
|
448
430
|
};
|
431
|
+
|
432
|
+
// ---------------------------------------------------------------------------
|
433
|
+
export var defined = function(obj) {
|
434
|
+
return (obj !== undef) && (obj !== null);
|
435
|
+
};
|
436
|
+
|
437
|
+
// ---------------------------------------------------------------------------
|
438
|
+
export var notdefined = function(obj) {
|
439
|
+
return (obj === undef) || (obj === null);
|
440
|
+
};
|
441
|
+
|
442
|
+
// ---------------------------------------------------------------------------
|
443
|
+
export var isIterable = function(obj) {
|
444
|
+
if ((obj === undef) || (obj === null)) {
|
445
|
+
return false;
|
446
|
+
}
|
447
|
+
return typeof obj[Symbol.iterator] === 'function';
|
448
|
+
};
|