@jdeighan/coffee-utils 10.0.17 → 11.0.0
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/indent_utils.coffee +10 -4
- package/src/indent_utils.js +15 -7
package/package.json
CHANGED
package/src/indent_utils.coffee
CHANGED
@@ -69,7 +69,7 @@ export isUndented = (line) ->
|
|
69
69
|
|
70
70
|
# ---------------------------------------------------------------------------
|
71
71
|
# indented - add indentation to each string in a block or array
|
72
|
-
# -
|
72
|
+
# - returns the same type as input, i.e. array or string
|
73
73
|
|
74
74
|
export indented = (input, level=1, oneIndent="\t") ->
|
75
75
|
|
@@ -78,14 +78,20 @@ export indented = (input, level=1, oneIndent="\t") ->
|
|
78
78
|
return input
|
79
79
|
|
80
80
|
toAdd = indentation(level, oneIndent)
|
81
|
-
lInputLines = toArray(input)
|
82
81
|
|
83
|
-
|
82
|
+
# --- NOTE: toArray(input) just returns input if it's an array
|
83
|
+
# else it splits the string into an array of lines
|
84
|
+
lLines = for line in toArray(input)
|
84
85
|
if isEmpty(line)
|
85
86
|
""
|
86
87
|
else
|
87
88
|
"#{toAdd}#{line}"
|
88
|
-
|
89
|
+
if isArray(input)
|
90
|
+
return lLines
|
91
|
+
else if isString(input)
|
92
|
+
return toBlock(lLines)
|
93
|
+
else
|
94
|
+
croak "Invalid input; #{OL(input)}"
|
89
95
|
|
90
96
|
# ---------------------------------------------------------------------------
|
91
97
|
# undented - string with 1st line indentation removed for each line
|
package/src/indent_utils.js
CHANGED
@@ -82,20 +82,22 @@ export var isUndented = function(line) {
|
|
82
82
|
|
83
83
|
// ---------------------------------------------------------------------------
|
84
84
|
// indented - add indentation to each string in a block or array
|
85
|
-
// -
|
85
|
+
// - returns the same type as input, i.e. array or string
|
86
86
|
export var indented = function(input, level = 1, oneIndent = "\t") {
|
87
|
-
var
|
87
|
+
var lLines, line, toAdd;
|
88
88
|
assert(level >= 0, "indented(): negative level");
|
89
89
|
if (level === 0) {
|
90
90
|
return input;
|
91
91
|
}
|
92
92
|
toAdd = indentation(level, oneIndent);
|
93
|
-
|
93
|
+
// --- NOTE: toArray(input) just returns input if it's an array
|
94
|
+
// else it splits the string into an array of lines
|
94
95
|
lLines = (function() {
|
95
|
-
var i, len1, results;
|
96
|
+
var i, len1, ref, results;
|
97
|
+
ref = toArray(input);
|
96
98
|
results = [];
|
97
|
-
for (i = 0, len1 =
|
98
|
-
line =
|
99
|
+
for (i = 0, len1 = ref.length; i < len1; i++) {
|
100
|
+
line = ref[i];
|
99
101
|
if (isEmpty(line)) {
|
100
102
|
results.push("");
|
101
103
|
} else {
|
@@ -104,7 +106,13 @@ export var indented = function(input, level = 1, oneIndent = "\t") {
|
|
104
106
|
}
|
105
107
|
return results;
|
106
108
|
})();
|
107
|
-
|
109
|
+
if (isArray(input)) {
|
110
|
+
return lLines;
|
111
|
+
} else if (isString(input)) {
|
112
|
+
return toBlock(lLines);
|
113
|
+
} else {
|
114
|
+
return croak(`Invalid input; ${OL(input)}`);
|
115
|
+
}
|
108
116
|
};
|
109
117
|
|
110
118
|
// ---------------------------------------------------------------------------
|