ByPasser overview
This module implements a type that can optionally short-circuit the normal stringification pipeline for a given non-primitive value. When a PPByPasser decides to handle a value it returns a some of the resulting string, bypassing the usual property-extraction and formatting steps. When it does not apply, it returns a none and the normal pipeline takes over.
A typical use case is printing a Date as a human-readable string rather than as an object with all its internal properties.
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 PPByPasser
Signature
export declare const make: (params: MTypes.Data<Type>) => Type
merge
Creates a new PPByPasser by composing several existing PPByPasser’s. The resulting PPByPasser returns the some of the first PPByPasser in byPassers that returns a some for the given value. Returns none if no PPByPasser matches.
Signature
export declare const merge: ({
id,
byPassers
}: {
readonly id: string
readonly byPassers: ReadonlyArray<Type>
}) => 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<
{
readonly nonPrimitive: PPValue.ReadonlyNonPrimitive
readonly parameters: PPParameters.Type
readonly applicableNonPrimitiveParameters: PPResolvedNonPrimitiveParameters.Type
},
Option.Option<string>
>
>
id
Returns the id property of self
Signature
export declare const id: MTypes.OneArgFunction<Type, string>
Instances
allWithName
PPByPasser instance that displays the non-primitive value as its name surrounded by the openingTagMark and closingTagMark (e.g. [Function: foo]). Always returns a some. Can be used to display functions.
Signature
export declare const allWithName: Type
dateAndRegExp
PPByPasser instance that:
- Returns a
someof the result of calling.toISOString()on aDatenon-primitive value - Returns a
someof the result of calling.toString()on aRegExpnon-primitive value - Returns a
nonefor all other non-primitive values
This is the default byPasser baked into the merge defaults, so dates and regular expressions are pretty-printed as 2026-04-29T00:00:00.000Z and /foo/g even when no PPNonPrimitiveParameters explicitly sets a byPasser.
Signature
export declare const dateAndRegExp: Type
empty
PPByPasser instance that never bypasses any value (always returns none)
Signature
export declare const empty: Type
toStringable
PPByPasser instance that calls the .toString() method of the non-primitive value, but only when that method is not Object.prototype.toString (i.e. the value has a custom or overridden implementation). Returns a some of the result on success, none otherwise.
Practical examples where this returns a some: Date, any class that overrides toString. Note that calling .toString() on a function will return its source code, which is usually not the desired output.
Signature
export declare const toStringable: Type
Models
Type (class)
Type that represents a PPByPasser
Signature
export declare class Type {
constructor({ id, action }: MTypes.Data<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 PPByPasser instance. Useful for equality and debugging
Signature
readonly id: string
action (property)
Action of this PPByPasser. Takes as input:
nonPrimitive: the non-primitive value being stringified (used as context for styling),parameters: thePPParametersinstance passed to thePPStringifier,applicableNonPrimitiveParameters: the merged, fully-resolvedPPNonPrimitiveParametersfields applicable tononPrimitive(seePPResolvedNonPrimitiveParameters.fromApplicableNonPrimitiveParameters).
Returns Option.some(s) where s is the bypass string when this bypasser handles the value.
Signature
readonly action: MTypes.OneArgFunction<{ readonly nonPrimitive: PPValue.ReadonlyNonPrimitive; readonly parameters: PPParameters.Type; readonly applicableNonPrimitiveParameters: PPResolvedNonPrimitiveParameters.Type; }, Option.Option<string>>
Module markers
moduleTag
Module tag
Signature
export declare const moduleTag: "@parischap/pretty-print/Parameters/ByPasser/"