import {Exception} from './exception'; /** * A simple interface which matches a function * which accepts an input and an optional map of * options for the converter and returns a value of * another type. */ export interface Converter { (arg: T): R; } export class EncodingException extends Exception { constructor(message: string) { super(message); } } export function composeConverters(fst: Converter, snd: Converter): Converter { return (input) => snd(fst(input)); } export function chainConverters(...converters: Converter[]): Converter { return converters.reduce(composeConverters, identityConverter); } export function identityConverter(arg: T): T { return arg; } export function toStringConverter(arg: any): string { return arg.toString(); }