function escapeString ( str ) { return str . replace ( /"/g , '\\"' ) ; } export function getType ( value ) { if ( value === null ) { return 'null' ; } return typeof value ; } export function isObject ( value ) { var type = typeof value ; return ! ! value && ( type == 'object' ) ; } export function getObjectName ( object ) { if ( object === undefined ) { return '' ; } if ( object === null ) { return 'Object' ; } if ( typeof object === 'object' && ! object . constructor ) { return 'Object' ; } const funcNameRegex = /function ([^(]*)/ ; const results = ( funcNameRegex ) . exec ( ( object ) . constructor . toString ( ) ) ; if ( results && results . length > 1 ) { return results [ 1 ] ; } else { return '' ; } } export function getValuePreview ( type , object , value ) { if ( type === 'null' || type === 'undefined' ) { return type ; } if ( type === 'string' || type === 'stringifiable' ) { value = '"' + escapeString ( value ) + '"' ; } if ( type === 'function' ) { return object . toString ( ) . replace ( /[\r\n]/g , '' ) . replace ( /\{.*\}/ , '' ) + '{…}' ; } return value ; } export function getPreview ( object ) { let value = '' ; if ( isObject ( object ) ) { value = getObjectName ( object ) ; if ( Array . isArray ( object ) ) value += '[' + object . length + ']' ; } else { value = getValuePreview ( getType ( object ) , object , object ) ; } return value ; } export function cssClass ( className ) { return `json-formatter-${ className }` ; } export function createElement ( type , className ? , content ? ) { const el = document . createElement ( type ) ; if ( className ) { el . classList . add ( cssClass ( className ) ) ; } if ( content !== undefined ) { if ( content instanceof Node ) { el . appendChild ( content ) ; } else { el . appendChild ( document . createTextNode ( String ( content ) ) ) ; } } return el ; }