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

NonPrimitiveFormatter.ts overview

This module implements a type that assembles the stringified representation of a non-primitive value from the already-stringified representations of its properties. It is responsible for decisions such as: adding opening/closing marks (brackets, braces), choosing between single-line and multi-line output, and applying tree-style indentation.

Use the make function to define custom instances if the pre-built ones do not suit your needs.


Exports Grouped by Category


Constructors

make

Constructor

Signature

declare const make: (params: MTypes.Data<Type>) => Type

Source

singleLine

Constructor that returns a PPNonPrimitiveFormatter instance that always prints non-primitive values on a single line, surrounding properties with the opening/closing marks and separating them with inBetweenPropertySeparatorMark.

Signature

declare const singleLine: ({
  inBetweenPropertySeparatorMark,
  nonPrimitiveValueOpeningMark,
  nonPrimitiveValueClosingMark,
  singleLineSpacingMark
}: {
  readonly inBetweenPropertySeparatorMark: string
  readonly nonPrimitiveValueOpeningMark: string
  readonly nonPrimitiveValueClosingMark: string
  readonly singleLineSpacingMark: string
}) => Type

Source

splitOnConstituentNumber

Constructor that returns a PPNonPrimitiveFormatter instance that prints a non-primitive value on a single line if the number of its displayed properties (after filtering and deduping) is less than or equal to limit. Falls back to tabify otherwise.

Signature

declare const splitOnConstituentNumber: ({
  limit,
  inBetweenPropertySeparatorMark,
  nonPrimitiveValueOpeningMark,
  nonPrimitiveValueClosingMark,
  singleLineSpacingMark,
  tabMark
}: {
  readonly limit: number
  readonly inBetweenPropertySeparatorMark: string
  readonly nonPrimitiveValueOpeningMark: string
  readonly nonPrimitiveValueClosingMark: string
  readonly singleLineSpacingMark: string
  readonly tabMark: string
}) => Type

Source

splitOnLongestPropLength

Constructor that returns a PPNonPrimitiveFormatter instance that prints a non-primitive value on a single line if the length of the longest property to print (excluding formatting characters and object marks) is less than or equal to limit. Falls back to tabify otherwise.

Signature

declare const splitOnLongestPropLength: ({
  limit,
  inBetweenPropertySeparatorMark,
  nonPrimitiveValueOpeningMark,
  nonPrimitiveValueClosingMark,
  singleLineSpacingMark,
  tabMark
}: {
  readonly limit: number
  readonly inBetweenPropertySeparatorMark: string
  readonly nonPrimitiveValueOpeningMark: string
  readonly nonPrimitiveValueClosingMark: string
  readonly singleLineSpacingMark: string
  readonly tabMark: string
}) => Type

Source

splitOnTotalLength

Constructor that returns a PPNonPrimitiveFormatter instance that prints a non-primitive value on a single line if its total display length (including header, separators and delimiters) is less than or equal to limit. Falls back to tabify otherwise.

Signature

declare const splitOnTotalLength: ({
  limit,
  inBetweenPropertySeparatorMark,
  nonPrimitiveValueOpeningMark,
  nonPrimitiveValueClosingMark,
  singleLineSpacingMark,
  tabMark
}: {
  readonly limit: number
  readonly inBetweenPropertySeparatorMark: string
  readonly nonPrimitiveValueOpeningMark: string
  readonly nonPrimitiveValueClosingMark: string
  readonly singleLineSpacingMark: string
  readonly tabMark: string
}) => Type

Source

tabify

Constructor that returns a PPNonPrimitiveFormatter instance that always prints non-primitive values on multiple lines with tabMark as indentation prefix for each property line.

Signature

declare const tabify: ({
  inBetweenPropertySeparatorMark,
  nonPrimitiveValueOpeningMark,
  nonPrimitiveValueClosingMark,
  tabMark
}: {
  readonly inBetweenPropertySeparatorMark: string
  readonly nonPrimitiveValueOpeningMark: string
  readonly nonPrimitiveValueClosingMark: string
  readonly tabMark: string
}) => Type

Source

treeify

Constructor that returns a PPNonPrimitiveFormatter instance that prints non-primitive values in a tree-like fashion using the four provided indentation marks. The header and value marks are not printed.

Signature

