1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | 'use strict';
|
7 |
|
8 | var isArray = require('isarray');
|
9 |
|
10 | function deepCopyInternal (obj, result) {
|
11 | var key, val;
|
12 | for (key in obj) {
|
13 | if (key.lastIndexOf('_', 0) === 0) {
|
14 | continue;
|
15 | }
|
16 | if (obj.hasOwnProperty(key)) {
|
17 | val = obj[key];
|
18 | if (typeof val === 'object' && val !== null) {
|
19 | if (val instanceof RegExp) {
|
20 | val = new RegExp(val);
|
21 | } else {
|
22 | val = deepCopyInternal(val, isArray(val) ? [] : {});
|
23 | }
|
24 | }
|
25 | result[key] = val;
|
26 | }
|
27 | }
|
28 | return result;
|
29 | }
|
30 |
|
31 | function deepCopy (obj) {
|
32 | return deepCopyInternal(obj, isArray(obj) ? [] : {});
|
33 | }
|
34 |
|
35 | module.exports = deepCopy;
|