UNPKG

type-transformer

Version:

Transformation / serialization / deserialization of plain JavaScript objects to typed objects and vice versa

39 lines (38 loc) 1.5 kB
export declare enum Direction { PLAIN_TO_TYPED = "PLAIN_TO_TYPED", TYPED_TO_PLAIN = "TYPED_TO_PLAIN" } export declare enum Visibility { EXPOSE = "EXPOSE", EXCLUDE = "EXCLUDE" } export interface SelectOptions { toTypedOnly?: boolean; toPlainOnly?: boolean; [key: string]: any; } export interface SelectFunction { (obj: any, direction: Direction, options?: SelectOptions): boolean; } declare type SelectorOptionsTuple = [SelectFunction, SelectOptions | undefined]; export declare class Selectable { selectors: SelectorOptionsTuple[]; defaultVisibility: Visibility; /** * Add a select function, possibly with options, that is asked if this * selectable should be selected for a transformation. * @param selector A function that is passed the object to be transformed, * the transformation direction and the options. So the * options can be used to prametrize the function. * @param options An object implementing SelectOptions. */ addSelector(selector: SelectFunction, options?: SelectOptions): void; /** * Is this selectable to be selected for the given object and direction? * @returns either `Visibility.EXPOSE` or `Visibility.EXCLUDE` if there * is an explicit answer, `undefined` otherwise. */ selected(obj: any, direction: Direction): Visibility | undefined; private doesSelectorApply; } export {};