"Fossies" - the Fresh Open Source Software Archive

Member "Atom/resources/app/apm/node_modules/es5-ext/object/copy-deep.js" (8 Mar 2017, 939 Bytes) of archive /windows/misc/atom-windows.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Javascript source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 'use strict';
    2 
    3 var forEach       = require('./for-each')
    4   , isPlainObject = require('./is-plain-object')
    5   , value         = require('./valid-value')
    6 
    7   , isArray = Array.isArray
    8   , copy, copyItem;
    9 
   10 copyItem = function (value, key) {
   11     var index;
   12     if (!isPlainObject(value) && !isArray(value)) return value;
   13     index = this[0].indexOf(value);
   14     if (index === -1) return copy.call(this, value);
   15     return this[1][index];
   16 };
   17 
   18 copy = function (source) {
   19     var target = isArray(source) ? [] : {};
   20     this[0].push(source);
   21     this[1].push(target);
   22     if (isArray(source)) {
   23         source.forEach(function (value, key) {
   24             target[key] = copyItem.call(this, value, key);
   25         }, this);
   26     } else {
   27         forEach(source, function (value, key) {
   28             target[key] = copyItem.call(this, value, key);
   29         }, this);
   30     }
   31     return target;
   32 };
   33 
   34 module.exports = function (source) {
   35     var obj = Object(value(source));
   36     if (obj !== source) return obj;
   37     return copy.call([[], []], obj);
   38 };