@jdeighan/coffee-utils 10.0.15 → 10.0.17
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 +5 -4
- package/src/block_utils.js +6 -3
- package/src/coffee_utils.coffee +20 -0
- package/src/coffee_utils.js +24 -0
- package/src/indent_utils.coffee +2 -1
- package/src/indent_utils.js +2 -1
package/package.json
CHANGED
package/src/block_utils.coffee
CHANGED
@@ -5,8 +5,9 @@ import readline from 'readline'
|
|
5
5
|
|
6
6
|
import {assert, error, croak} from '@jdeighan/unit-tester/utils'
|
7
7
|
import {
|
8
|
-
undef, pass, defined,
|
9
|
-
|
8
|
+
undef, pass, defined, notdefined,
|
9
|
+
isEmpty, isString, isArray, nonEmpty, isArrayOfStrings,
|
10
|
+
escapeStr, rtrim, OL,
|
10
11
|
} from '@jdeighan/coffee-utils'
|
11
12
|
|
12
13
|
# ---------------------------------------------------------------------------
|
@@ -90,9 +91,9 @@ export arrayToBlock = (lLines) ->
|
|
90
91
|
|
91
92
|
export toBlock = (lLines) ->
|
92
93
|
|
93
|
-
if (lLines
|
94
|
+
if notdefined(lLines)
|
94
95
|
return undef
|
95
|
-
assert
|
96
|
+
assert isArrayOfStrings(lLines), "lLines is not an array: #{OL(lLines)}"
|
96
97
|
lNewLines = []
|
97
98
|
for line in lLines
|
98
99
|
if defined(line)
|
package/src/block_utils.js
CHANGED
@@ -14,12 +14,15 @@ import {
|
|
14
14
|
undef,
|
15
15
|
pass,
|
16
16
|
defined,
|
17
|
+
notdefined,
|
17
18
|
isEmpty,
|
18
19
|
isString,
|
19
20
|
isArray,
|
20
21
|
nonEmpty,
|
22
|
+
isArrayOfStrings,
|
23
|
+
escapeStr,
|
21
24
|
rtrim,
|
22
|
-
|
25
|
+
OL
|
23
26
|
} from '@jdeighan/coffee-utils';
|
24
27
|
|
25
28
|
// ---------------------------------------------------------------------------
|
@@ -113,10 +116,10 @@ export var arrayToBlock = function(lLines) {
|
|
113
116
|
// but undef items are ignored
|
114
117
|
export var toBlock = function(lLines) {
|
115
118
|
var i, lNewLines, len1, line;
|
116
|
-
if (lLines
|
119
|
+
if (notdefined(lLines)) {
|
117
120
|
return undef;
|
118
121
|
}
|
119
|
-
assert(
|
122
|
+
assert(isArrayOfStrings(lLines), `lLines is not an array: ${OL(lLines)}`);
|
120
123
|
lNewLines = [];
|
121
124
|
for (i = 0, len1 = lLines.length; i < len1; i++) {
|
122
125
|
line = lLines[i];
|
package/src/coffee_utils.coffee
CHANGED
@@ -633,3 +633,23 @@ export setCharsAt = (str, pos, str2) ->
|
|
633
633
|
else
|
634
634
|
return str.substring(0, pos) + str2 + str.substring(pos + str2.length)
|
635
635
|
|
636
|
+
# ---------------------------------------------------------------------------
|
637
|
+
|
638
|
+
export getOptions = (hOptions, hDefault={}) ->
|
639
|
+
# --- If hOptions is a string, break into words and set each to true
|
640
|
+
|
641
|
+
if isString(hOptions)
|
642
|
+
h = {}
|
643
|
+
for word in words(hOptions)
|
644
|
+
h[word] = true
|
645
|
+
return h
|
646
|
+
else if isHash(hOptions)
|
647
|
+
return hOptions
|
648
|
+
else
|
649
|
+
return hDefault
|
650
|
+
|
651
|
+
# ---------------------------------------------------------------------------
|
652
|
+
|
653
|
+
export timestamp = () ->
|
654
|
+
|
655
|
+
return new Date().toLocaleTimeString("en-US")
|
package/src/coffee_utils.js
CHANGED
@@ -712,3 +712,27 @@ export var setCharsAt = function(str, pos, str2) {
|
|
712
712
|
return str.substring(0, pos) + str2 + str.substring(pos + str2.length);
|
713
713
|
}
|
714
714
|
};
|
715
|
+
|
716
|
+
// ---------------------------------------------------------------------------
|
717
|
+
export var getOptions = function(hOptions, hDefault = {}) {
|
718
|
+
var h, i, len1, ref, word;
|
719
|
+
// --- If hOptions is a string, break into words and set each to true
|
720
|
+
if (isString(hOptions)) {
|
721
|
+
h = {};
|
722
|
+
ref = words(hOptions);
|
723
|
+
for (i = 0, len1 = ref.length; i < len1; i++) {
|
724
|
+
word = ref[i];
|
725
|
+
h[word] = true;
|
726
|
+
}
|
727
|
+
return h;
|
728
|
+
} else if (isHash(hOptions)) {
|
729
|
+
return hOptions;
|
730
|
+
} else {
|
731
|
+
return hDefault;
|
732
|
+
}
|
733
|
+
};
|
734
|
+
|
735
|
+
// ---------------------------------------------------------------------------
|
736
|
+
export var timestamp = function() {
|
737
|
+
return new Date().toLocaleTimeString("en-US");
|
738
|
+
};
|
package/src/indent_utils.coffee
CHANGED
@@ -68,7 +68,8 @@ export isUndented = (line) ->
|
|
68
68
|
return (lMatches[0].length == 0)
|
69
69
|
|
70
70
|
# ---------------------------------------------------------------------------
|
71
|
-
# indented - add indentation to each string in a block
|
71
|
+
# indented - add indentation to each string in a block or array
|
72
|
+
# - always returns a string
|
72
73
|
|
73
74
|
export indented = (input, level=1, oneIndent="\t") ->
|
74
75
|
|
package/src/indent_utils.js
CHANGED
@@ -81,7 +81,8 @@ export var isUndented = function(line) {
|
|
81
81
|
};
|
82
82
|
|
83
83
|
// ---------------------------------------------------------------------------
|
84
|
-
// indented - add indentation to each string in a block
|
84
|
+
// indented - add indentation to each string in a block or array
|
85
|
+
// - always returns a string
|
85
86
|
export var indented = function(input, level = 1, oneIndent = "\t") {
|
86
87
|
var lInputLines, lLines, line, toAdd;
|
87
88
|
assert(level >= 0, "indented(): negative level");
|