NonPrimitiveParameters overview
This module implements the pretty-printing parameters that govern how a specific category of non- primitive values is displayed. A PPParameters instance holds an ordered array of PPNonPrimitiveParameters. When stringifying a non-primitive value, every entry whose isApplicableTo predicate matches is selected and the matching ones are merged together (lower- index entries override higher-index ones); fields not specified by any of the merged entries fall back to the record-like defaults exposed by PPResolvedNonPrimitiveParameters.utilInspectLikeRecord.
Apart from id and isApplicableTo, every field is optional: an instance therefore acts as a partial override layer. Use the make function to define your own.
Table of contents
- Constructors
- Equivalences
- Getters
- Instances
- Models
- Type (class)
- [MData.idSymbol] (method)
- [Hash.symbol] (method)
- [MEquivalenceBasedEqualityData.isEquivalentToSymbol] (method)
- [MEquivalenceBasedEqualityData.hasSameTypeMarkerAsSymbol] (method)
- id (property)
- isApplicableTo (property)
- showName (property)
- propertyNumberDisplayOption (property)
- byPasser (property)
- maxPrototypeDepth (property)
- propertyFilter (property)
- propertySortOrder (property)
- dedupeProperties (property)
- maxPropertyNumber (property)
- propertyFormatter (property)
- nonPrimitiveFormatter (property)
- hideAutoGeneratedKeys (property)
- extractIterableElements (property)
- Type (class)
- Module markers
Constructors
make
Constructor of a PPNonPrimitiveParameters. Only id and isApplicableTo are required; every other field is optional and falls back to the module-level default after merging.
Signature
export declare const make: (params: MTypes.Data<Type>) => Type
Equivalences
equivalence
Equivalence
Signature
export declare const equivalence: Equivalence.Equivalence<Type>
Getters
id
Returns the id property of self
Signature
export declare const id: MTypes.OneArgFunction<Type, string>
isApplicableTo
Returns the isApplicableTo property of self
Signature
export declare const isApplicableTo: MTypes.OneArgFunction<Type, Predicate.Predicate<MTypes.ReadonlyNonPrimitive>>
Instances
treeify
Catch-all PPNonPrimitiveParameters instance used to treeify any non-primitive value. Shows leaf keys regardless of whether the keys were auto-generated.
Signature
export declare const treeify: Type
treeifyHideLeaves
Same as treeify but hides leaf values, only displaying their keys.
Signature
export declare const treeifyHideLeaves: Type
utilInspectLikeArray
PPNonPrimitiveParameters instance for arrays. Shows [Array] when maxDepth is exceeded; otherwise displays the array as util.inspect does (e.g. [ 3, 4 ]). The contents are extracted through iteration; properties of the array object (e.g. length) are not displayed unless you change maxPrototypeDepth to 1 or more.
Note: this instance must be placed before utilInspectLikeIterable in the nonPrimitiveParametersArray (lower index = higher priority during merge). It explicitly resets showName, propertyNumberDisplayOption and propertyFormatter because, when an array is processed, utilInspectLikeIterable (which is also applicable) would otherwise contribute its iterable-style values for those fields.
Signature
export declare const utilInspectLikeArray: Type
utilInspectLikeFunction
PPNonPrimitiveParameters instance for functions. Functions are displayed as util.inspect does (e.g. [Function: foo], or [Function: (anonymous)] when the function has no name)
Signature
export declare const utilInspectLikeFunction: Type
utilInspectLikeIterable
PPNonPrimitiveParameters instance for iterables (Arrays, Maps, Sets, HashMaps, HashSets, typed arrays…). Always shows the value’s name and total element count in the header, e.g. Map(1) { 'A' => 2 }. The name itself comes from PPParameters.name, whose default uses value.constructor.name, so this transparently handles Map, Set, WeakMap, WeakSet, Int8Array, Float32Array, etc. as well as user-defined iterable classes.
Signature
export declare const utilInspectLikeIterable: Type
Models
Type (class)
Type that represents a PPNonPrimitiveParameters. Apart from id and isApplicableTo, every field is optional: unset fields are filled in by PPResolvedNonPrimitiveParameters.fromApplicableNonPrimitiveParameters from the record-like defaults.
Signature
export declare class Type {
constructor(params: 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 PPNonPrimitiveParameters. Used for equality and debugging
Signature
readonly id: string
isApplicableTo (property)
Predicate that returns true if this PPNonPrimitiveParameters is applicable to nonPrimitive.
Signature
readonly isApplicableTo: Predicate.Predicate<MTypes.ReadonlyNonPrimitive>
showName (property)
When true, the value’s name (computed by PPParameters.name) is shown in the header before the properties, separated by headerSeparatorMark. Property counts (when enabled via propertyNumberDisplayOption) are inserted between the name and the separator. Example: Map(2) { 'a' => 1, 'b' => 2 }.
Signature
readonly showName: boolean | undefined
propertyNumberDisplayOption (property)
Controls whether and how property counts are shown in the header. When not None, counts are wrapped in propertyNumberOpeningMark / propertyNumberClosingMark. For AllAndActual and AllAndActualIfDifferent, the two counts are separated by propertyNumberSeparatorMark. Examples: Map(2) { 'a' => 1 } with Actual; Map(5,2) { 'a' => 1 } with AllAndActual.
Signature
readonly propertyNumberDisplayOption: PPPropertyNumberDisplayOption.Type | undefined
byPasser (property)
PPByPasser instance (see PPByPasser.ts) to apply to the non-primitive values to which self is applicable. If you need to pass several PPByPasser’s, use the PPByPasser.merge constructor.
Signature
readonly byPasser: PPByPasser.Type | undefined
maxPrototypeDepth (property)
Indicates the level in the prototypal chain of a non-primitive value down to which properties are shown. maxPrototypeDepth <= 0 means that no properties are shown. maxPrototypeDepth = 1 means that only the own properties of a non-primitive value are shown. maxPrototypeDepth = 2 means that only the own properties of a non-primitive value and that of its direct prototype are shown…
Signature
readonly maxPrototypeDepth: number | undefined
propertyFilter (property)
PPPropertyFilter instance (see PropertyFilter.ts) to apply to the properties of non-primitive values to which this is applicable. If you need to pass several PPPropertyFilter instances, use the PPPropertyFilter.merge function.
Signature
readonly propertyFilter: PPPropertyFilter.Type | undefined
propertySortOrder (property)
Order to use to sort the properties of that type of non-primitive values just after application of the property filter. If none is passed, properties are not sorted.
Signature
readonly propertySortOrder: Option.Option<PPValueOrder.Type> | undefined
dedupeProperties (property)
Non-primitive values can have several properties with the same key. For instance, the same key can appear in an object and one or several of its prototypes. This option allows you to decide if you want to keep all the properties with the same key. If true, only the first occurrence of each property with the same key is kept. Sorting happens before deduping, so you can decide which property will be first by choosing your propertySortOrder carefully (e.g. you may use PropertyOrder.byPrototypalDepth). If false, all occurrences of the same property are kept.
Signature
readonly dedupeProperties: boolean | undefined
maxPropertyNumber (property)
Maximal number of properties to keep for non-primitive values. Pass +Infinity to show all properties. Keeps the maxPropertyNumber first properties after filtering, sorting and deduping.
Signature
readonly maxPropertyNumber: number | undefined
propertyFormatter (property)
PPPropertyFormatter instance which allows you to specify how to format properties of non- primitive values (see PropertyFormatter.ts).
Signature
readonly propertyFormatter: PPPropertyFormatter.Type | undefined
nonPrimitiveFormatter (property)
PPNonPrimitiveFormatter instance: allows you to specify how to print a non-primitive value from its stringified properties (see NonPrimitiveFormatter.ts).
Signature
readonly nonPrimitiveFormatter: PPNonPrimitiveFormatter.Type | undefined
hideAutoGeneratedKeys (property)
Keys of the properties of a non-primitive value are not shown if hideAutoGeneratedKeys is true and if all the keys of the properties of that non-primitive value have been generated (this usually happens for an iterable when maxPrototypeDepth is equal to 0). Otherwise, the keys are shown.
Signature
readonly hideAutoGeneratedKeys: boolean | undefined
extractIterableElements (property)
When true and the non-primitive value is iterable, its elements are extracted via iteration (in addition to its own keyed properties controlled by maxPrototypeDepth). When false, iteration is skipped even when the value is iterable. Defaults to true. Set to false for categories whose iteration is not meaningful for display, e.g. functions.
Signature
readonly extractIterableElements: boolean | undefined
Module markers
moduleTag
Module tag
Signature
export declare const moduleTag: "@parischap/pretty-print/Parameters/NonPrimitiveParameters/"