bin/util.js
function copy(obj, map) {
    if (map.has(obj)) {
        return map.get(obj);
    } else if (Array.isArray(obj)) {
        const result = [];
        map.set(obj, result);
        obj.forEach(item => {
            result.push(copy(item, map));
        });
        return result;
    } else if (typeof obj === 'object' && obj) {
        const result = {};
        map.set(obj, result);
        Object.keys(obj).forEach(key => {
            result[key] = copy(obj[key], map);
        });
        return result;
    } else {
        return obj;
    }
}
function copy(obj, map) {
    if (map.has(obj)) {
        return map.get(obj);
    } else if (Array.isArray(obj)) {
        const result = [];
        map.set(obj, result);
        obj.forEach(item => {
            result.push(copy(item, map));
        });
        return result;
    } else if (typeof obj === 'object' && obj) {
        const result = {};
        map.set(obj, result);
        Object.keys(obj).forEach(key => {
            result[key] = copy(obj[key], map);
        });
        return result;
    } else {
        return obj;
    }
}
function copy ( obj , map ) { if ( map . has ( obj ) ) { return map . get ( obj ) ; } else if ( Array . isArray ( obj ) ) { const result = [ ] ; map . set ( obj , result ) ; obj . forEach ( item => { result . push ( copy ( item , map ) ) ; } ) ; return result ; } else if ( typeof obj === 'object' && obj ) { const result = { } ; map . set ( obj , result ) ; Object . keys ( obj ) . forEach ( key => { result [ key ] = copy ( obj [ key ] , map ) ; } ) ; return result ; } else { return obj ; } }
Perform a deep copy of a value.
@param {*} obj
@param {WeakMap} [map]
@returns {*}
Perform a deep copy of a value .