unclechu / node-deep-extend

Recursive extend module
MIT License
202 stars 53 forks source link

Why arrays doesn't get merged? #22

Closed pateketrueke closed 8 years ago

pateketrueke commented 8 years ago

In your README you point out that extending j: [1, 2] with j: [3, 4] will return j: [3,4 ] and I don't want that behavior... there is an option for concat arrays?

unclechu commented 8 years ago

@pateketrueke because it isn't obvious what to do with arrays in this case, concat/replace or something else. There's no way to concat arrays now.

shellscape commented 6 years ago

@unclechu resurrecting this one from the dead... it could be possible to create a factory pattern that accepted options for determining behavior. e.g.

const extend = deepExtend.set({ arrays: 'concat' });
const result = extend({}, {a:[3]}, {a:[1,2]});
// { a: [3, 1, 2] }

That could support multiple different methods (which could also be user-extendible), with the default being the current behavior of right-most replacement.