PropertyFormatter overview
This module implements a type that takes care of the stringification of the properties of a non- primitive value. From the stringified representation of the value of a property which it receives, it must return the stringified representation of the whole property (key and value).
With the make function, you can define your own instances if the provided ones don’t suit your needs.
Table of contents
Constructors
keyAndValue
Constructor that builds a PPPropertyFormatter instance that prints the key and value of a property on the same line, separated by keyValueSeparatorMark (similar to the usual way a record is printed). prototypePrefixMark is prepended and prototypeSuffixMark is appended to property keys as many times as the depth of the property in the prototypal chain (useful to visually distinguish inherited properties).
Signature
export declare const keyAndValue: ({
keyValueSeparatorMark,
prototypePrefixMark,
prototypeSuffixMark
}: {
readonly keyValueSeparatorMark: string
readonly prototypePrefixMark: string
readonly prototypeSuffixMark: string
}) => Type
make
Constructor
Signature
export declare const make: (params: MTypes.Data<Type>) => Type
treeify
Constructor that builds a PPPropertyFormatter instance for tree-style output:
- For a leaf property: prints key and value on the same line, separated by
keyValueSeparatorMark(same askeyAndValue). - For a non-leaf property: prints the key on its own line and the formatted sub-tree on the following lines, with no separator.
Signature
export declare const treeify: ({
keyValueSeparatorMark,
prototypePrefixMark,
prototypeSuffixMark
}: {
readonly keyValueSeparatorMark: string
readonly prototypePrefixMark: string
readonly prototypeSuffixMark: string
}) => Type
treeifyHideLeaves
Constructor that builds a PPPropertyFormatter instance for tree-style output with hidden leaves: - For a leaf property: prints only the key (the value is hidden). - For a non-leaf property: prints the key on its own line and the formatted sub-tree on the following lines, with no separator.
Signature
export declare const treeifyHideLeaves: ({
keyValueSeparatorMark,
prototypePrefixMark,
prototypeSuffixMark
}: {
readonly keyValueSeparatorMark: string
readonly prototypePrefixMark: string
readonly prototypeSuffixMark: string
}) => Type
Equivalences
equivalence
PropertyFormatter 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,
({
property,
stringifiedPropValue,
isLeaf,
hideKey,
parameters
}: {
readonly property: PPValue.Any
readonly stringifiedPropValue: PPStringifiedValue.Type
readonly isLeaf: boolean
readonly hideKey: boolean
readonly parameters: PPParameters.Type
}) => PPStringifiedValue.Type
>
id
Returns the id property of self
Signature
export declare const id: MTypes.OneArgFunction<Type, string>
Instances
usualTreeify
PropertyFormatter instance that treeifies a non-primitive value (and shows the leaves)
Signature
export declare const usualTreeify: Type
usualTreeifyHideLeaves
PropertyFormatter instance that treeifies a non-primitive value (and hides the leaves)
Signature
export declare const usualTreeifyHideLeaves: Type
utilInspectLikeArrayAndRecord
PropertyFormatter instance that formats a non-primitive value in the way util.inspect does for records. Property key and value are separated by : (if the key is shown, which is usually not the case for arrays). @ is suffixed to all property keys as many times as the depth of the property in the prototypal chain
Signature
export declare const utilInspectLikeArrayAndRecord: Type
utilInspectLikeIterable
PropertyFormatter instance that formats a non-primitive value in the way util.inspect does for maps and sets. Property key and value are separated by => (if the key is shown, which is usually not the case for sets). @ is suffixed to all property keys as many times as the depth of the property in the prototypal chain
Signature
export declare const utilInspectLikeIterable: Type
valueOnly
PropertyFormatter instance that prints only the value of a property (similar to the usual way an array is printed).
Signature
export declare const valueOnly: Type
Models
Type (class)
Type that represents a PropertyFormatter.
Signature
export declare class Type {
public 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 PPPropertyFormatter instance. Useful for equality and debugging
Signature
readonly id: string
action (property)
Action of this PPPropertyFormatter. The action takes as input:
property: the property being stringified,stringifiedPropValue: the stringified representation of the value of that property,isLeaf: a boolean that indicates if the property is a leaf (useful to hide leaves when treeifying),hideKey: a boolean that indicates if the key must be displayed (useful for iterables like arrays for which keys have been generated automatically by auto-incrementation and are usually not displayed)parameters: the parameters passed by the user to build thePPStringifier.
It returns a stringified representation of the whole property.
Signature
readonly action: ({ property, stringifiedPropValue, isLeaf, hideKey, parameters, }: { readonly property: PPValue.Any; readonly stringifiedPropValue: PPStringifiedValue.Type; readonly isLeaf: boolean; readonly hideKey: boolean; readonly parameters: PPParameters.Type; }) => PPStringifiedValue.Type
Module markers
moduleTag
Module tag
Signature
export declare const moduleTag: "@parischap/pretty-print/Parameters/PropertyFormatter/"