Skip to main content Link Search Menu Expand Document (external link)

Option overview

This module implements the options for pretty-printing.

With the make function, you can define your own instances if the provided ones don’t suit your needs.


Table of contents


Constructors

make

Constructor without a id

Signature

export declare const make: (params: MTypes.Data<Type>) => Type

Destructors

id

Returns the id property of self

Signature

export declare const id: MTypes.OneArgFunction<Type, string>

toStringifier

Builds a Stringifier from an Option

Signature

export declare const toStringifier: (self: Type) => Stringifier.Type

Equivalences

equivalence

Equivalence

Signature

export declare const equivalence: Equivalence.Equivalence<Type>

Guards

has

Type guard

Signature

export declare const has: (u: unknown) => u is Type

Instances

darkModeTreeify

Option instance that treeifies a value with colors adapted to dark mode

Signature

export declare const darkModeTreeify: Type

darkModeTreeifyHideLeaves

Option instance that treeifies a value and hides the leaves with colors adapted to dark mode

Signature

export declare const darkModeTreeifyHideLeaves: Type

darkModeUtilInspectLike

Option instance that pretty-prints a value in a way very similar to util.inspect with colors adapted to a terminal in dark mode.

Signature

export declare const darkModeUtilInspectLike: Type

treeify

Option instance that treeifies a value

Signature

export declare const treeify: Type

treeifyHideLeaves

Option instance that treeifies a value and hides the leaves

Signature

export declare const treeifyHideLeaves: Type

utilInspectLike

Option instance that pretty-prints a value in a way very similar to util.inspect.

Signature

export declare const utilInspectLike: Type

Models

NonPrimitive (namespace)

Namespace for the options for pretty printing non-primitive values

Type (interface)

Type of an option for a NonPrimitive

Signature

export interface Type extends Equal.Equal, MInspectable.Inspectable, Pipeable.Pipeable {
  /**
   * Id of this type of non-primitive valie. This id is:
   *
   * - Used for equality and debugging
   * - Displayed in case `maxDepth` is superseded surrounded by the MessageStartDelimiter and
   *   MessageEndDelimiter marks. For instance: [Array]
   * - Displayed in front of the representation of the non-primitive value even if `maxDepth` is not
   *   superseded if `showId` is `true` (see below).
   */
  readonly id: string

  /**
   * If true, the id will be shown just before the non-primitive value representation seperated
   * from it by the `NonPrimitiveValueNameSeparator` mark. For instance: `Map { 'a' => 1, 'b' => 2
   * }`
   */
  readonly showId: boolean

  /**
   * Options regarding the display of the property number of a non-primitive value. If not `None`,
   * the property number will be suffixed to the id in between the `PropertyNumberStartDelimiter`
   * and `PropertyNumberEndDelimiter` marks. For `AllAndActual` and `AllAndActualIfDifferent`, the
   * `PropertyNumberSeparator` mark is used to seperate the two property numbers. For instance:
   * `Map(2) { 'a' => 1, 'b' => 2 }` with `Actual` or `Map(5,2) { 'a' => 1, 'b' => 2 }` with
   * `AllAndActual`
   */
  readonly propertyNumberDisplayOption: PropertyNumberDisplayOption.Type

  /** Key/value separator mark for that type of non-primitive value. For instance ': ' for an array */
  readonly keyValueSeparatorMark: string

  /**
   * Mark shown before the representation of a non-primitive value when it is displayed on a
   * single line. For instance '{ ' for a record
   */
  readonly singleLineStartDelimiterMark: string

  /**
   * Mark shown after the representation of a non-primitive value when it is displayed on a single
   * line. For instance ' }' for a record
   */
  readonly singleLineEndDelimiterMark: string

  /**
   * Mark shown before the representation of a non-primitive value when it is displayed on
   * multiple lines. For instance '{' for a record
   */
  readonly multiLineStartDelimiterMark: string

  /**
   * Mark shown after the representation of a non-primitive value when it is displayed on multiple
   * lines. For instance '}' for a record
   */
  readonly multiLineEndDelimiterMark: string

  /**
   * Mark repeated before the key of the property of a non-primitive value to indicate the depth
   * of that key in the prototypal chain
   */
  readonly prototypeStartDelimiterMark: string

  /**
   * Mark repeated after the key of the property of a non-primitive value to indicate the depth of
   * that key in the prototypal chain. For instance '@'. `@` means that the key is on the direct
   * prototype of the non-primitive value and '@@' means that the key is on the prototype of the
   * prototype of the non-primitive value
   */
  readonly prototypeEndDelimiterMark: string

  /**
   * SingleLineInBetweenPropertySeparatorMark for that type of non-primitive value. For instance
   * ', ' for records
   */
  readonly singleLineInBetweenPropertySeparatorMark: string

  /**
   * MultiLineInBetweenPropertySeparatorMark for that non-primitive value. For instance ',' for
   * records
   */
  readonly multiLineInBetweenPropertySeparatorMark: string

  /** IdSeparatorMark for that type of non-primitive value. For instance ' ' */
  readonly idSeparatorMark: string

  /** PropertyNumberSeparatorMark for that type of non-primitive value. For instance ',' */
  readonly propertyNumberSeparatorMark: string

  /** PropertyNumberStartDelimiterMark for that type of non-primitive value. For instance '(' */
  readonly propertyNumberStartDelimiterMark: string

