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

StringifiedValue overview

This module implements a type that represents the output of the stringification process of a value. It is a non-empty array of ASText’s (see @parischap/ansi-styles), where each element represents one line of the stringified output. At least one line is always present, though that line may be empty.


Table of contents


Constructors

concat

Returns a new PPStringifiedValue formed by appending all lines of that after all lines of self

Signature

export declare const concat: (that: ReadonlyArray<ASText.Type>) => (self: Type) => Type

fromFlattenedStringifiedProperties

Builds a PPStringifiedValue from a PPStringifiedProperties by concatenating all lines of all inner PPStringifiedValue’s into a flat array of lines. Returns the empty instance when the input array is empty.

Signature

export declare const fromFlattenedStringifiedProperties: MTypes.OneArgFunction<
  PPStringifiedProperties.Type,
  [ASText.Type, ...ASText.Type[]]
>

fromJoinedStringifiedProperties

Builds a PPStringifiedValue from a PPStringifiedProperties by collapsing each inner PPStringifiedValue into a single line (joining its lines with empty text), then collecting those single lines. Returns the empty instance when the input array is empty.

Signature

export declare const fromJoinedStringifiedProperties: MTypes.OneArgFunction<
  PPStringifiedProperties.Type,
  [ASText.Type, ...ASText.Type[]]
>

fromText

Wraps a single ASText into a one-line PPStringifiedValue

Signature

export declare const fromText: MTypes.OneArgFunction<ASText.Type, [ASText.Type, ...ASText.Type[]]>

Destructors

firstLine

Returns the first line of self

Signature

export declare const firstLine: MTypes.OneArgFunction<[ASText.Type, ...ASText.Type[]], ASText.Type>

initLines

Returns all lines of self but the last

Signature

export declare const initLines: MTypes.OneArgFunction<[ASText.Type, ...ASText.Type[]], readonly ASText.Type[]>

lastLine

Returns the last line of self

Signature

export declare const lastLine: MTypes.OneArgFunction<[ASText.Type, ...ASText.Type[]], ASText.Type>

tailLines

Returns all lines of self but the first

Signature

export declare const tailLines: MTypes.OneArgFunction<[ASText.Type, ...ASText.Type[]], readonly ASText.Type[]>

toAnsiString

Returns the ANSI string corresponding to self

Signature

export declare const toAnsiString: (sep?: ASText.Type) => MTypes.OneArgFunction<Type, string>

toLength

Returns the length of self, i.e. the sum of the lengths of all the ASText instances constituting self

Signature

export declare const toLength: MTypes.OneArgFunction<[ASText.Type, ...ASText.Type[]], number>

toText

Collapses all lines of self into a single ASText by joining them with empty text

Signature

export declare const toText: MTypes.OneArgFunction<[ASText.Type, ...ASText.Type[]], ASText.Type>

toUnstyledStrings

Returns the strings corresponding to self without any styling

Signature

export declare const toUnstyledStrings: MTypes.OneArgFunction<[ASText.Type, ...ASText.Type[]], [string, ...string[]]>

Equivalences

equivalence

Equivalence for StringifiedValue’s.

Signature

export declare const equivalence: Equivalence.Equivalence<[ASText.Type, ...ASText.Type[]]>

Instances

empty

Empty StringifiedValue instance

Signature

export declare const empty: [ASText.Type, ...ASText.Type[]]

Models

Type (type alias)

Type that represents a PPStringifiedValue

Signature

export type Type = MTypes.OverOne<ASText.Type>

Predicates

isEmpty

Returns true if self is empty.

Signature

export declare const isEmpty: Predicate.Predicate<[ASText.Type, ...ASText.Type[]]>

isNotEmpty

Returns true if self is not empty.

Signature

export declare const isNotEmpty: Predicate.Predicate<[ASText.Type, ...ASText.Type[]]>

Utils

addLineAfter

Returns a copy of self with a new line at the end

Signature

export declare const addLineAfter: (line: ASText.Type) => MTypes.OneArgFunction<ReadonlyArray<ASText.Type>, Type>

addLineBefore

Returns a copy of self with a new line at the start

Signature

export declare const addLineBefore: (line: ASText.Type) => MTypes.OneArgFunction<ReadonlyArray<ASText.Type>, Type>

appendToLastLine

Returns a copy of self in which text has been appended to the last line

Signature

export declare const appendToLastLine: (text: ASText.Type) => MTypes.OneArgFunction<Type>

prependToAllLines

Returns a copy of self in which text has been prepended to each line

Signature

export declare const prependToAllLines: (text: ASText.Type) => MTypes.OneArgFunction<Type>

prependToFirstLine

Returns a copy of self in which text has been prepended to the first line

Signature

export declare const prependToFirstLine: (text: ASText.Type) => MTypes.OneArgFunction<Type>

prependToTailLines

Returns a copy of self in which text has been prepended to all lines but the first

Signature

export declare const prependToTailLines: (text: ASText.Type) => MTypes.OneArgFunction<Type>

toSingleLine

Returns a single-line version of self by collapsing all lines into one (equivalent to calling toText then fromText)

Signature

export declare const toSingleLine: MTypes.OneArgFunction<
  [ASText.Type, ...ASText.Type[]],
  [ASText.Type, ...ASText.Type[]]
>