3 var forEach = require('./for-each')
4 , isPlainObject = require('./is-plain-object')
5 , value = require('./valid-value')
7 , isArray = Array.isArray
10 copyItem = function (value, key) {
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];
18 copy = function (source) {
19 var target = isArray(source) ? [] : {};
22 if (isArray(source)) {
23 source.forEach(function (value, key) {
24 target[key] = copyItem.call(this, value, key);
27 forEach(source, function (value, key) {
28 target[key] = copyItem.call(this, value, key);
34 module.exports = function (source) {
35 var obj = Object(value(source));
36 if (obj !== source) return obj;
37 return copy.call([[], []], obj);