UNPKG

@parischap/pretty-print

Version:
450 lines 17.9 kB
/** * 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. */ import { MTypes } from '@parischap/effect-lib'; import { Option } from 'effect'; import { MInspectable } from '@parischap/effect-lib'; import { Equal, Equivalence, Pipeable } from 'effect'; import * as PPByPassers from './ByPassers.js'; import * as PPMarkMap from './MarkMap.js'; import * as PPMarkShower from './MarkShower.js'; import * as PPMarkShowerConstructor from './MarkShowerConstructor.js'; import * as PPNonPrimitiveFormatter from './NonPrimitiveFormatter.js'; import * as PPPrimitiveFormatter from './PrimitiveFormatter.js'; import * as PPPropertyFilter from './PropertyFilter.js'; import * as PPPropertyFilters from './PropertyFilters.js'; import * as PPPropertyFormatter from './PropertyFormatter.js'; import * as PPStringifiedValue from './StringifiedValue.js'; import * as PPStyleMap from './StyleMap.js'; import * as PPValue from './Value.js'; import * as PPValueBasedStylerConstructor from './ValueBasedStylerConstructor.js'; import * as PPValueOrder from './ValueOrder.js'; /** * Module tag * * @category Models */ export declare const moduleTag = "@parischap/pretty-print/Option/"; declare const _TypeId: unique symbol; type _TypeId = typeof _TypeId; /** * Namespace of a Stringifier * * @category Models */ export declare namespace Stringifier { /** * Type of a Stringifier * * @category Models */ interface Type extends MTypes.OneArgFunction<unknown, PPStringifiedValue.Type> { } } /** * Namespace for the possible sources of properties for non-primitive values * * @category Models */ export declare namespace PropertySource { /** * Type of a PropertySource * * @category Models */ enum Type { /** * Properties are obtained by calling Reflect.getOwnProperties on the non-primitive-value and * its prototypes (until maxPrototypeDepth is reached). This is usually a good choice for * records */ FromProperties = 0, /** * Properties are obtained by iterating over the non-primitive-value that must implement the * Iterable protocol. Each value returned by the iterator is used to create a property with an * auto-incremented numerical key (converted to a string). This is usually a good choice for * arrays and sets. */ FromValueIterable = 1, /** * Properties are obtained by iterating over the non-primitive-value that must implement the * Iterable protocol. The iterator must return a key/value pair. Otherwise, the returned value * is ignored. This is usually a good choice for maps,... */ FromKeyValueIterable = 2 } } /** * 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. * * @category Models */ export declare namespace PropertyNumberDisplayOption { /** * Type of a PropertyNumberDisplayOption * * @category Models */ enum Type { /** The number of properties is not shown */ None = 0, /** Shows the number of properties retrieved from the property source */ All = 1, /** * Shows the number of properties actually displayed, i.e. these remaining after filtering, * deduping and applying `maxPropertyNumber` */ Actual = 2, /** * Shows both the number of properties retrieved from the property source and the number of * properties actually displayed (after filtering, deduping and applying `maxPropertyNumber`) */ AllAndActual = 3, /** * Shows both the number of properties retrieved from the property source and the number of * properties actually displayed (after filtering, deduping and applying `maxPropertyNumber`) * only if these two numbers are different. Otherwise, does not show anything */ AllAndActualIfDifferent = 4 } } /** * Namespace for the options for pretty printing non-primitive values * * @category Models */ export declare namespace NonPrimitive { const _TypeId: unique symbol; type _TypeId = typeof _TypeId; /** * Type of an option for a NonPrimitive * * @category Models */ 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; } /** * Type guard * * @category Guards */ export const has: (u: unknown) => u is Type; /** * Equivalence * * @category Equivalences */ export const equivalence: Equivalence.Equivalence<Type>; /** * Constructor without an id * * @category Constructors */ export const make: (params: MTypes.Data<Type>) => Type; /** * Returns the `id` property of `self` * * @category Destructors */ export const id: MTypes.OneArgFunction<Type, string>; /** * Defaults NonPrimitive Option instance * * @category Instances */ export const record: Type; /** * NonPrimitive Option instance for arrays * * @category Instances */ export const array: Type; /** * Constructor that generates a NonPrimitive Option instance suitable for maps * * @category Constructors */ export const maps: (id: string) => Type; /** * Constructor that generates a NonPrimitive Option instance suitable for sets and arrays other * than Array * * @category Constructors */ export const setsAndArrays: (id: string) => Type; /** * Namespace of an initialized NonPrimitive Option * * @category Models */ export namespace Initialized { /** * Type of an InitializedNonPrimitiveOption * * @category Models */ 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; } /** * Builds an Initialized from a NonPrimitive * * @category Constructors */ const fromNonPrimitive: (params: { readonly valueBasedStylerConstructor: PPValueBasedStylerConstructor.Type; readonly markShowerConstructor: PPMarkShowerConstructor.Type; }) => MTypes.OneArgFunction<NonPrimitive.Type, Type>; } export {}; } /** * Interface that represents the options for pretty printing * * @category Models */ 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; } /** * Type guard * * @category Guards */ export declare const has: (u: unknown) => u is Type; /** * Equivalence * * @category Equivalences */ export declare const equivalence: Equivalence.Equivalence<Type>; /** * Constructor without a id * * @category Constructors */ export declare const make: (params: MTypes.Data<Type>) => Type; /** * Returns the `id` property of `self` * * @category Destructors */ export declare const id: MTypes.OneArgFunction<Type, string>; /** * `Option` instance that pretty-prints a value in a way very similar to util.inspect. * * @category Instances */ export declare const utilInspectLike: Type; /** * `Option` instance that pretty-prints a value in a way very similar to util.inspect with colors * adapted to a terminal in dark mode. * * @category Instances */ export declare const darkModeUtilInspectLike: Type; /** * `Option` instance that treeifies a value * * @category Instances */ export declare const treeify: Type; /** * `Option` instance that treeifies a value with colors adapted to dark mode * * @category Instances */ export declare const darkModeTreeify: Type; /** * `Option` instance that treeifies a value and hides the leaves * * @category Instances */ export declare const treeifyHideLeaves: Type; /** * `Option` instance that treeifies a value and hides the leaves with colors adapted to dark mode * * @category Instances */ export declare const darkModeTreeifyHideLeaves: Type; /** * Builds a Stringifier from an Option * * @category Destructors */ export declare const toStringifier: (self: Type) => Stringifier.Type; export {}; //# sourceMappingURL=Option.d.ts.map