Rush StackShopBlogEvents
Skip to main content

Home > @rushstack/node-core-library > Text

Text class

Operations for working with strings that contain text.

Signature:

export declare class Text 

Remarks

The utilities provided by this class are intended to be simple, small, and very broadly applicable.

Methods

Method

Modifiers

Description

convertTo(input, newlineKind)

static

Converts all newlines in the provided string to use the specified newline type.

convertToCrLf(input)

static

Converts all newlines in the provided string to use Windows-style CRLF end of line characters.

convertToLf(input)

static

Converts all newlines in the provided string to use POSIX-style LF end of line characters.

POSIX is a registered trademark of the Institute of Electrical and Electronic Engineers, Inc.

ensureTrailingNewline(s, newlineKind)

static

Returns the input string with a trailing \n character appended, if not already present.

escapeRegExp(literal)

static

Escapes a string so that it can be treated as a literal string when used in a regular expression.

getNewline(newlineKind)

static

Returns the newline character sequence for the specified NewlineKind.

padEnd(s, minimumLength, paddingCharacter)

static

Append characters to the end of a string to ensure the result has a minimum length.

padStart(s, minimumLength, paddingCharacter)

static

Append characters to the start of a string to ensure the result has a minimum length.

readLinesFromIterable(iterable, options)

static

Read lines from an iterable object that returns strings or buffers, and return a generator that produces the lines as strings. The lines will not include the newline characters.

readLinesFromIterableAsync(iterable, options)

static

Read lines from an iterable object that returns strings or buffers, and return a generator that produces the lines as strings. The lines will not include the newline characters.

replaceAll(input, searchValue, replaceValue)

static

Returns the same thing as targetString.replace(searchValue, replaceValue), except that all matches are replaced, rather than just the first match.

reverse(s)

static

Returns a new string that is the input string with the order of characters reversed.

splitByNewLines(s)

static

Splits the provided string by newlines. Note that leading and trailing newlines will produce leading or trailing empty string array entries.

splitByNewLines(s)

static

splitByNewLines(s)

static

truncateWithEllipsis(s, maximumLength)

static

If the string is longer than maximumLength characters, truncate it to that length using "..." to indicate the truncation.