UNPKG

@parischap/pretty-print

Version:
186 lines 5.47 kB
/** * Type that represents a value in its stringification context. * * This module provides several Order instances to sort Value's according to your needs */ import { MTypes } from '@parischap/effect-lib'; import { Equal, Equivalence, Inspectable, Pipeable, Types } from 'effect'; /** * Module tag * * @category Models */ export declare const moduleTag = "@parischap/pretty-print/Value/"; declare const _TypeId: unique symbol; type _TypeId = typeof _TypeId; /** * Type of a Value * * @category Models */ export interface Type<out V> extends Equal.Equal, Inspectable.Inspectable, Pipeable.Pipeable { /** The value */ readonly content: V; /** Type of content */ readonly contentType: MTypes.Category.Type; /** * Depth of this value in the value to stringify: number of nested non-primitive values to open to * reach this value. */ readonly depth: number; /** Depth of this value in the prototypal chain of a non-primitive value */ readonly protoDepth: number; /** * Array of strings representing the key associated to that value if any. If this value is not in * a non-primitive value, i.e. it is itself the value to stringify, `stringKey` is an array * containing an empty string. If it is the value of one of the properties of a non-primitive * value, `stringKey` is a one-element array containing the property key converted to a string. If * it is one of the values of an iterable non-primitive value (e.g. a Map), `stringKey` is the * unstyled stringified key associated to the value. */ readonly stringKey: MTypes.OverOne<string>; /** Same as stringKey, but all lines are joined with an empty string */ readonly oneLineStringKey: string; /** * `true` if this value is the value of one of the properties of a non-primitive value whose * associated property key is a symbol. `false` otherwise. */ readonly hasSymbolicKey: boolean; /** * `true` if this value is the value of one of the properties of a non-primitive value that is * enumerable. `false` otherwise. */ readonly isEnumerable: boolean; /** @internal */ readonly [_TypeId]: { readonly _V: Types.Covariant<V>; }; } /** * Type that represents any value in its stringification context * * @category Models */ export interface All extends Type<unknown> { } /** * Type that represents a primitive value in its stringification context * * @category Models */ export interface Primitive extends Type<MTypes.Primitive> { } /** * Type that represents a non-primitive value in its stringification context * * @category Models */ export interface NonPrimitive extends Type<MTypes.NonPrimitive> { } /** * Type guard * * @category Guards */ export declare const has: (u: unknown) => u is All; /** * Value equivalence based on strict equality of the content properties. Used for cycle detection * * @category Equivalences */ export declare const equivalence: Equivalence.Equivalence<All>; /** * Constructor from the top value to stringify * * @category Constructors */ export declare const fromTopValue: <V>(content: V) => Type<V>; /** * Constructor from the property of a non-primitive value * * @category Constructors */ export declare const fromNonPrimitiveValueAndKey: ({ nonPrimitiveContent, key, depth, protoDepth }: { readonly nonPrimitiveContent: MTypes.NonPrimitive; readonly key: string | symbol; readonly depth: number; readonly protoDepth: number; }) => All; /** * Constructor from a value extracted from an iterable non-primitive value * * @category Constructors */ export declare const fromIterable: <V>({ content, stringKey, depth }: { readonly content: V; readonly stringKey: MTypes.OverOne<string>; readonly depth: number; }) => Type<V>; /** * Type guard * * @category Guards */ export declare const isPrimitive: (u: All) => u is Primitive; /** * Type guard * * @category Guards */ export declare const isNonPrimitive: (u: All) => u is NonPrimitive; /** * Type guard * * @category Guards */ export declare const isFunction: (u: All) => u is Type<MTypes.AnyFunction>; /** * Returns the `content` property of `self` * * @category Destructors */ export declare const content: <V>(self: Type<V>) => V; /** * Returns the `contentType` property of `self` * * @category Destructors */ export declare const contentType: MTypes.OneArgFunction<All, MTypes.Category.Type>; /** * Returns the `depth` property of `self` * * @category Destructors */ export declare const depth: MTypes.OneArgFunction<All, number>; /** * Returns the `protoDepth` property of `self` * * @category Destructors */ export declare const protoDepth: MTypes.OneArgFunction<All, number>; /** * Returns the `stringKey` property of `self` * * @category Destructors */ export declare const stringKey: MTypes.OneArgFunction<All, MTypes.OverOne<string>>; /** * Returns the `oneLineStringKey` property of `self` * * @category Destructors */ export declare const oneLineStringKey: MTypes.OneArgFunction<All, string>; /** * Returns the `hasSymbolicKey` property of `self` * * @category Destructors */ export declare const hasSymbolicKey: MTypes.OneArgFunction<All, boolean>; /** * Returns the `isEnumerable` property of `self` * * @category Destructors */ export declare const isEnumerable: MTypes.OneArgFunction<All, boolean>; export {}; //# sourceMappingURL=Value.d.ts.map