UNPKG

@parischap/pretty-print

Version:
138 lines 4.62 kB
/** * 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. */ import { MInspectable, MTypes } from '@parischap/effect-lib'; import { Equal, Equivalence, Pipeable } from 'effect'; import * as PPMarkShowerConstructor from './MarkShowerConstructor.js'; import type * as PPOption from './Option.js'; import * as PPStringifiedValue from './StringifiedValue.js'; import * as PPValue from './Value.js'; import * as PPValueBasedStylerConstructor from './ValueBasedStylerConstructor.js'; /** * Module tag * * @category Models */ export declare const moduleTag = "@parischap/pretty-print/PropertyFormatter/"; declare const _TypeId: unique symbol; type _TypeId = typeof _TypeId; /** * Namespace of a PropertyFormatter used as an action * * @category Models */ export declare namespace Action { /** * Namespace of an initialized PropertyFormatter used as an action * * @category Models */ namespace Initialized { /** * Type of the action. The action takes as input the Value (see Value.ts) being currently * printed, a boolean that indicates if the value is a leaf (i.e. it could be stringified * without stringifying each of its properties) and the stringified representation of that value * (see StringifiedValue.ts) . Based on these two parameters, it must return a stringified * representation of the whole property. * * @category Models */ interface Type { ({ value, isLeaf }: { readonly value: PPValue.All; readonly isLeaf: boolean; }): MTypes.OneArgFunction<PPStringifiedValue.Type>; } } /** * Type of the action. The action takes as input a ValueBasedStylerConstructor (see * ValueBasedStylerConstructor.ts), a MarkShowerConstructor (see MarkShowerConstructor.ts). Based * on these two parameters, it must return an Initialized Action. * * @category Models */ interface Type { (this: PPOption.NonPrimitive.Type, { valueBasedStylerConstructor, markShowerConstructor }: { readonly valueBasedStylerConstructor: PPValueBasedStylerConstructor.Type; readonly markShowerConstructor: PPMarkShowerConstructor.Type; }): Initialized.Type; } } /** * Type that represents a PropertyFormatter. * * @category Models */ export interface Type extends Action.Type, Equal.Equal, MInspectable.Inspectable, Pipeable.Pipeable { /** Id of this PropertyFormatter instance. Useful for equality and debugging */ readonly id: string; /** @internal */ readonly [_TypeId]: _TypeId; } /** * Type guard * * @category Guards */ export declare const has: (u: unknown) => u is Type; /** * PropertyFormatter equivalence * * @category Equivalences */ export declare const equivalence: Equivalence.Equivalence<Type>; /** * Constructor * * @category Constructors */ export declare const make: ({ id, action }: { readonly id: string; readonly action: Action.Type; }) => Type; /** * Returns the `id` property of `self` * * @category Destructors */ export declare const id: MTypes.OneArgFunction<Type, string>; /** * PropertyFormatter instance that prints only the value of a property (similar to the usual way an * array is printed). * * @category Instances */ export declare const valueOnly: Type; /** * PropertyFormatter instance that prints the key and value of a property (similar to the usual way * a record is printed). A mark can be prepended or appended to the key to show if the property * comes from the object itself or from one of its prototypes. * * @category Instances */ export declare const keyAndValue: Type; /** * PropertyFormatter instance that : * * - For a leaf: does the same as keyAndValue * - For a non-leaf: prints the key and value on separate lines without any key/value separator * * @category Instances */ export declare const treeify: Type; /** * PropertyFormatter instance that : * * - For a leaf: prints only the key * - For a non-leaf: prints the key and value on separate lines without any key/value separator * * @category Instances */ export declare const treeifyHideLeafValues: Type; export {}; //# sourceMappingURL=PropertyFormatter.d.ts.map