export const hasOwnProperty = Object . prototype . hasOwnProperty ; export function objectType ( object ) { if ( object === undefined ) { return 'undefined' ; } if ( object === null ) { return 'null' ; } if ( Array . isArray ( object ) ) { return 'array' ; } return typeof object ; } function isNonPrimitive ( value ) { return value != null && typeof value == 'object' ; } param source returns export function clone < T extends any > ( source ) { if ( ! isNonPrimitive ( source ) ) { return source ; } if ( source . constructor == Array ) { const length = ( source as Array < any > ) . length ; const arrayTarget = new Array ( length ) ; for ( let i = 0 ; i < length ; i ++ ) { arrayTarget [ i ] = clone ( source [ i ] ) ; } return arrayTarget ; } if ( source . constructor == Date ) { const dateTarget = new Date ( + source ) ; return dateTarget ; } const objectTarget = { } ; for ( const key in source ) { if ( hasOwnProperty . call ( source , key ) ) { objectTarget [ key ] = clone ( source [ key ] ) ; } } return objectTarget ; }