Text overview
This module implements styled text, supporting nested styles and efficient ANSI rendering
Table of contents
Constructors
fromString
Builds a Text from a string without applying any style
Signature
export declare const fromString: MTypes.OneArgFunction<string, Type>
fromStyleAndElems
Builds a Text by applying a StyleCharacteristics to some strings and other Text’s
Signature
export declare const fromStyleAndElems: (
style: ASStyleCharacteristics.Type
) => (...elems: ReadonlyArray<string | Type>) => Type
Destructors
toAnsiString
Returns the ANSI string corresponding to self
Signature
export declare const toAnsiString: MTypes.OneArgFunction<Type, string>
toLength
Returns the length of self without the length of the styling
Signature
export declare const toLength: MTypes.OneArgFunction<Type, number>
toUnstyledString
Returns the string corresponding to self without any styling
Signature
export declare const toUnstyledString: MTypes.OneArgFunction<Type, string>
Equivalences
equivalence
Equivalence
Signature
export declare const equivalence: Equivalence.Equivalence<Type>
haveSameText
Equivalence that compares only the text content, ignoring styles
Signature
export declare const haveSameText: Equivalence.Equivalence<Type>
Getters
uniStyledTexts
Returns the uniStyledTexts property of self
Signature
export declare const uniStyledTexts: MTypes.OneArgFunction<Type, readonly ASUnistyledText.Type[]>
Instances
empty
An empty Text
Signature
export declare const empty: Type
lineBreak
A Text instance that represents a linebreak
Signature
export declare const lineBreak: Type
Models
Type (class)
Text Type
Signature
export declare class Type {
private constructor({ uniStyledTexts }: MTypes.Data<Type>)
}
make (static method)
Static constructor
Signature
static make(params: MTypes.Data<Type>): Type
[MData.idSymbol] (method)
Returns the id of this
Signature
[MData.idSymbol](): string | (() => string)
[Hash.symbol] (method)
Calculates the hash value of this
Signature
[Hash.symbol](): number
[MEquivalenceBasedEqualityData.isEquivalentToSymbol] (method)
Function that implements the equivalence of this and that
Signature
[MEquivalenceBasedEqualityData.isEquivalentToSymbol](this: this, that: this): boolean
[MEquivalenceBasedEqualityData.hasSameTypeMarkerAsSymbol] (method)
Predicate that returns true if that has the same type marker as this
Signature
[MEquivalenceBasedEqualityData.hasSameTypeMarkerAsSymbol](that: unknown): boolean
uniStyledTexts (property)
The text as an array of UniStyled
Signature
readonly uniStyledTexts: readonly ASUnistyledText.Type[]
Module markers
moduleTag
Module tag
Signature
export declare const moduleTag: "@parischap/ansi-styles/Text/"
Predicates
isEmpty
Predicate that returns true if self is empty
Signature
export declare const isEmpty: Predicate.Predicate<Type>
isNotEmpty
Predicate that returns true if self is not empty
Signature
export declare const isNotEmpty: Predicate.Predicate<Type>
Utils
append
Builds a new Text by appending that to self
Signature
export declare const append: (that: Type) => (self: Type) => Type
appendIfNotEmpty
Appends that to self if self is not empty. Returns self otherwise.
Signature
export declare const appendIfNotEmpty: (that: Type) => MTypes.OneArgFunction<Type>
concat
Builds a new Text by concatenating all passed Texts or strings
Signature
export declare const concat: (...elems: ReadonlyArray<string | Type>) => Type
join
Builds a new Text by joining all passed Texts and adding self as separator in between
Signature
export declare const join: (self: Type) => (arr: ReadonlyArray<Type>) => Type
prepend
Builds a new Text by prepending that to self
Signature
export declare const prepend: (that: Type) => (self: Type) => Type
prependIfNotEmpty
Prepends that to self if self is not empty. Returns self otherwise.
Signature
export declare const prependIfNotEmpty: (that: Type) => MTypes.OneArgFunction<Type>
removeEmptyAndJoin
Removes empty Text values from self and joins the remaining Text values using sep.
Signature
export declare const removeEmptyAndJoin: (sep: Type) => MTypes.OneArgFunction<Iterable<Type>, Type>
repeat
Builds a new Text by repeating n times the passed Text. n must be a strictly positive integer.
Signature
export declare const repeat: (n: number) => (self: Type) => Type
surround
Builds a new Text by prepending startText and appending ‘endText’ to self
Signature
export declare const surround: (prefix: Type, suffix: Type) => MTypes.OneArgFunction<Type>
surroundIfNotEmpty
Surrounds self with prefix and suffix if self is not empty. Returns self otherwise.
Signature
export declare const surroundIfNotEmpty: (prefix: Type, suffix: Type) => MTypes.OneArgFunction<Type>