@mahmoudxyz/hassan
Version:
Type-safe data mapper for TypeScript with zero runtime overhead
22 lines • 923 B
TypeScript
interface DirectValue {
__type: 'direct';
value: unknown;
}
interface ConditionalMapping {
__type: 'conditional';
when: TransformFunction;
then: string | DirectValue | TransformFunction;
else?: string | DirectValue | TransformFunction;
}
type TransformFunction = (source: Record<string, unknown>, context?: Record<string, unknown>) => unknown;
type MappingValue = string | DirectValue | TransformFunction | ConditionalMapping;
interface Mapper {
map: (input: unknown, context?: Record<string, unknown>) => unknown;
}
export declare const h: {
direct: (value: unknown) => DirectValue;
when: (condition: TransformFunction, thenValue: string | DirectValue | TransformFunction, elseValue?: string | DirectValue | TransformFunction) => ConditionalMapping;
};
export declare function createMapper(mappings: Record<string, MappingValue>): Mapper;
export {};
//# sourceMappingURL=mapper.d.ts.map