UNPKG

@clickup/pg-microsharding

Version:
25 lines 961 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.lastLines = lastLines; /** * Returns the last count lines of out, each truncated to maxLineLength * characters, with an ellipsis if the line is truncated. Performance is almost * independent on out size, given that count is constant. */ function lastLines(out, count, maxLineLength) { const lines = []; let posNewline1 = out.lastIndexOf("\n"); let posNewline2 = out.length; while (posNewline2 >= 0 && lines.length < count) { const line = out.substring(posNewline1 + 1, posNewline2).trimEnd(); if (line.length > 0) { lines.unshift(line.length <= maxLineLength ? line : line.substring(0, maxLineLength - 1) + "…"); } posNewline2 = posNewline1; posNewline1 = out.lastIndexOf("\n", posNewline2 - 1); } return lines.join("\n"); } //# sourceMappingURL=lastLines.js.map