node package manager


An ES5+ compatible utility to deep or shallow copy and merge objects.


An ES5+ compatible utility to deep or shallow copy and merge objects.

The module has two sub modules: shallow and deep. Both of them will have two methods: copy and merge.

Will loop over all own keys and copy them to a new object. The equivalent operation can be described as such:

// it's based on descriptors 
  // it preserves inheritance 
  // it does shallow copy 
  Reflect.ownKeys(source).reduce(function (d, k) {
    d[k] = Object.getOwnPropertyDescriptor(source, k);
  }, {})
  // or Reflect.getOwnPropertyDescriptors(source) 

The cloner.shallow.copy utility is most likely what you are looking for instead of the underpowered Object.assign one.

Preserves what's already in the target and merge all own keys found in one or more passed sources.

var a = {a: 1, b: 2};
var b = cloner.shallow.merge({a: 3}, a);
b; // {a: 3, b: 2} 

Probably the best option to merge states, ideal for statics or immutable properties.

Same as cloner.shallow.copy beside the fact every single own key will be deeply copied. Like its shallow counterpart, it does preserve inheritance and it's recursion aware, meaning it shouldn't fail with recursive properties, as already tested.

Same as cloner.shallow.merge but each new own key will be deeply copied.

npm install cloner should do, otherwise grab the file you like the most in here.

Copyright (C) 2015 by Andrea Giammarchi - @WebReflection
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.