@jdeighan/coffee-utils 13.0.10 → 13.0.11
Sign up to get free protection for your applications and to get access to all the features.
- package/package.json +1 -1
- package/src/indent.coffee +12 -2
- package/src/indent.js +13 -2
package/package.json
CHANGED
package/src/indent.coffee
CHANGED
@@ -9,18 +9,28 @@ import {toArray, toBlock} from '@jdeighan/coffee-utils/block'
|
|
9
9
|
|
10
10
|
# ---------------------------------------------------------------------------
|
11
11
|
|
12
|
+
export getOneIndent = (str) ->
|
13
|
+
|
14
|
+
if (lMatches = str.match(/^\t+(?:\S|$)/))
|
15
|
+
return "\t"
|
16
|
+
else if (lMatches = str.match(/^(\x20+)(?:\S|$)/)) # space char
|
17
|
+
return lMatches[1]
|
18
|
+
assert notdefined(str.match(/^\s/)), "Mixed indentation types"
|
19
|
+
return undef
|
20
|
+
|
21
|
+
# ---------------------------------------------------------------------------
|
22
|
+
|
12
23
|
export splitPrefix = (line) ->
|
13
24
|
|
14
25
|
assert isString(line), "non-string #{OL(line)}"
|
15
26
|
line = rtrim(line)
|
16
27
|
lMatches = line.match(/^(\s*)(.*)$/)
|
17
|
-
assert defined(lMatches), "Failed to match: #{OL(line)}"
|
18
28
|
return [lMatches[1], lMatches[2]]
|
19
29
|
|
20
30
|
# ---------------------------------------------------------------------------
|
21
31
|
# splitLine - separate a line into [level, line]
|
22
32
|
|
23
|
-
export splitLine = (line, oneIndent=
|
33
|
+
export splitLine = (line, oneIndent=undef) ->
|
24
34
|
|
25
35
|
[prefix, str] = splitPrefix(line)
|
26
36
|
return [indentLevel(prefix, oneIndent), str]
|
package/src/indent.js
CHANGED
@@ -22,19 +22,30 @@ import {
|
|
22
22
|
toBlock
|
23
23
|
} from '@jdeighan/coffee-utils/block';
|
24
24
|
|
25
|
+
// ---------------------------------------------------------------------------
|
26
|
+
export var getOneIndent = function(str) {
|
27
|
+
var lMatches;
|
28
|
+
if ((lMatches = str.match(/^\t+(?:\S|$)/))) {
|
29
|
+
return "\t";
|
30
|
+
} else if ((lMatches = str.match(/^(\x20+)(?:\S|$)/))) { // space char
|
31
|
+
return lMatches[1];
|
32
|
+
}
|
33
|
+
assert(notdefined(str.match(/^\s/)), "Mixed indentation types");
|
34
|
+
return undef;
|
35
|
+
};
|
36
|
+
|
25
37
|
// ---------------------------------------------------------------------------
|
26
38
|
export var splitPrefix = function(line) {
|
27
39
|
var lMatches;
|
28
40
|
assert(isString(line), `non-string ${OL(line)}`);
|
29
41
|
line = rtrim(line);
|
30
42
|
lMatches = line.match(/^(\s*)(.*)$/);
|
31
|
-
assert(defined(lMatches), `Failed to match: ${OL(line)}`);
|
32
43
|
return [lMatches[1], lMatches[2]];
|
33
44
|
};
|
34
45
|
|
35
46
|
// ---------------------------------------------------------------------------
|
36
47
|
// splitLine - separate a line into [level, line]
|
37
|
-
export var splitLine = function(line, oneIndent =
|
48
|
+
export var splitLine = function(line, oneIndent = undef) {
|
38
49
|
var prefix, str;
|
39
50
|
[prefix, str] = splitPrefix(line);
|
40
51
|
return [indentLevel(prefix, oneIndent), str];
|