antsibull-docs
Version:
TypeScript library for processing Ansible documentation markup
44 lines • 1.54 kB
JavaScript
;
/*
Simplified BSD License (see LICENSES/BSD-2-Clause.txt or https://opensource.org/licenses/BSD-2-Clause)
SPDX-FileCopyrightText: Ansible Project
SPDX-License-Identifier: BSD-2-Clause
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.splitLines = splitLines;
exports.startsWith = startsWith;
exports.endsWith = endsWith;
function splitLines(line) {
// The regex uses the line separators listed in https://docs.python.org/3/library/stdtypes.html#str.splitlines
/* eslint-disable-next-line no-control-regex */
const lines = line.split(/(?:\r\n|\n|\r|\v|\f|\x1c|\x1d|\x1e|\x85|\u2028|\u2029)/);
if (lines.length && lines[lines.length - 1] === '') {
lines.splice(lines.length - 1, 1);
}
return lines;
}
function startsWith(text, prefix, start = 0, end) {
const prefixLen = prefix.length;
const textLen = text.length;
if (start < 0 || start + prefixLen > textLen) {
return false;
}
end = end !== null && end !== void 0 ? end : textLen;
if (start + prefixLen > end) {
return false;
}
return text.startsWith(prefix, start);
}
function endsWith(text, prefix, start = 0, end) {
const prefixLen = prefix.length;
const textLen = text.length;
if (start < 0 || start + prefixLen > textLen) {
return false;
}
end = end !== null && end !== void 0 ? end : textLen;
if (start + prefixLen > end) {
return false;
}
return text.endsWith(prefix, end);
}
//# sourceMappingURL=util.js.map