export interface IValueTransformer { transform ( originalValue , name , widgetType ) : ValueTransformResult ; } export interface ValueTransformResult { handled : boolean ; value : string ; propertyType : string ; } export class ValueTransformersProvider { private readonly resolvers : { [ name ] : IValueTransformer ; } = { } ; private static instance : ValueTransformersProvider ; constructor ( ) { ValueTransformersProvider . instance = this ; } register ( name , resolver ) { if ( name instanceof Array ) { name . forEach ( n => this . resolvers [ n ] = resolver ) ; } else { this . resolvers [ name ] = resolver ; } } get ( name ) { return this . resolvers [ name ] ; } static transform ( value , name , widgetType ) { const valueTransformer = ValueTransformersProvider . instance . get ( name ) ; let valueTransformResult = { } as any ; if ( valueTransformer ) { valueTransformResult = valueTransformer . transform ( value , name , widgetType ) ; if ( valueTransformResult . handled ) { return valueTransformResult . value ; } } return value ; } }