function splitLines(text) {
    var hasTrailingNl = text.endsWith('\n');
    var result = text.split('\n').map(function (line) {
        return line + '\n';
    });
    if (hasTrailingNl) {
        result.pop();
    } else {
        result.push(result.pop().slice(0, -1));
    }
    return result;
    }
Split `text` into an array of lines, including the trailing newline character (where present)