@jdeighan/coffee-utils 13.0.9 → 13.0.10
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 +15 -7
- package/src/indent.js +16 -8
package/package.json
CHANGED
package/src/indent.coffee
CHANGED
@@ -38,22 +38,30 @@ export indentation = (level, oneIndent="\t") ->
|
|
38
38
|
# indentLevel - determine indent level of a string
|
39
39
|
# it's OK if the string is ONLY indentation
|
40
40
|
|
41
|
-
export indentLevel = (line, oneIndent=
|
41
|
+
export indentLevel = (line, oneIndent=undef) ->
|
42
42
|
|
43
|
-
|
43
|
+
assert isString(line), "not a string"
|
44
44
|
|
45
|
-
# --- This will always match
|
45
|
+
# --- This will always match, and it's greedy
|
46
46
|
if lMatches = line.match(/^(\s*)/)
|
47
47
|
prefix = lMatches[1]
|
48
48
|
prefixLen = prefix.length
|
49
49
|
|
50
|
-
|
51
|
-
|
52
|
-
|
50
|
+
if (prefixLen == 0)
|
51
|
+
return 0
|
52
|
+
|
53
|
+
if defined(oneIndent)
|
54
|
+
len = oneIndent.length
|
55
|
+
else
|
56
|
+
oneIndent = "\t"
|
57
|
+
len = 1
|
58
|
+
|
59
|
+
if (prefixLen % len != 0)
|
60
|
+
croak "prefix #{OL(prefix)} not a mult of #{OL(oneIndent)}"
|
53
61
|
|
54
62
|
level = prefixLen / len
|
55
63
|
if (prefix != oneIndent.repeat(level))
|
56
|
-
|
64
|
+
croak "prefix #{OL(prefix)} not a mult of #{OL(oneIndent)}"
|
57
65
|
|
58
66
|
return level
|
59
67
|
|
package/src/indent.js
CHANGED
@@ -51,21 +51,29 @@ export var indentation = function(level, oneIndent = "\t") {
|
|
51
51
|
// ---------------------------------------------------------------------------
|
52
52
|
// indentLevel - determine indent level of a string
|
53
53
|
// it's OK if the string is ONLY indentation
|
54
|
-
export var indentLevel = function(line, oneIndent =
|
55
|
-
var lMatches, len, level, prefix, prefixLen
|
56
|
-
|
57
|
-
// --- This will always match
|
54
|
+
export var indentLevel = function(line, oneIndent = undef) {
|
55
|
+
var lMatches, len, level, prefix, prefixLen;
|
56
|
+
assert(isString(line), "not a string");
|
57
|
+
// --- This will always match, and it's greedy
|
58
58
|
if (lMatches = line.match(/^(\s*)/)) {
|
59
59
|
prefix = lMatches[1];
|
60
60
|
prefixLen = prefix.length;
|
61
61
|
}
|
62
|
-
|
63
|
-
|
64
|
-
|
62
|
+
if (prefixLen === 0) {
|
63
|
+
return 0;
|
64
|
+
}
|
65
|
+
if (defined(oneIndent)) {
|
66
|
+
len = oneIndent.length;
|
67
|
+
} else {
|
68
|
+
oneIndent = "\t";
|
69
|
+
len = 1;
|
70
|
+
}
|
71
|
+
if (prefixLen % len !== 0) {
|
72
|
+
croak(`prefix ${OL(prefix)} not a mult of ${OL(oneIndent)}`);
|
65
73
|
}
|
66
74
|
level = prefixLen / len;
|
67
75
|
if (prefix !== oneIndent.repeat(level)) {
|
68
|
-
|
76
|
+
croak(`prefix ${OL(prefix)} not a mult of ${OL(oneIndent)}`);
|
69
77
|
}
|
70
78
|
return level;
|
71
79
|
};
|