Sha256: cef6f3b22ddf3f51e7293ede4740b1f5690eeb16ef691c7512d6a196ee1a735e

Contents?: true

Size: 1.09 KB

Versions: 7

Compression:

Stored size: 1.09 KB

Contents

var kindOf = require('./kindOf');
var isPlainObject = require('./isPlainObject');
var mixIn = require('../object/mixIn');

    /**
     * Clone native types.
     */
    function clone(val){
        switch (kindOf(val)) {
            case 'Object':
                return cloneObject(val);
            case 'Array':
                return cloneArray(val);
            case 'RegExp':
                return cloneRegExp(val);
            case 'Date':
                return cloneDate(val);
            default:
                return val;
        }
    }

    function cloneObject(source) {
        if (isPlainObject(source)) {
            return mixIn({}, source);
        } else {
            return source;
        }
    }

    function cloneRegExp(r) {
        var flags = '';
        flags += r.multiline ? 'm' : '';
        flags += r.global ? 'g' : '';
        flags += r.ignorecase ? 'i' : '';
        return new RegExp(r.source, flags);
    }

    function cloneDate(date) {
        return new Date(+date);
    }

    function cloneArray(arr) {
        return arr.slice();
    }

    module.exports = clone;


Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
entangled-0.0.16 spec/dummy/public/node_modules/bower/node_modules/mout/lang/clone.js
entangled-0.0.15 spec/dummy/public/node_modules/bower/node_modules/mout/lang/clone.js
entangled-0.0.14 spec/dummy/public/node_modules/bower/node_modules/mout/lang/clone.js
entangled-0.0.13 spec/dummy/public/node_modules/bower/node_modules/mout/lang/clone.js
entangled-0.0.12 spec/dummy/public/node_modules/bower/node_modules/mout/lang/clone.js
entangled-0.0.11 spec/dummy/public/node_modules/bower/node_modules/mout/lang/clone.js
entangled-0.0.10 spec/dummy/public/node_modules/bower/node_modules/mout/lang/clone.js