Skip to main content Link Search Menu Expand Document (external link)

Text.ts overview

This module implements styled text, supporting nested styles and efficient ANSI rendering


Exports Grouped by Category


Constructors

fromString

Builds a Text from a string without applying any style

Signature

declare const fromString: MTypes.OneArgFunction<string, Type>

Source

fromStyleAndElems

Builds a Text by applying a StyleCharacteristics to some strings and other Text’s

Signature

declare const fromStyleAndElems: (
  style: ASStyleCharacteristics.Type
) => (...elems: ReadonlyArray<string | Type>) => Type

Source

Destructors

toAnsiString

Returns the ANSI string corresponding to self

Signature

declare const toAnsiString: MTypes.OneArgFunction<Type, string>

Source

toLength

Returns the length of self without the length of the styling

Signature

declare const toLength: MTypes.OneArgFunction<Type, number>

Source

toUnstyledString

Returns the string corresponding to self without any styling

Signature

declare const toUnstyledString: MTypes.OneArgFunction<Type, string>

Source

Equivalences

equivalence

Equivalence

Signature

declare const equivalence: Equivalence.Equivalence<Type>

Source

haveSameText

Equivalence that compares only the text content, ignoring styles

Signature

declare const haveSameText: Equivalence.Equivalence<Type>

Source

Getters

uniStyledTexts

Returns the uniStyledTexts property of self

Signature

declare const uniStyledTexts: MTypes.OneArgFunction<Type, ReadonlyArray<ASUnistyledText.Type>>

Source

Instances

empty

An empty Text

Signature

declare const empty: Type

Source

lineBreak

A Text instance that represents a linebreak

Signature

declare const lineBreak: Type

Source

Models

Type (class)

Text Type

Signature

declare class Type {
  private constructor({ uniStyledTexts }: MTypes.Data<Type>)
}

Source

make (static method)

Static constructor

Signature

declare const make: (params: MTypes.Data<Type>) => Type

Source

[MData.idSymbol] (method)

Returns the id of this

Signature

declare const [MData.idSymbol]: () => string | (() => string)

Source

[Hash.symbol] (method)

Calculates the hash value of this

Signature

declare const [Hash.symbol]: () => number

Source

[MEquivalenceBasedEqualityData.isEquivalentToSymbol] (method)

Function that implements the equivalence of this and that

Signature

declare const [MEquivalenceBasedEqualityData.isEquivalentToSymbol]: (this: this, that: this) => boolean

Source

[MEquivalenceBasedEqualityData.hasSameTypeMarkerAsSymbol] (method)

Predicate that returns true if that has the same type marker as this

Signature

declare const [MEquivalenceBasedEqualityData.hasSameTypeMarkerAsSymbol]: (that: unknown) => boolean

Source

uniStyledTexts (property)

The text as an array of UniStyled

Signature

readonly uniStyledTexts: ReadonlyArray<ASUnistyledText.Type>

Source

Module markers

moduleTag

Module tag

Signature

declare const moduleTag: "@parischap/ansi-styles/Text/"

Source

Predicates

isEmpty

Predicate that returns true if self is empty

Signature

declare const isEmpty: Predicate.Predicate<Type>

Source

isNotEmpty

Predicate that returns true if self is not empty

Signature

declare const isNotEmpty: Predicate.Predicate<Type>

Source

Utils

append

Builds a new Text by appending that to self

Signature

declare const append: (that: Type) => (self: Type) => Type

Source

appendIfNotEmpty

Appends that to self if self is not empty. Returns self otherwise.

Signature

declare const appendIfNotEmpty: (that: Type) => MTypes.OneArgFunction<Type>

Source

concat

Builds a new Text by concatenating all passed Texts or strings

Signature

declare const concat: (...elems: ReadonlyArray<string | Type>) => Type

Source

join

Builds a new Text by joining all passed Texts and adding self as separator in between

Signature

declare const join: (self: Type) => (arr: ReadonlyArray<Type>) => Type

Source

prepend

Builds a new Text by prepending that to self

Signature

declare const prepend: (that: Type) => (self: Type) => Type

Source

prependIfNotEmpty

Prepends that to self if self is not empty. Returns self otherwise.

Signature

declare const prependIfNotEmpty: (that: Type) => MTypes.OneArgFunction<Type>

Source

removeEmptyAndJoin

Removes empty Text values from self and joins the remaining Text values using sep.

Signature

declare const removeEmptyAndJoin: (sep: Type) => MTypes.OneArgFunction<Iterable<Type>, Type>

Source

repeat

Builds a new Text by repeating n times the passed Text. n must be a strictly positive integer.

Signature

declare const repeat: (n: number) => (self: Type) => Type

Source

surround

Builds a new Text by prepending startText and appending ‘endText’ to self

Signature

declare const surround: (prefix: Type, suffix: Type) => MTypes.OneArgFunction<Type>

Source

surroundIfNotEmpty

Surrounds self with prefix and suffix if self is not empty. Returns self otherwise.

Signature

declare const surroundIfNotEmpty: (prefix: Type, suffix: Type) => MTypes.OneArgFunction<Type>

Source