PrimitiveFormatter 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.
Table of contents
Constructors
make
Constructor of a PPPrimitiveFormatter
Signature
export declare const make: (params: MTypes.Data<Type>) => Type
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
export 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
Equivalences
equivalence
Equivalence
Signature
export declare const equivalence: Equivalence.Equivalence<Type>
Getters
action
Returns the action property of self
Signature
export declare const action: MTypes.OneArgFunction<Type, MTypes.OneArgFunction<PPValue.Primitive, string>>
id
Returns the id property of self
Signature
export declare const id: MTypes.OneArgFunction<Type, string>
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
export declare const utilInspectLike: Type
Models
Type (class)
Type that represents a PPPrimitiveFormatter
Signature
export declare class Type {
private constructor({ id, action }: MTypes.Data<Type>)
}
make (static method)
Static constructor
Signature
static make(params: MTypes.Data<Type>): Type
[MData.idSymbol] (method)
Returns the id of this
Signature
[MData.idSymbol](): string | (() => string)
[Hash.symbol] (method)
Calculates the hash value of this
Signature
[Hash.symbol](): number
[MEquivalenceBasedEqualityData.isEquivalentToSymbol] (method)
Function that implements the equivalence of this and that
Signature
[MEquivalenceBasedEqualityData.isEquivalentToSymbol](this: this, that: this): boolean
[MEquivalenceBasedEqualityData.hasSameTypeMarkerAsSymbol] (method)
Predicate that returns true if that has the same type marker as this
Signature
[MEquivalenceBasedEqualityData.hasSameTypeMarkerAsSymbol](that: unknown): boolean
id (property)
Id of this PPPrimitiveFormatter instance. Useful for equality and debugging
Signature
readonly id: string
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>
Module markers
moduleTag
Module tag
Signature
export declare const moduleTag: "@parischap/pretty-print/Parameters/PrimitiveFormatter/"