import { Dict } from '../../types' ; import { JsonSchema } from '../../types/jsonschema' ; export const Value = { parseValue ( data , { type } ) { if ( this . hasOwnProperty ( type ) ) { if ( type === 'boolean' && typeof data === 'string' ) { data = data === 'true' ; } return ( Value as any ) [ type ] ( data ) ; } return data as any ; } , null ( ) { return null ; } , boolean ( value ) { return value === true ; } , integer ( data ) { const value = Number ( data ) ; const parsedValue = Number . parseInt ( data as string , 10 ) ; return Number . isNaN ( value ) || Number . isNaN ( parsedValue ) ? undefined : parsedValue ; } , number ( data ) { const value = Number ( data ) ; const parsedValue = Number . parseFloat ( data as string ) ; return Number . isNaN ( value ) || Number . isNaN ( parsedValue ) ? undefined : parsedValue ; } , object ( data ) { return data as any || { } ; } , string ( data ) { return typeof data !== 'undefined' ? `${ data }` : undefined ; } , array ( data ) { return data instanceof Array ? data . filter ( ( item ) => typeof item !== 'undefined' ) : [ ] ; } } ;