declare const treeify: ({
  treeIndentForFirstLineOfInitPropsMark,
  treeIndentForTailLinesOfInitPropsMark,
  treeIndentForFirstLineOfLastPropMark,
  treeIndentForTailLinesOfLastPropMark
}: {
  readonly treeIndentForFirstLineOfInitPropsMark: string
  readonly treeIndentForTailLinesOfInitPropsMark: string
  readonly treeIndentForFirstLineOfLastPropMark: string
  readonly treeIndentForTailLinesOfLastPropMark: string
}) => Type

Source

Equivalences

equivalence

Equivalence

Signature

declare const equivalence: Equivalence.Equivalence<Type>

Source

Getters

action

Returns the action property of self

Signature

declare const action: MTypes.OneArgFunction<
  Type,
  MTypes.OneArgFunction<
    {
      readonly nonPrimitive: PPValue.ReadonlyNonPrimitive
      readonly parameters: PPParameters.Type
      readonly applicableNonPrimitiveParameters: PPResolvedNonPrimitiveParameters.Type
      readonly header: Function.LazyArg<ASText.Type>
      readonly stringifiedProperties: PPStringifiedProperties.Type
    },
    [ASText.Type, ...ASText.Type[]]
  >
>

Source

id

Returns the id property of self

Signature

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

Source

Instances

usualTreeify

NonPrimitiveFormatter instance that treeifies a non-primitive value: no header, no value marks, no inBetweenProperty separator. Tabs are replaced by lines.

Signature

declare const usualTreeify: Type

Source

utilInspectLikeArray

NonPrimitiveFormatter instance that formats a non-primitive value in the way util.inspect does for arrays. Properties are separated by , and surrounded by [, ]. Arrays are split on several lines if the length of the object on a single line would exceed 80 characters. Uses two spaces as tab if the record is printed on several lines

Signature

declare const utilInspectLikeArray: Type

Source

utilInspectLikeRecord

NonPrimitiveFormatter instance that formats a non-primitive value in the way util.inspect does for records. Properties are separated by , and surrounded by {, }. Records are split on several lines if the length of the object on a single line would exceed 80 characters. Uses two spaces as tab if the record is printed on several lines

Signature

declare const utilInspectLikeRecord: Type

Source

Models

Type (class)

Type that represents a NonPrimitiveFormatter.

Signature

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

Source

[MData.idSymbol] (method)

Returns the id of this

Signature

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

Source

[Hash.symbol] (method)

Calculates the hash value of this

Signature

declare const [Hash.symbol]: () => number

Source

[MEquivalenceBasedEqualityData.isEquivalentToSymbol] (method)

Function that implements the equivalence of this and that

Signature

declare const [MEquivalenceBasedEqualityData.isEquivalentToSymbol]: (this: this, that: this) => boolean

Source

[MEquivalenceBasedEqualityData.hasSameTypeMarkerAsSymbol] (method)

Predicate that returns true if that has the same type marker as this

Signature

declare const [MEquivalenceBasedEqualityData.hasSameTypeMarkerAsSymbol]: (that: unknown) => boolean

Source

id (property)

Id of this NonPrimitiveFormatter instance. Useful for equality and debugging

Signature

readonly id: string

Source

action (property)

Action of this PPNonPrimitiveFormatter. Takes as input:

  • nonPrimitive: the non-primitive value being stringified (used as context for styling),
  • parameters: the PPParameters instance passed to the PPStringifier,
  • applicableNonPrimitiveParameters: the merged, fully-resolved PPNonPrimitiveParameters fields applicable to nonPrimitive (see PPResolvedNonPrimitiveParameters.fromApplicableNonPrimitiveParameters),
  • header: a lazy ASText header placed before the properties (usually the value’s name and property count, e.g. Map(2) ),
  • stringifiedProperties: the already-stringified representation of each property.

Returns the complete stringified representation of the non-primitive value.

Signature

readonly action: MTypes.OneArgFunction<{ readonly nonPrimitive: PPValue.ReadonlyNonPrimitive; readonly parameters: PPParameters.Type; readonly applicableNonPrimitiveParameters: PPResolvedNonPrimitiveParameters.Type; readonly header: Function.LazyArg<ASText.Type>; readonly stringifiedProperties: PPStringifiedProperties.Type; }, [ASText.Type, ...ASText.Type[]]>

Source

Module markers

moduleTag

Module tag

Signature

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

Source