import { IConversionValidation } from '../types' ; /**
 * Wrapper methods to test the datatype of the given value
 */ export abstract class DataUtility { static isUndefined ( data ) { return data === undefined ; } static isUndefinedOrNull ( data ) { return DataUtility . isUndefined ( data ) || data === null ; } static isNull ( data ) { return data === null ; } static isEmpty ( data ) { return DataUtility . isUndefinedOrNull ( data ) || data === '' ; } static isFunction ( data ) { return typeof data === 'function' ; } static isString ( data ) { return typeof data === 'string' ; } static isRegExp ( data ) { return data instanceof RegExp ; } static isBoolean ( data ) { const val = DataUtility . isString ( data ) && ( data . toLowerCase ( ) === 'false' || data . toLowerCase ( ) === 'true' ) ; return val ? true : DataUtility . isStrictBoolean ( data ) ; } static isStrictBoolean ( data ) { return typeof data === 'boolean' ; } static isNumber ( data ) { return DataUtility . isString ( data ) ? Number . isFinite ( Number ( data ) ) : DataUtility . isStrictNumber ( data ) ; } /**
     * Strict - does not use string conversion
     */ static isStrictNumber ( data ) { return typeof data === 'number' ; } static isArray ( data ) { return Array . isArray ( data ) ; } static isInteger ( data ) { return DataUtility . isStrictNumber ( data ) || DataUtility . isString ( data ) ? Number . isInteger ( Number ( data ) ) : false ; } static toNumber ( data ) { let valid = false ; let value ; if ( DataUtility . isNumber ( data ) ) { value = Number . parseFloat ( data ) ; valid = true ; } return { isValid : valid , value : value } ; } static toInteger ( data ) { let valid = false ; let value ; if ( DataUtility . isStrictNumber ( data ) || ( DataUtility . isString ( data ) && Number . isInteger ( Number ( data ) ) ) ) { value = Number . parseInt ( data ) ; valid = true ; } return { isValid : valid , value : value } ; } static toBoolean ( data ) { let valid = false ; let value ; if ( DataUtility . isStrictBoolean ( data ) ) { valid = true ; value = data ; } else if ( DataUtility . isString ( data ) ) { if ( data . toLowerCase ( ) === 'true' ) { valid = true ; value = true ; } else if ( data . toLowerCase ( ) === 'false' ) { valid = true ; value = false ; } } return { isValid : valid , value : value } ; } }