@jdeighan/coffee-utils 8.0.6 → 8.0.9
Sign up to get free protection for your applications and to get access to all the features.
- package/package.json +3 -3
- package/src/Section.coffee +18 -12
- package/src/Section.js +17 -12
- package/src/SectionMap.coffee +2 -1
- package/src/SectionMap.js +2 -1
- package/src/indent_utils.coffee +11 -5
- package/src/indent_utils.js +12 -6
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@jdeighan/coffee-utils",
|
3
3
|
"type": "module",
|
4
|
-
"version": "8.0.
|
4
|
+
"version": "8.0.9",
|
5
5
|
"description": "A set of utility functions for CoffeeScript",
|
6
6
|
"main": "coffee_utils.js",
|
7
7
|
"exports": {
|
@@ -52,9 +52,9 @@
|
|
52
52
|
"js-yaml": "^4.1.0",
|
53
53
|
"n-readlines": "^1.0.1",
|
54
54
|
"readline-sync": "^1.4.10",
|
55
|
-
"svelte": "^3.
|
55
|
+
"svelte": "^3.49.0"
|
56
56
|
},
|
57
57
|
"devDependencies": {
|
58
|
-
"@jdeighan/unit-tester": "^2.0.
|
58
|
+
"@jdeighan/unit-tester": "^2.0.10"
|
59
59
|
}
|
60
60
|
}
|
package/src/Section.coffee
CHANGED
@@ -12,34 +12,34 @@ export class Section
|
|
12
12
|
|
13
13
|
constructor: (@name) ->
|
14
14
|
|
15
|
-
@
|
15
|
+
@lParts = []
|
16
16
|
|
17
17
|
# ..........................................................
|
18
18
|
|
19
19
|
length: () ->
|
20
20
|
|
21
|
-
return @
|
21
|
+
return @lParts.length
|
22
22
|
|
23
23
|
# ..........................................................
|
24
24
|
|
25
25
|
indent: (level=1) ->
|
26
26
|
|
27
|
-
lNewLines = for line in @
|
27
|
+
lNewLines = for line in @lParts
|
28
28
|
indented(line, level)
|
29
|
-
@
|
29
|
+
@lParts = lNewLines
|
30
30
|
return
|
31
31
|
|
32
32
|
# ..........................................................
|
33
33
|
|
34
34
|
isEmpty: () ->
|
35
35
|
|
36
|
-
return (@
|
36
|
+
return (@lParts.length == 0)
|
37
37
|
|
38
38
|
# ..........................................................
|
39
39
|
|
40
40
|
nonEmpty: () ->
|
41
41
|
|
42
|
-
return (@
|
42
|
+
return (@lParts.length > 0)
|
43
43
|
|
44
44
|
# ..........................................................
|
45
45
|
|
@@ -47,9 +47,9 @@ export class Section
|
|
47
47
|
|
48
48
|
if isArray(data)
|
49
49
|
for line in data
|
50
|
-
@
|
50
|
+
@lParts.push line
|
51
51
|
else
|
52
|
-
@
|
52
|
+
@lParts.push data
|
53
53
|
return
|
54
54
|
|
55
55
|
# ..........................................................
|
@@ -57,16 +57,22 @@ export class Section
|
|
57
57
|
prepend: (data) ->
|
58
58
|
|
59
59
|
if isArray(data)
|
60
|
-
@
|
60
|
+
@lParts = [data..., @lParts...]
|
61
61
|
else
|
62
|
-
@
|
62
|
+
@lParts = [data, @lParts...]
|
63
63
|
return
|
64
64
|
|
65
65
|
# ..........................................................
|
66
66
|
|
67
|
+
getParts: () ->
|
68
|
+
|
69
|
+
return @lParts
|
70
|
+
|
71
|
+
# ..........................................................
|
72
|
+
|
67
73
|
getBlock: () ->
|
68
74
|
|
69
|
-
if (@
|
75
|
+
if (@lParts.length == 0)
|
70
76
|
return undef
|
71
77
|
else
|
72
|
-
return arrayToBlock(@
|
78
|
+
return arrayToBlock(@lParts)
|
package/src/Section.js
CHANGED
@@ -21,12 +21,12 @@ import {
|
|
21
21
|
export var Section = class Section {
|
22
22
|
constructor(name) {
|
23
23
|
this.name = name;
|
24
|
-
this.
|
24
|
+
this.lParts = [];
|
25
25
|
}
|
26
26
|
|
27
27
|
// ..........................................................
|
28
28
|
length() {
|
29
|
-
return this.
|
29
|
+
return this.lParts.length;
|
30
30
|
}
|
31
31
|
|
32
32
|
// ..........................................................
|
@@ -34,7 +34,7 @@ export var Section = class Section {
|
|
34
34
|
var lNewLines, line;
|
35
35
|
lNewLines = (function() {
|
36
36
|
var i, len, ref, results;
|
37
|
-
ref = this.
|
37
|
+
ref = this.lParts;
|
38
38
|
results = [];
|
39
39
|
for (i = 0, len = ref.length; i < len; i++) {
|
40
40
|
line = ref[i];
|
@@ -42,17 +42,17 @@ export var Section = class Section {
|
|
42
42
|
}
|
43
43
|
return results;
|
44
44
|
}).call(this);
|
45
|
-
this.
|
45
|
+
this.lParts = lNewLines;
|
46
46
|
}
|
47
47
|
|
48
48
|
// ..........................................................
|
49
49
|
isEmpty() {
|
50
|
-
return this.
|
50
|
+
return this.lParts.length === 0;
|
51
51
|
}
|
52
52
|
|
53
53
|
// ..........................................................
|
54
54
|
nonEmpty() {
|
55
|
-
return this.
|
55
|
+
return this.lParts.length > 0;
|
56
56
|
}
|
57
57
|
|
58
58
|
// ..........................................................
|
@@ -61,28 +61,33 @@ export var Section = class Section {
|
|
61
61
|
if (isArray(data)) {
|
62
62
|
for (i = 0, len = data.length; i < len; i++) {
|
63
63
|
line = data[i];
|
64
|
-
this.
|
64
|
+
this.lParts.push(line);
|
65
65
|
}
|
66
66
|
} else {
|
67
|
-
this.
|
67
|
+
this.lParts.push(data);
|
68
68
|
}
|
69
69
|
}
|
70
70
|
|
71
71
|
// ..........................................................
|
72
72
|
prepend(data) {
|
73
73
|
if (isArray(data)) {
|
74
|
-
this.
|
74
|
+
this.lParts = [...data, ...this.lParts];
|
75
75
|
} else {
|
76
|
-
this.
|
76
|
+
this.lParts = [data, ...this.lParts];
|
77
77
|
}
|
78
78
|
}
|
79
79
|
|
80
|
+
// ..........................................................
|
81
|
+
getParts() {
|
82
|
+
return this.lParts;
|
83
|
+
}
|
84
|
+
|
80
85
|
// ..........................................................
|
81
86
|
getBlock() {
|
82
|
-
if (this.
|
87
|
+
if (this.lParts.length === 0) {
|
83
88
|
return undef;
|
84
89
|
} else {
|
85
|
-
return arrayToBlock(this.
|
90
|
+
return arrayToBlock(this.lParts);
|
86
91
|
}
|
87
92
|
}
|
88
93
|
|
package/src/SectionMap.coffee
CHANGED
@@ -120,7 +120,8 @@ export class SectionMap
|
|
120
120
|
return
|
121
121
|
|
122
122
|
# ..........................................................
|
123
|
-
# --- procFunc should be (name,
|
123
|
+
# --- procFunc should be (name, block) ->
|
124
|
+
# return processed block
|
124
125
|
|
125
126
|
getBlock: (procFunc=undef, lTree=undef) ->
|
126
127
|
|
package/src/SectionMap.js
CHANGED
@@ -147,7 +147,8 @@ export var SectionMap = class SectionMap {
|
|
147
147
|
}
|
148
148
|
|
149
149
|
// ..........................................................
|
150
|
-
// --- procFunc should be (name,
|
150
|
+
// --- procFunc should be (name, block) ->
|
151
|
+
// return processed block
|
151
152
|
getBlock(procFunc = undef, lTree = undef) {
|
152
153
|
var j, lParts, len, part, result, text;
|
153
154
|
debug("enter getBlock()");
|
package/src/indent_utils.coffee
CHANGED
@@ -6,6 +6,15 @@ import {
|
|
6
6
|
} from '@jdeighan/coffee-utils'
|
7
7
|
import {arrayToBlock, blockToArray} from '@jdeighan/coffee-utils/block'
|
8
8
|
|
9
|
+
# ---------------------------------------------------------------------------
|
10
|
+
|
11
|
+
export splitPrefix = (line) ->
|
12
|
+
|
13
|
+
assert isString(line), "non-string #{OL(line)}"
|
14
|
+
line = rtrim(line)
|
15
|
+
lMatches = line.match(/^(\s*)(.*)$/)
|
16
|
+
return [lMatches[1], lMatches[2]]
|
17
|
+
|
9
18
|
# ---------------------------------------------------------------------------
|
10
19
|
# NOTE: Currently, only TAB indentation is supported
|
11
20
|
# ---------------------------------------------------------------------------
|
@@ -13,11 +22,8 @@ import {arrayToBlock, blockToArray} from '@jdeighan/coffee-utils/block'
|
|
13
22
|
|
14
23
|
export splitLine = (line) ->
|
15
24
|
|
16
|
-
|
17
|
-
|
18
|
-
line = rtrim(line)
|
19
|
-
lMatches = line.match(/^(\s*)(.*)$/)
|
20
|
-
return [lMatches[1].length, lMatches[2]]
|
25
|
+
[prefix, str] = splitPrefix(line)
|
26
|
+
return [indentLevel(prefix), str]
|
21
27
|
|
22
28
|
# ---------------------------------------------------------------------------
|
23
29
|
# indentation - return appropriate indentation string for given level
|
package/src/indent_utils.js
CHANGED
@@ -19,17 +19,23 @@ import {
|
|
19
19
|
blockToArray
|
20
20
|
} from '@jdeighan/coffee-utils/block';
|
21
21
|
|
22
|
+
// ---------------------------------------------------------------------------
|
23
|
+
export var splitPrefix = function(line) {
|
24
|
+
var lMatches;
|
25
|
+
assert(isString(line), `non-string ${OL(line)}`);
|
26
|
+
line = rtrim(line);
|
27
|
+
lMatches = line.match(/^(\s*)(.*)$/);
|
28
|
+
return [lMatches[1], lMatches[2]];
|
29
|
+
};
|
30
|
+
|
22
31
|
// ---------------------------------------------------------------------------
|
23
32
|
// NOTE: Currently, only TAB indentation is supported
|
24
33
|
// ---------------------------------------------------------------------------
|
25
34
|
// splitLine - separate a line into [level, line]
|
26
35
|
export var splitLine = function(line) {
|
27
|
-
var
|
28
|
-
|
29
|
-
|
30
|
-
line = rtrim(line);
|
31
|
-
lMatches = line.match(/^(\s*)(.*)$/);
|
32
|
-
return [lMatches[1].length, lMatches[2]];
|
36
|
+
var prefix, str;
|
37
|
+
[prefix, str] = splitPrefix(line);
|
38
|
+
return [indentLevel(prefix), str];
|
33
39
|
};
|
34
40
|
|
35
41
|
// ---------------------------------------------------------------------------
|