mappet
Version:
Lightweight, composable mappers for object transformations
28 lines (27 loc) • 749 B
TypeScript
interface Source {
[key: string]: any;
}
declare type Result<T> = {
[K in keyof T]: any;
};
declare type Modifier = (value: any, source: any) => any;
declare type Include = (value: any, source: any) => boolean;
declare type Path = string | string[];
interface PathConfig {
path: Path;
modifier?: Modifier;
include?: Include;
}
export declare type SchemaEntry = Path | PathConfig;
interface Schema {
[key: string]: SchemaEntry;
}
interface MappetOptions {
strict?: boolean;
greedy?: boolean;
name?: string;
}
export default function mappet<S extends Schema, O extends MappetOptions>(schema: S, options?: Partial<O>): <T extends Source>(source: T) => Result<O extends {
greedy: true;
} ? T & S : S>;
export {};