import { asString } from '../types/Text'; export class Convert { constructor( public readonly from: (f: From) => To, public readonly to: (t: To) => From ) {} } export const convert = { default: new Convert( a => a, a => a ), ignore: new Convert( () => undefined, () => undefined ), toBool: { fromNumber: new Convert( b => (b ? 1 : 0), n => n !== 0 ), fromString: new Convert( b => (b ? 'true' : 'false'), s => s === 'true' ), }, toDate: { fromString: new Convert( s => new Date(s).toISOString(), s => s ), }, toNumber: { fromString: new Convert( n => asString(n), s => parseInt(s) ), }, };