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

PrimitiveFormatter.ts overview

This module implements a type that converts a primitive value to its string representation. Typical responsibilities include: surrounding strings in quotes, truncating long strings with an ellipsis, appending n to bigints, and formatting numbers with a custom formatter.

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 of a PPPrimitiveFormatter

Signature

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

Source

utilInspectLikeMaker

Constructor that builds a PPPrimitiveFormatter instance modelled on util.inspect: - Strings are truncated at maxStringLength characters (an ellipsis is appended when truncated) and surrounded with quoteChar. Pass maxStringLength = +Infinity to disable truncation. - Numbers are formatted with numberFormatter. - Bigints are formatted with bigintFormatter and suffixed with n.

Signature

declare const utilInspectLikeMaker: ({
  id,
  maxStringLength,
  quoteChar,
  numberFormatter,
  bigintFormatter
}: {
  readonly id: string
  readonly maxStringLength: number
  readonly quoteChar: string
  readonly numberFormatter: MTypes.OneArgFunction<number, string>
  readonly bigintFormatter: MTypes.OneArgFunction<bigint, 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<PPValue.Primitive, string>>

Source

id

Returns the id property of self

Signature

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

Source

Instances

utilInspectLike

PPPrimitiveFormatter instance modelled on util.inspect: - Strings are truncated at 10 000 characters and surrounded with '. - Numbers are formatted with MString.fromNumber(10) (same output as Number.prototype.toString()). - Bigints are formatted with MString.fromNumber(10) (same output as BigInt.prototype.toString()) and suffixed with n.

Signature

declare const utilInspectLike: Type

Source

Models

Type (class)

Type that represents a PPPrimitiveFormatter

Signature

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

Source

make (static method)

Static constructor

Signature

declare const make: (params: MTypes.Data<Type>) => 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 PPPrimitiveFormatter instance. Useful for equality and debugging

Signature

readonly id: string

Source

action (property)

Action of this PPPrimitiveFormatter. Takes a PPValue.Primitive and returns its string representation (e.g. 'hello' for a string, 42 for a number, 42n for a bigint)

Signature

readonly action: MTypes.OneArgFunction<PPValue.Primitive, string>

Source

Module markers

moduleTag

Module tag

Signature

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

Source