@jdeighan/coffee-utils 8.0.7 → 8.0.8
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 +11 -5
- package/src/indent_utils.js +12 -6
package/package.json
CHANGED
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
|
// ---------------------------------------------------------------------------
|