/**
 * This file exports tiny facades over the external packages.
 * The behavior of a dependency can be overridden here
*/ import has from 'lodash/has' ; import set from 'lodash/set' ; import get from 'lodash/get' ; import unset from 'lodash/unset' ; import { isPlainObject as _isPlainObject } from 'is-plain-object' ; import _clone from 'shallow-clone' ; import kindOf from 'kind-of' ; import jsStringEscape from 'js-string-escape' ; import geoHash from 'latlon-geohash' ; import pMap from 'p-map' ; import { AnyObject } from './interfaces' ; import { DataEntity } from './entities' ; /**
 * Detect if an object created by Object.create(null)
*/ function isNullObject ( input ) { return input != null && typeof input === 'object' && input . constructor === undefined ; } /**
 * Detect if value is a plain object, that is,
 * an object created by the Object constructor or one via Object.create(null)
*/ export function isPlainObject ( input ) { if ( input == null ) return false ; if ( _isPlainObject ( input ) ) return true ; return false ; } /**
 * Shallow clone an object
*/ export function clone ( input ) { if ( isNullObject ( input ) ) { return Object . assign ( Object . create ( null ) , input ) ; } return _clone ( input ) ; } function _isDataEntity ( input ) { return input && typeof input === 'object' && Boolean ( input . __isDataEntity ) ; } const _cloneTypeHandlers = Object . freeze ( { object ( input ) { const descriptors = Object . getOwnPropertyDescriptors ( input ) ; for ( const key in descriptors ) { descriptors [ key ] . value = cloneDeep ( descriptors [ key ] . value ) ; } return Object . create ( Object . getPrototypeOf ( input ) , descriptors ) ; } , array ( input ) { const res = new input . constructor ( input . length ) ; for ( let i = 0 ; i < input . length ; i ++ ) { res [ i ] = cloneDeep ( input [ i ] ) ; } return res ; } , } ) ; export function cloneDeep < T = any > ( input ) { const handler = _cloneTypeHandlers [ kindOf ( input ) ] || clone ; return handler ( input ) ; } return export function getTypeOf ( val ) { if ( val === undefined ) return 'undefined' ; if ( val === null ) return 'null' ; if ( _isDataEntity ( val ) ) { if ( val . constructor && val . constructor . name !== 'Object' ) { return val . constructor . name ; } return 'DataEntity' ; } if ( typeof val === 'object' ) { if ( val . constructor && val . constructor . name ) { return val . constructor . name ; } if ( val . prototype && val . prototype . name ) { return val . prototype . name ; } } const kind = kindOf ( val ) ; if ( ! kind || kind . length <= 1 ) return `${ kind }` ; return `${ kind . charAt ( 0 ) . toUpperCase ( ) }${ kind . slice ( 1 ) }` ; } /** Escape characters in string and avoid double escaping */ export function escapeString ( input ) { return jsStringEscape ( `${ input }` ) ; } export { get , set , unset , has , geoHash , pMap , } ;