@jdeighan/coffee-utils 13.0.14 → 13.0.15
Sign up to get free protection for your applications and to get access to all the features.
- package/package.json +3 -3
- package/src/indent.coffee +11 -9
- package/src/indent.js +16 -20
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@jdeighan/coffee-utils",
|
3
3
|
"type": "module",
|
4
|
-
"version": "13.0.
|
4
|
+
"version": "13.0.15",
|
5
5
|
"description": "A set of utility functions for CoffeeScript",
|
6
6
|
"main": "coffee_utils.js",
|
7
7
|
"exports": {
|
@@ -50,13 +50,13 @@
|
|
50
50
|
},
|
51
51
|
"homepage": "https://github.com/johndeighan/coffee-utils#readme",
|
52
52
|
"dependencies": {
|
53
|
-
"@jdeighan/base-utils": "^2.0.
|
53
|
+
"@jdeighan/base-utils": "^2.0.10",
|
54
54
|
"cross-env": "^7.0.3",
|
55
55
|
"n-readlines": "^1.0.1",
|
56
56
|
"readline-sync": "^1.4.10",
|
57
57
|
"svelte": "^3.55.0"
|
58
58
|
},
|
59
59
|
"devDependencies": {
|
60
|
-
"@jdeighan/unit-tester": "^3.0.
|
60
|
+
"@jdeighan/unit-tester": "^3.0.10"
|
61
61
|
}
|
62
62
|
}
|
package/src/indent.coffee
CHANGED
@@ -90,32 +90,34 @@ export isUndented = (line) ->
|
|
90
90
|
|
91
91
|
export indented = (input, level=1, oneIndent="\t") ->
|
92
92
|
|
93
|
+
# --- level can be a string, in which case it is
|
94
|
+
# pre-pended to each line of input
|
93
95
|
if isString(level)
|
94
|
-
|
95
|
-
if (level == "")
|
96
|
+
if (level == '')
|
96
97
|
return input
|
97
98
|
toAdd = level
|
98
99
|
else if isInteger(level)
|
99
|
-
assert (level >= 0), "indented(): negative level"
|
100
100
|
if (level == 0)
|
101
101
|
return input
|
102
|
+
assert (level > 0), "Invalid level #{OL(level)}"
|
102
103
|
toAdd = indentation(level, oneIndent)
|
103
104
|
else
|
104
|
-
croak "level
|
105
|
+
croak "Invalid level #{OL(level)}"
|
105
106
|
|
106
107
|
# --- NOTE: toArray(input) just returns input if it's an array
|
107
108
|
# else it splits the string into an array of lines
|
108
|
-
lLines =
|
109
|
+
lLines = []
|
110
|
+
for line in toArray(input)
|
109
111
|
if isEmpty(line)
|
110
|
-
|
112
|
+
lLines.push ''
|
111
113
|
else
|
112
|
-
"#{toAdd}#{line}"
|
114
|
+
lLines.push "#{toAdd}#{line}"
|
115
|
+
|
113
116
|
if isArray(input)
|
114
117
|
return lLines
|
115
118
|
else if isString(input)
|
116
119
|
return toBlock(lLines)
|
117
|
-
|
118
|
-
croak "Invalid input; #{OL(input)}"
|
120
|
+
croak "Invalid input; #{OL(input)}"
|
119
121
|
|
120
122
|
# ---------------------------------------------------------------------------
|
121
123
|
# undented - string with 1st line indentation removed for each line
|
package/src/indent.js
CHANGED
@@ -102,45 +102,41 @@ export var isUndented = function(line) {
|
|
102
102
|
// indented - add indentation to each string in a block or array
|
103
103
|
// - returns the same type as input, i.e. array or string
|
104
104
|
export var indented = function(input, level = 1, oneIndent = "\t") {
|
105
|
-
var lLines, line, toAdd;
|
105
|
+
var i, lLines, len1, line, ref, toAdd;
|
106
|
+
// --- level can be a string, in which case it is
|
107
|
+
// pre-pended to each line of input
|
106
108
|
if (isString(level)) {
|
107
|
-
|
108
|
-
if (level === "") {
|
109
|
+
if (level === '') {
|
109
110
|
return input;
|
110
111
|
}
|
111
112
|
toAdd = level;
|
112
113
|
} else if (isInteger(level)) {
|
113
|
-
assert(level >= 0, "indented(): negative level");
|
114
114
|
if (level === 0) {
|
115
115
|
return input;
|
116
116
|
}
|
117
|
+
assert(level > 0, `Invalid level ${OL(level)}`);
|
117
118
|
toAdd = indentation(level, oneIndent);
|
118
119
|
} else {
|
119
|
-
croak(
|
120
|
+
croak(`Invalid level ${OL(level)}`);
|
120
121
|
}
|
121
122
|
// --- NOTE: toArray(input) just returns input if it's an array
|
122
123
|
// else it splits the string into an array of lines
|
123
|
-
lLines =
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
} else {
|
132
|
-
results.push(`${toAdd}${line}`);
|
133
|
-
}
|
124
|
+
lLines = [];
|
125
|
+
ref = toArray(input);
|
126
|
+
for (i = 0, len1 = ref.length; i < len1; i++) {
|
127
|
+
line = ref[i];
|
128
|
+
if (isEmpty(line)) {
|
129
|
+
lLines.push('');
|
130
|
+
} else {
|
131
|
+
lLines.push(`${toAdd}${line}`);
|
134
132
|
}
|
135
|
-
|
136
|
-
})();
|
133
|
+
}
|
137
134
|
if (isArray(input)) {
|
138
135
|
return lLines;
|
139
136
|
} else if (isString(input)) {
|
140
137
|
return toBlock(lLines);
|
141
|
-
} else {
|
142
|
-
return croak(`Invalid input; ${OL(input)}`);
|
143
138
|
}
|
139
|
+
return croak(`Invalid input; ${OL(input)}`);
|
144
140
|
};
|
145
141
|
|
146
142
|
// ---------------------------------------------------------------------------
|