Skip to content

This site describes solve-engine 2.44.0, the version npm installs.

countLines

function countLines(text, stopAfter?): number;

Defined in: packages/engine/src/utilities/Strings.ts:82

How many lines text has, without splitting it into an array.

splitLines(text).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”. A line ends where splitLines ends one.

ParameterTypeDefault valueDescription
textstringundefinedThe document.
stopAfter?numberNumber.MAX_SAFE_INTEGERStop counting once past this many lines.

number

The line count, or stopAfter + 1 for anything longer. A document with no line break in it is one line, matching split.