@jdeighan/coffee-utils 9.0.1 → 9.0.4
Sign up to get free protection for your applications and to get access to all the features.
- package/package.json +2 -2
- package/src/Section.coffee +2 -2
- package/src/Section.js +2 -2
- package/src/SectionMap.coffee +14 -12
- package/src/SectionMap.js +15 -13
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@jdeighan/coffee-utils",
|
3
3
|
"type": "module",
|
4
|
-
"version": "9.0.
|
4
|
+
"version": "9.0.4",
|
5
5
|
"description": "A set of utility functions for CoffeeScript",
|
6
6
|
"main": "coffee_utils.js",
|
7
7
|
"exports": {
|
@@ -55,6 +55,6 @@
|
|
55
55
|
"svelte": "^3.49.0"
|
56
56
|
},
|
57
57
|
"devDependencies": {
|
58
|
-
"@jdeighan/unit-tester": "^2.0.
|
58
|
+
"@jdeighan/unit-tester": "^2.0.21"
|
59
59
|
}
|
60
60
|
}
|
package/src/Section.coffee
CHANGED
@@ -23,10 +23,10 @@ export class Section
|
|
23
23
|
|
24
24
|
# ..........................................................
|
25
25
|
|
26
|
-
indent: (level=1) ->
|
26
|
+
indent: (level=1, oneIndent="\t") ->
|
27
27
|
|
28
28
|
lNewLines = for line in @lParts
|
29
|
-
indented(line, level)
|
29
|
+
indented(line, level, oneIndent)
|
30
30
|
@lParts = lNewLines
|
31
31
|
return
|
32
32
|
|
package/src/Section.js
CHANGED
@@ -34,7 +34,7 @@ export var Section = class Section {
|
|
34
34
|
}
|
35
35
|
|
36
36
|
// ..........................................................
|
37
|
-
indent(level = 1) {
|
37
|
+
indent(level = 1, oneIndent = "\t") {
|
38
38
|
var lNewLines, line;
|
39
39
|
lNewLines = (function() {
|
40
40
|
var i, len, ref, results;
|
@@ -42,7 +42,7 @@ export var Section = class Section {
|
|
42
42
|
results = [];
|
43
43
|
for (i = 0, len = ref.length; i < len; i++) {
|
44
44
|
line = ref[i];
|
45
|
-
results.push(indented(line, level));
|
45
|
+
results.push(indented(line, level, oneIndent));
|
46
46
|
}
|
47
47
|
return results;
|
48
48
|
}).call(this);
|
package/src/SectionMap.coffee
CHANGED
@@ -121,10 +121,11 @@ export class SectionMap
|
|
121
121
|
return
|
122
122
|
|
123
123
|
# ..........................................................
|
124
|
-
# ---
|
125
|
-
#
|
124
|
+
# --- hProc should be <name> -> <function>
|
125
|
+
# <function> should be <block> -> <block>
|
126
|
+
# --- lTree allows you to get just a section
|
126
127
|
|
127
|
-
getBlock: (
|
128
|
+
getBlock: (hProc={}, lTree=undef) ->
|
128
129
|
|
129
130
|
debug "enter getBlock()"
|
130
131
|
if (lTree == undef)
|
@@ -135,22 +136,23 @@ export class SectionMap
|
|
135
136
|
lParts = []
|
136
137
|
for part in lTree
|
137
138
|
if isString(part)
|
138
|
-
|
139
|
-
if
|
140
|
-
|
139
|
+
block = @section(part).getBlock()
|
140
|
+
if defined(hProc[part])
|
141
|
+
# --- called even if block is empty
|
142
|
+
block = hProc[part](block)
|
141
143
|
else if isNonEmptyArray(part)
|
142
144
|
if isSectionName(part[0])
|
143
|
-
|
145
|
+
block = @getBlock(hProc, part)
|
144
146
|
else if isSetName(part[0])
|
145
|
-
|
146
|
-
if
|
147
|
-
|
147
|
+
block = @getBlock(hProc, part.slice(1))
|
148
|
+
if defined(hProc[part[0]])
|
149
|
+
block = hProc[part[0]](block)
|
148
150
|
else
|
149
151
|
croak "Bad part: #{OL(part)}"
|
150
152
|
else
|
151
153
|
croak "Bad part: #{OL(part)}"
|
152
|
-
if defined(
|
153
|
-
lParts.push
|
154
|
+
if defined(block)
|
155
|
+
lParts.push block
|
154
156
|
|
155
157
|
debug 'lParts', lParts
|
156
158
|
result = arrayToBlock(lParts)
|
package/src/SectionMap.js
CHANGED
@@ -151,10 +151,11 @@ export var SectionMap = class SectionMap {
|
|
151
151
|
}
|
152
152
|
|
153
153
|
// ..........................................................
|
154
|
-
// ---
|
155
|
-
//
|
156
|
-
|
157
|
-
|
154
|
+
// --- hProc should be <name> -> <function>
|
155
|
+
// <function> should be <block> -> <block>
|
156
|
+
// --- lTree allows you to get just a section
|
157
|
+
getBlock(hProc = {}, lTree = undef) {
|
158
|
+
var block, j, lParts, len, part, result;
|
158
159
|
debug("enter getBlock()");
|
159
160
|
if (lTree === undef) {
|
160
161
|
lTree = this.lSectionTree;
|
@@ -165,17 +166,18 @@ export var SectionMap = class SectionMap {
|
|
165
166
|
for (j = 0, len = lTree.length; j < len; j++) {
|
166
167
|
part = lTree[j];
|
167
168
|
if (isString(part)) {
|
168
|
-
|
169
|
-
if (
|
170
|
-
|
169
|
+
block = this.section(part).getBlock();
|
170
|
+
if (defined(hProc[part])) {
|
171
|
+
// --- called even if block is empty
|
172
|
+
block = hProc[part](block);
|
171
173
|
}
|
172
174
|
} else if (isNonEmptyArray(part)) {
|
173
175
|
if (isSectionName(part[0])) {
|
174
|
-
|
176
|
+
block = this.getBlock(hProc, part);
|
175
177
|
} else if (isSetName(part[0])) {
|
176
|
-
|
177
|
-
if (
|
178
|
-
|
178
|
+
block = this.getBlock(hProc, part.slice(1));
|
179
|
+
if (defined(hProc[part[0]])) {
|
180
|
+
block = hProc[part[0]](block);
|
179
181
|
}
|
180
182
|
} else {
|
181
183
|
croak(`Bad part: ${OL(part)}`);
|
@@ -183,8 +185,8 @@ export var SectionMap = class SectionMap {
|
|
183
185
|
} else {
|
184
186
|
croak(`Bad part: ${OL(part)}`);
|
185
187
|
}
|
186
|
-
if (defined(
|
187
|
-
lParts.push(
|
188
|
+
if (defined(block)) {
|
189
|
+
lParts.push(block);
|
188
190
|
}
|
189
191
|
}
|
190
192
|
debug('lParts', lParts);
|