Skip to content

This site describes solve-engine as it is on main: 2.43.0, which npm does not have yet. npm installs 2.40.0, so a page may show an answer that version does not give yet.

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.
stopAfternumberNumber.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.