  /** PropertyNumberEndDelimiterMark for that type of non-primitive value. For instance ')' */
  readonly propertyNumberEndDelimiterMark: string

  /**
   * Specifies the source of properties for non-primitive values. See the PropertySource.Type for
   * more details
   */
  readonly propertySource: PropertySource.Type

  /**
   * Indicates the level in the prototypal chain of a non-primitive value down to which properties
   * are shown. This value is only used when propertySource is `FromProperties`. maxPrototypeDepth
   * <= 0 means that only the own properties of a non-primitive value are shown. maxPrototypeDepth
   * = 1 means that only the own properties of a non-primitive value and that of its direct
   * prototype are shown...
   */
  readonly maxPrototypeDepth: number

  /**
   * Array of `PropertyFilter` instances applied successively just after retrieving the properties
   * of a non-primitive value from the selected source (see PropertyFilter.ts)
   */
  readonly propertyFilters: PPPropertyFilters.Type

  /**
   * If `none`, properties are not sorted. If a `some` of a ValueOrder (see ValueOrder.ts), that
   * ValueOrder is used to sort properties of non-primitive values just after application of the
   * propertyFilters.
   */
  readonly propertySortOrder: Option.Option<PPValueOrder.Type>

  /**
   * 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.
   */
  readonly dedupeProperties: boolean

  /**
   * Maximal number of properties to keep for non-primitive values. Pass +Infinity to show all
   * properties. Keeps the `maxPropertyNumber` first properties after filtering, ordering and
   * deduping.
   */
  readonly maxPropertyNumber: number

  /**
   * `PropertyFormatter` instance which allows you to specify how to format properties of
   * non-primitive values (see PropertyFormatter.ts)
   */
  readonly propertyFormatter: PPPropertyFormatter.Type

  /**
   * `NonPrimitiveFormatter` instance: allows you to specify how to print a non-primitive value
   * from its stringified properties (see NonPrimitiveFormatter.ts)
   */
  readonly nonPrimitiveFormatter: PPNonPrimitiveFormatter.Type

  /** @internal */
  readonly [_TypeId]: _TypeId
}

Initialized (namespace)

Namespace of an initialized NonPrimitive Option

Type (interface)

Type of an InitializedNonPrimitiveOption

Signature

export interface Type extends MTypes.Data<NonPrimitive.Type> {
  readonly syntheticPropertyFilter: PPPropertyFilter.Action.Type
  readonly initializedPropertyFormatter: PPPropertyFormatter.Action.Initialized.Type
  readonly initializedNonPrimitiveFormatter: PPNonPrimitiveFormatter.Action.Initialized.Type
  readonly toHeaderMarkShower: ({
    allPropertyNumber,
    actualPropertyNumber
  }: {
    readonly allPropertyNumber: number
    readonly actualPropertyNumber: number
  }) => PPMarkShower.Type
}

PropertyNumberDisplayOption (namespace)

Namespace for the options regarding the display of the number of properties of a non-primitive value. The number of properties is shown in between parentheses just after the non-primitive value id.

PropertySource (namespace)

Namespace for the possible sources of properties for non-primitive values

Stringifier (namespace)

Namespace of a Stringifier

Type (interface)

Type of a Stringifier

Signature

export interface Type extends MTypes.OneArgFunction<unknown, PPStringifiedValue.Type> {}

Type (interface)

Interface that represents the options for pretty printing

Signature

export interface Type extends Equal.Equal, MInspectable.Inspectable, Pipeable.Pipeable {
  /** Id of this Option instance. Useful for equality and debugging */
  readonly id: string

  /** Map of ValueBasedStyler's used to style the different parts of a stringified value */
  readonly styleMap: PPStyleMap.Type

  /** Map of the different marks that appear in a value to stringify */
  readonly markMap: PPMarkMap.Type

  /**
   * Array of `ByPasser` instances (see ByPasser.ts): the first ByPasser that returns a `some` is
   * used to display that value. If all ByPasser's return a `none`, the normal stringification
   * process is applied.
   */
  readonly byPassers: PPByPassers.Type

  /** PrimitiveFormatter (see PrimitiveFormatter.ts) instance used to format primitive values */
  readonly primitiveFormatter: PPPrimitiveFormatter.Type

  /**
   * Maximum number of nested non primitive values that will be opened. A value inferior or equal to
   * 0 means that only the value to stringify is shown, provided it is a primitive. If it is a
   * non-primitive value, it gets replaced by a message string that depends on the type of that non
   * primitive value (e.g. [Object], [Array],...). Pass +Infinity to see all levels of any non
   * primitive value.
   */
  readonly maxDepth: number

  /**
   * Options that will apply to all non-primitive values other than those for which specific options
   * are provided. See specificNonPrimitiveOptions below
   */
  readonly generalNonPrimitiveOption: NonPrimitive.Type

  /**
   * Function that takes a value and returns either a `none` if the generalNonPrimitiveOptions must
   * be applied for that value or a `some` of the specific options to apply for that value.
   */
  readonly specificNonPrimitiveOption: MTypes.OneArgFunction<PPValue.NonPrimitive, Option.Option<NonPrimitive.Type>>

  /** @internal */
  readonly [_TypeId]: _TypeId
}

moduleTag

Module tag

Signature

export declare const moduleTag: "@parischap/pretty-print/Option/"