@parischap/pretty-print
Version:
A functional library to pretty-print and treeify objects
145 lines • 5.32 kB
TypeScript
/**
* This module implements a type that takes care of the formatting of non-primitive values. From the
* stringified representation of the properties of a non-primitive value which it receives, it must
* return the stringified representation of the whole non-primitive value. It can take care of
* aspects like adding specific array/object marks, printing on a single or multiple lines,
* indentation when printing on multiple lines, ...
*
* With the make function, you can define your own instances if the provided ones don't suit your
* needs.
*/
import { ASText } from '@parischap/ansi-styles';
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 PPStringifiedProperties from './StringifiedProperties.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/NonPrimitiveFormatter/";
declare const _TypeId: unique symbol;
type _TypeId = typeof _TypeId;
/**
* Namespace of a NonPrimitiveFormatter used as an action
*
* @category Models
*/
export declare namespace Action {
/**
* Namespace of an initialized NonPrimitiveFormatter used as an action
*
* @category Models
*/
namespace Initialized {
/**
* Type of the action of a NonPrimitiveFormatter. The action takes as input the Value being
* currently printed (see Value.ts), a header to be displayed in front of the stringified
* properties (usually the id of the non primitive value and the number of displayed properties)
* and an array of the stringified properties (see StringifiedProperties.ts) of that value.
* Based on these parameters, it must return a stringified representation of the whole record.
*/
interface Type {
({ value, header }: {
readonly value: PPValue.NonPrimitive;
readonly header: ASText.Type;
}): (children: PPStringifiedProperties.Type) => PPStringifiedValue.Type;
}
}
/**
* Type of the action of a NonPrimitiveFormatter. The action takes as input a
* ValueBasedStylerConstructor (see ValueBasedStylerConstructor.ts), a MarkShowerConstructor (see
* MarkShowerConstructor.ts). Based on these parameters, it must return an Initialized Action.
*/
interface Type {
(this: PPOption.NonPrimitive.Type, { valueBasedStylerConstructor, markShowerConstructor }: {
readonly valueBasedStylerConstructor: PPValueBasedStylerConstructor.Type;
readonly markShowerConstructor: PPMarkShowerConstructor.Type;
}): Initialized.Type;
}
}
/**
* Type that represents a NonPrimitiveFormatter.
*
* @category Models
*/
export interface Type extends Action.Type, Equal.Equal, MInspectable.Inspectable, Pipeable.Pipeable {
/** Id of this NonPrimitiveFormatter 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;
/**
* 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>;
/**
* NonPrimitiveFormatter instance that will always print non-primitive values on a single line
*
* @category Instances
*/
export declare const singleLine: Type;
/**
* NonPrimitiveFormatter instance that will always print non-primitive values on multiple lines with
* a tab indentation
*
* @category Instances
*/
export declare const tabify: Type;
/**
* NonPrimitiveFormatter instance that will always print non-primitive values in a tree-like fashion
*
* @category Instances
*/
export declare const treeify: Type;
/**
* NonPrimitiveFormatter instance maker that will print non-primitive values on a single line if the
* actual number of their constituents (after filtering,...) is less than or equal to `limit`.
*
* @category Constructors
*/
export declare const splitOnConstituentNumberMaker: (limit: number) => Type;
/**
* Calls `singleLine` if the total length of the properties to print (excluding formatting
* characters) is less than or equal to `limit`. Calls `tabify` otherwise
*
* @category Constructors
*/
export declare const splitOnTotalLengthMaker: (limit: number) => Type;
/**
* Calls `singleLine` if the length of the longest property to print (excluding formatting
* characters and object marks) is less than or equal to `limit`. Calls `tabify` otherwise
*
* @category Constructors
*/
export declare const splitOnLongestPropLengthMaker: (limit: number) => Type;
export {};
//# sourceMappingURL=NonPrimitiveFormatter.d.ts.map