import { JSONValue } from './types' ; import { find } from './util' ; export interface CustomTransfomer < I , O extends JSONValue > { name : string ; isApplicable : ( v : any ) => v is I ; serialize : ( v : I ) => O ; deserialize : ( v : O ) => I ; } const transfomers = { } ; export const CustomTransformerRegistry = { register < I , O extends JSONValue > ( transformer ) { transfomers [ transformer . name ] = transformer ; } , findApplicable < T > ( v ) { return find ( transfomers , transformer => transformer . isApplicable ( v ) ) as CustomTransfomer < T , JSONValue > | undefined ; } , findByName ( name ) { return transfomers [ name ] ; } } ;