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

ContextStyler.ts overview

This module implements a type that applies to a string or text a style that depends on a context object. Two constructors are provided:

  • makeConstant: creates a ContextStyler that always applies the same style regardless of the context. Useful when a function expects a ContextStyler but should ignore the context.
  • makePaletteBased: creates a ContextStyler that contains a Palette (an array of styles) and a function that transforms a context object into an index. The style that is applied is the one at position index (modulo the number of styles in the Palette).

Exports Grouped by Category


Constructors

makeConstant

Constructor of a constant ContextStyler that always applies the same style regardless of the context

Signature

declare const makeConstant: ({ style }: { readonly style: ASStyle.Type }) => Type<unknown>

Source

makePaletteBased

Constructor of a palette-based ContextStyler that selects a style from a palette based on a context object of type C. The indexFromContext function must return an integer index from a value of type C. Use a named function or function declaration for indexFromContext (don’t use an arrow function), otherwise the name of this ContextStyler will be meaningless (e.g. function depth(c) { return c. depth; }, not (c)=>c.depth ).

Signature

declare const makePaletteBased: <C>({
  palette,
  indexFromContext
}: {
  readonly palette: ASPalette.Type
  readonly indexFromContext: (c: C) => number
}) => Type<C>

Source

Getters

id

Gets the id of self

Signature

declare const id: MTypes.OneArgFunction<Any, string>

Source

style

Gets the style function of self

Signature

declare const style: <C>(self: Type<C>) => Type<C>["style"]

Source

Instances

black

Original black color instance

Signature

declare const black: Never

Source

blue

Original blue color instance

Signature

declare const blue: Never

Source

cyan

Original cyan color instance

Signature

declare const cyan: Never

Source

green

Original green color instance

Signature

declare const green: Never

Source

magenta

Original magenta color instance

Signature

declare const magenta: Never

Source

none

None ASContextStyler instance: does not apply any style

Signature

declare const none: Never

Source

red

Original red color instance

Signature

declare const red: Never

Source

white

Original white color instance

Signature

declare const white: Never

Source

yellow

Original yellow color instance

Signature

declare const yellow: Never

Source

Models

Any (interface)

Type of an ASContextStyler to which any ASContextStyler can be assigned

Signature

export interface Any extends Type<never> {}

Source

Never (interface)

Type of an ASContextStyler that can be assigned to any ASContextStyler (i.e an ASContextStyler that works with any context object)

Signature

export interface Never extends Type<unknown> {}

Source

Type (class)

Type that represents an ASContextStyler

Signature

declare class Type<C> {
  public constructor({ id, style }: MTypes.Data<Type<C>>)
}

Source

[MData.idSymbol] (method)

Returns the id of this

Signature

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

Source

id (property)

Id of this ContextStyler instance. Useful for equality and debugging

Signature

readonly id: string

Source

style (property)

Function that takes a context c and returns an ASStyle

Signature

readonly style: (c: C) => ASStyle.Type

Source

Module markers

moduleTag

Module tag

Signature

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

Source