@ebflat9/fp
Advanced tools
Comparing version 1.1.23 to 1.1.24
{ | ||
"name": "@ebflat9/fp", | ||
"version": "1.1.23", | ||
"version": "1.1.24", | ||
"description": "my fp utils", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -779,3 +779,14 @@ /** | ||
aux = new obj.constructor() | ||
Object.getOwnPropertyNames(obj).forEach(prop => (aux[prop] = deepCopy(obj[prop]))) | ||
if (isMap(aux)) { | ||
for (const key of obj.keys()) { | ||
const keyCopy = deepCopy(key) | ||
aux.set(keyCopy, obj.get(key)) | ||
} | ||
} else if (isSet(aux)) { | ||
for (const val of obj.values()) { | ||
aux.add(val) | ||
} | ||
} else { | ||
Object.getOwnPropertyNames(obj).forEach(prop => (aux[prop] = deepCopy(obj[prop]))) | ||
} | ||
} | ||
@@ -782,0 +793,0 @@ return aux |
@@ -748,5 +748,33 @@ import * as combinators from '../src/combinators.js' | ||
assert.deepEqual(combinators.diff(a, b), { age: 16 }) | ||
assert.deepEqual(combinators.merge(b, combinators.diff(a, b)), b) | ||
const merged = combinators.merge(b, combinators.diff(a, b)) | ||
assert.deepEqual(merged, b) | ||
assert.notEqual(merged, b) | ||
}) | ||
}) | ||
describe('deepCopy', function () { | ||
it('should copy maps, sets and objects', function () { | ||
const s = new Set([1, 2, 3]) | ||
assert.deepEqual(combinators.deepCopy(s), new Set([1, 2, 3])) | ||
const m = new Map([ | ||
['hi', 'there'], | ||
[{}, null], | ||
]) | ||
assert.deepEqual( | ||
combinators.deepCopy(m), | ||
new Map([ | ||
['hi', 'there'], | ||
[{}, null], | ||
]) | ||
) | ||
const o = { | ||
a: { | ||
b: 'x', | ||
}, | ||
c: ['cat'], | ||
} | ||
assert.deepEqual(combinators.deepCopy(o), o) | ||
assert.notEqual(combinators.deepCopy(o), o) | ||
}) | ||
}) | ||
}) |
239157
7697