NonPrimitiveFormatter 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.
Table of contents
Constructors
make
Constructor
Signature
export declare const make: (params: MTypes.Data<Type>) => Type
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
export declare const singleLine: ({
inBetweenPropertySeparatorMark,
nonPrimitiveValueOpeningMark,
nonPrimitiveValueClosingMark,
singleLineSpacingMark
}: {
readonly inBetweenPropertySeparatorMark: string
readonly nonPrimitiveValueOpeningMark: string
readonly nonPrimitiveValueClosingMark: string
readonly singleLineSpacingMark: string
}) => Type
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
export 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
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
export 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
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
export 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
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
export declare const tabify: ({
inBetweenPropertySeparatorMark,
nonPrimitiveValueOpeningMark,
nonPrimitiveValueClosingMark,
tabMark
}: {
readonly inBetweenPropertySeparatorMark: string
readonly nonPrimitiveValueOpeningMark: string
readonly nonPrimitiveValueClosingMark: string
readonly tabMark: string
}) => Type
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
export declare const treeify: ({
treeIndentForFirstLineOfInitPropsMark,
treeIndentForTailLinesOfInitPropsMark,
treeIndentForFirstLineOfLastPropMark,
treeIndentForTailLinesOfLastPropMark
}: {
readonly treeIndentForFirstLineOfInitPropsMark: string
readonly treeIndentForTailLinesOfInitPropsMark: string
readonly treeIndentForFirstLineOfLastPropMark: string
readonly treeIndentForTailLinesOfLastPropMark: 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<
{
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[]]
>
>
id
Returns the id property of self
Signature
export declare const id: MTypes.OneArgFunction<Type, string>
Instances
usualTreeify
NonPrimitiveFormatter instance that treeifies a non-primitive value: no header, no value marks, no inBetweenProperty separator. Tabs are replaced by lines.
Signature
export declare const usualTreeify: Type
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
export declare const utilInspectLikeArray: Type
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
export declare const utilInspectLikeRecord: Type
Models
Type (class)
Type that represents a NonPrimitiveFormatter.
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 NonPrimitiveFormatter instance. Useful for equality and debugging
Signature
readonly id: string
action (property)
Action of this PPNonPrimitiveFormatter. 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),header: a lazyASTextheader 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[]]>
Module markers
moduleTag
Module tag
Signature
export declare const moduleTag: "@parischap/pretty-print/Parameters/NonPrimitiveFormatter/"