aboutsummaryrefslogtreecommitdiff
path: root/lib/utils.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/utils.js')
-rw-r--r--lib/utils.js16
1 files changed, 16 insertions, 0 deletions
diff --git a/lib/utils.js b/lib/utils.js
index 8af638d3c..585c4fced 100644
--- a/lib/utils.js
+++ b/lib/utils.js
@@ -29,6 +29,7 @@ const tabsRe = /\t/g;
const lineRe = /\r?\n/;
function splitLines(text) {
+ if (!text) return [];
const result = text.split(lineRe);
if (result.length > 0 && result[result.length - 1] === '')
return result.slice(0, result.length - 1);
@@ -175,3 +176,18 @@ exports.glGetMainContents = function glGetMainContents(content) {
});
return contents;
};
+
+function trimLine(line) {
+ if (!line.trim().length) {
+ return "";
+ }
+ const splat = line.split(/\s+/);
+ if (splat[0] === "") {
+ // An indented line: preserve a two-space indent (max)
+ const intent = line[1] !== " " ? " " : " ";
+ return intent + splat.slice(1).join(" ");
+ }
+ return splat.join(" ");
+}
+
+exports.trimLine = trimLine;