countLines
function countLines(text, stopAfter?): number;Defined in: packages/engine/src/utilities/Strings.ts:29
How many lines text has, without splitting it into an array.
split("\n").length answers the same question and allocates the whole
document to do it, which is the wrong shape for a caller whose next move may
be to refuse the document for being too large. Counting stops as soon as the
answer is “more than the caller cares about”.
Parameters
Section titled “Parameters”| Parameter | Type | Default value | Description |
|---|---|---|---|
text | string | undefined | The document. |
stopAfter | number | Number.MAX_SAFE_INTEGER | Stop counting once past this many lines. |
Returns
Section titled “Returns”number
The line count, or stopAfter + 1 for anything longer. A document
with no newline in it is one line, matching split.