deep-clone-map
Advanced tools
Comparing version 1.3.2 to 1.4.0
@@ -16,2 +16,3 @@ { | ||
"benchmark": "^2.1.4", | ||
"clone-deep": "^4.0.1", | ||
"deep-map": "^2.0.0", | ||
@@ -18,0 +19,0 @@ "es6-weak-map": "^2.0.3", |
@@ -29,4 +29,6 @@ var __assign = this && this.__assign || function () { | ||
var previousKey = prevKey ? prevKey + '.' + key : key; | ||
if (obj[key] && typeof obj[key] === 'object') { | ||
obj[key] = Array.isArray(obj[key]) ? __spreadArrays(obj[key]) : __assign({}, obj[key]); | ||
var isArr = Array.isArray(obj[key]); | ||
var isObj = obj[key] && obj[key].constructor === Object; | ||
if (isArr || isObj) { | ||
obj[key] = isArr ? __spreadArrays(obj[key]) : __assign({}, obj[key]); | ||
t(obj[key], previousKey); | ||
@@ -33,0 +35,0 @@ } else if (typeof cb === 'function') { |
@@ -45,4 +45,6 @@ "use strict"; | ||
var previousKey = prevKey ? prevKey + '.' + key : key; | ||
if (obj[key] && typeof obj[key] === 'object') { | ||
obj[key] = Array.isArray(obj[key]) ? __spread(obj[key]) : __assign({}, obj[key]); | ||
var isArr = Array.isArray(obj[key]); | ||
var isObj = obj[key] && obj[key].constructor === Object; | ||
if (isArr || isObj) { | ||
obj[key] = isArr ? __spread(obj[key]) : __assign({}, obj[key]); | ||
t(obj[key], previousKey); | ||
@@ -49,0 +51,0 @@ } |
@@ -13,4 +13,6 @@ "use strict"; | ||
const previousKey = prevKey ? prevKey + '.' + key : key; | ||
if (obj[key] && typeof obj[key] === 'object') { | ||
obj[key] = Array.isArray(obj[key]) ? [...obj[key]] : { ...obj[key] }; | ||
const isArr = Array.isArray(obj[key]); | ||
const isObj = obj[key] && obj[key].constructor === Object; | ||
if (isArr || isObj) { | ||
obj[key] = isArr ? [...obj[key]] : { ...obj[key] }; | ||
t(obj[key], previousKey); | ||
@@ -17,0 +19,0 @@ } |
@@ -15,2 +15,4 @@ import deepCloneMap from './dist' | ||
expectedArr2, | ||
testObjPrimitives, | ||
expectedObjPrimitives, | ||
} from './test-data' | ||
@@ -214,1 +216,9 @@ | ||
}) | ||
describe('object primitives', () => { | ||
it('should map all objects besides Object and Array', () => { | ||
const res = deepCloneMap(testObjPrimitives, () => 1) | ||
expect(res).toEqual(expectedObjPrimitives) | ||
}) | ||
}) |
@@ -1,3 +0,1 @@ | ||
type Param = object | any[] | string | number | null | ||
type Callback = (arg0: any, arg1?: string) => any | ||
@@ -18,4 +16,7 @@ | ||
if (obj[key] && typeof obj[key] === 'object') { | ||
obj[key] = Array.isArray(obj[key]) ? [...obj[key]] : { ...obj[key] } | ||
const isArr = Array.isArray(obj[key]) | ||
const isObj = obj[key] && obj[key].constructor === Object | ||
if (isArr || isObj) { | ||
obj[key] = isArr ? [...obj[key]] : { ...obj[key] } | ||
t(obj[key], previousKey) | ||
@@ -22,0 +23,0 @@ } else if (typeof cb === 'function') { |
{ | ||
"name": "deep-clone-map", | ||
"version": "1.3.2", | ||
"version": "1.4.0", | ||
"description": "Deep clone and map complex nested objects", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -17,3 +17,3 @@ # Deep Clone Map | ||
<b>Deep Clone Map</b> size is really tiny only <b>242 bytes</b> minified and gzipped. | ||
<b>Deep Clone Map</b> size is really tiny somewhere between <b>242 bytes</b> up to <b>440 bytes</b> minified and gzipped, depending on the algorithm used. | ||
@@ -67,2 +67,4 @@ #### Performance | ||
The code for benchmarks is located under the <b>benchmark</b> folder in the github repository. | ||
## Install | ||
@@ -69,0 +71,0 @@ |
@@ -316,1 +316,31 @@ export const testObj1 = { | ||
] | ||
export const testObjPrimitives = { | ||
a: { | ||
a: { | ||
a: new Date('2099-01-01'), | ||
b: new String('a'), | ||
}, | ||
b: new Date('2099-01-01'), | ||
c: new Number(100), | ||
d: { | ||
a: Symbol('a'), | ||
b: new Map(), | ||
}, | ||
}, | ||
} | ||
export const expectedObjPrimitives = { | ||
a: { | ||
a: { | ||
a: 1, | ||
b: 1, | ||
}, | ||
b: 1, | ||
c: 1, | ||
d: { | ||
a: 1, | ||
b: 1, | ||
}, | ||
}, | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
2164595
32
63638
328