regular expressions are being ignored
JohannesMerz opened this issue · 2 comments
regular expressions are ignored.
console.log(deepAssign({
str: "a", reg: /a/
}, {
str: "b", reg: /b/
})); // results in { str: 'b', reg: /a/ } instead of { str: 'b', reg: /b/ }
Unfortunately, things aren't that easy. For example, the properties of rebB
are not ignored:
const regB = /b/;
regB.foo = 42;
console.log(deepAssign({
str: "a", reg: /a/
}, {
str: "b", reg: regB
}).reg.foo);
// => 42
–You may want to read the open deep-assign/issues.
If you only search for a solution, please consider a different library (e.g. merge-options
may fit you needs–disclaimer: I'm the author, and there are many other libraries).
Otherwise, I would be very, very happy if someone could contribute, but please read the arguments already mentioned in the issues. And keep in mind, the current goal is:
Recursive
Object.assign()
Please also note, the more technical specification at http://www.ecma-international.org/ecma-262/6.0/#sec-object.assign
IMO, the ways out are:
- change the goal of
deep-assign
, i.e. create a PR, which changes thereadme.md
(implies a major version bump) - create a new project, with a different goal (e.g.
merge-options
distinguishes plain and non-plain objects, which is not the goal ofdeep-assign
) - find a way to provide an options object, but without breaking compatibility in the base case(!)
- find an interpretation of of "recursive" and the "Object.assign()" algorithm, which justifies a new approach
- find something, I can't think of 😉
Bests, Michael
This module is now deprecated: b332062