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

Text overview

This module implements a styled text, i.e. an array of UniStyled where a UniStyled is a string formatted in a given style.


Table of contents


Constructors

fromString

Builds a Text from a string withoout 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>

uniStyledTexts

Returns the uniStyledTexts property of self

Signature

export declare const uniStyledTexts: MTypes.OneArgFunction<Type, readonly UniStyled.Type[]>

Equivalences

equivalence

Equivalence

Signature

export declare const equivalence: Equivalence.Equivalence<Type>

haveSameText

Equivalence

Signature

export declare const haveSameText: Equivalence.Equivalence<Type>

Guards

has

Type guard

Signature

export declare const has: (u: unknown) => u is 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 (interface)

Interface that represents a Text

Signature

export interface Type extends Equal.Equal, MInspectable.Inspectable, Pipeable.Pipeable {
  /* The text as an array of UniStyled */
  readonly uniStyledTexts: ReadonlyArray<UniStyled.Type>

  /* @internal */
  readonly [_TypeId]: _TypeId
}

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

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

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: (startText: Type, endText: Type) => MTypes.OneArgFunction<Type>