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

NonPrimitiveFormatter overview

This module implements a type that takes care of the formatting of non-primitive values. From the stringified representation of the properties of a non-primitive value which it receives, it must return the stringified representation of the whole non-primitive value. It can take care of aspects like adding specific array/object marks, printing on a single or multiple lines, indentation when printing on multiple lines, …

With the make function, you can define your own instances if the provided ones don’t suit your needs.


Table of contents


Constructors

make

Constructor

Signature

export declare const make: ({ id, action }: { readonly id: string; readonly action: Action.Type }) => Type

splitOnConstituentNumberMaker

NonPrimitiveFormatter instance maker that will print non-primitive values on a single line if the actual number of their constituents (after filtering,…) is less than or equal to limit.

Signature

export declare const splitOnConstituentNumberMaker: (limit: number) => Type

splitOnLongestPropLengthMaker

Calls singleLine if the length of the longest property to print (excluding formatting characters and object marks) is less than or equal to limit. Calls tabify otherwise

Signature

export declare const splitOnLongestPropLengthMaker: (limit: number) => Type

splitOnTotalLengthMaker

Calls singleLine if the total length of the properties to print (excluding formatting characters) is less than or equal to limit. Calls tabify otherwise

Signature

export declare const splitOnTotalLengthMaker: (limit: number) => Type

Destructors

id

Returns the id property of self

Signature

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

Equivalences

equivalence

Equivalence

Signature

export declare const equivalence: Equivalence.Equivalence<Type>

Guards

has

Type guard

Signature

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

Instances

singleLine

NonPrimitiveFormatter instance that will always print non-primitive values on a single line

Signature

export declare const singleLine: Type

tabify

NonPrimitiveFormatter instance that will always print non-primitive values on multiple lines with a tab indentation

Signature

export declare const tabify: Type

treeify

NonPrimitiveFormatter instance that will always print non-primitive values in a tree-like fashion

Signature

export declare const treeify: Type

Models

Action (namespace)

Namespace of a NonPrimitiveFormatter used as an action

Type (interface)

Type of the action of a NonPrimitiveFormatter. The action takes as input a ValueBasedStylerConstructor (see ValueBasedStylerConstructor.ts), a MarkShowerConstructor (see MarkShowerConstructor.ts). Based on these parameters, it must return an Initialized Action.

Signature

export interface Type {
  (
    this: PPOption.NonPrimitive.Type,
    {
      valueBasedStylerConstructor,
      markShowerConstructor
    }: {
      readonly valueBasedStylerConstructor: PPValueBasedStylerConstructor.Type
      readonly markShowerConstructor: PPMarkShowerConstructor.Type
    }
  ): Initialized.Type
}

Initialized (namespace)

Namespace of an initialized NonPrimitiveFormatter used as an action

Type (interface)

Type of the action of a NonPrimitiveFormatter. The action takes as input the Value being currently printed (see Value.ts), a header to be displayed in front of the stringified properties (usually the id of the non primitive value and the number of displayed properties) and an array of the stringified properties (see StringifiedProperties.ts) of that value. Based on these parameters, it must return a stringified representation of the whole record.

Signature

export interface Type {
  ({
    value,
    header
  }: {
    readonly value: PPValue.NonPrimitive
    readonly header: ASText.Type
  }): (children: PPStringifiedProperties.Type) => PPStringifiedValue.Type
}

Type (interface)

Type that represents a NonPrimitiveFormatter.

Signature

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

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

moduleTag

Module tag

Signature

export declare const moduleTag: "@parischap/pretty-print/NonPrimitiveFormatter/"