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

ContextStyler overview

A ContextStyler is a type that allows you to format a string differently depending on the value of a context object.


Table of contents


Constructors

fromPalette

Constructor of a ContextStyler based on a Palette (see Palette.ts) that contains n styles and an indexFromContext function that is able to transform a Context object into an integer i. The style that will be used is the one in the Palette at position i % n, where % is the modulo function.

Signature

export declare const fromPalette: <C>({
  palette,
  indexFromContext
}: {
  readonly palette: ASPalette.Type
  readonly indexFromContext: IndexFromContext.Type<C>
}) => Type<C>

fromSingleStyle

Constructor of a ContextStyler based on a single style. This ContextStyler is optimized to take care of the fact that the context value is needless

Signature

export declare const fromSingleStyle: <C>(style: ASStyle.Type) => Type<C>

Destructors

id

Gets the id of self

Signature

export declare const id: MTypes.OneArgFunction<Type<never>, string>

Equivalences

equivalence

Equivalence

Signature

export declare const equivalence: Equivalence.Equivalence<Type<unknown>>

Guards

has

Type guard

Signature

export declare const has: (u: unknown) => u is Type<unknown>

Instances

none

None ContextStyler instance: does not apply any style, does not provide a defaultText

Signature

export declare const none: <C>() => Type<C>

Models

Action (namespace)

Namespace of a ContextStyler used as an action

Type (interface)

Type of the action

Signature

export interface Type<in C> extends DirectAction.Type<C> {
  readonly withContextLast: ReversedAction.Type<C>
}

DirectAction (namespace)

Namespace of a ContextStyler used as an action

Type (interface)

Type of the action

Signature

export interface Type<in C> extends MTypes.OneArgFunction<C, ASStyle.Action.Type> {}

IndexFromContext (namespace)

Namespace of a function that transforms a context into an index

Type (interface)

Type of an IndexFromContext

Signature

export interface Type<in C> {
  (c: C): number
}

ReversedAction (namespace)

Namespace of a ContextStyler used as an action with flipped parameters

Type (interface)

Type of the action

Signature

export interface Type<in C> extends MTypes.OneArgFunction<string, Initialized.Type<C>> {}

Initialized (namespace)

Namespace of an initialized ContextStyler used as an action with flipped parameters

Type (interface)

Type of the action

Signature

export interface Type<in C> extends MTypes.OneArgFunction<C, ASText.Type> {}

Type (interface)

Type that represents a ContextStyler

Signature

export interface Type<in C> extends Action.Type<C>, Equal.Equal, MInspectable.Inspectable, Pipeable.Pipeable {
  /** Id of this ContextStyler instance. Useful for equality and debugging */
  readonly id: string

  /** @internal */
  readonly [_TypeId]: {
    readonly _C: Types.Contravariant<C>
  }
}

moduleTag

Module tag

Signature

export declare const moduleTag: "@parischap/ansi-styles/ContextStyler/"

Original instances

black

Original black color instance

Signature

export declare const black: <C>() => Type<C>

blue

Original blue color instance

Signature

export declare const blue: <C>() => Type<C>

cyan

Original cyan color instance

Signature

export declare const cyan: <C>() => Type<C>

green

Original green color instance

Signature

export declare const green: <C>() => Type<C>

magenta

Original magenta color instance

Signature

export declare const magenta: <C>() => Type<C>

red

Original red color instance

Signature

export declare const red: <C>() => Type<C>

white

Original white color instance

Signature

export declare const white: <C>() => Type<C>

yellow

Original yellow color instance

Signature

export declare const yellow: <C>() => Type<C>