You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

README.md 1.1 KiB

3 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. # Merge
  2. Merge multiple objects into one, optionally creating a new cloned object.
  3. Similar to the jQuery.extend but more flexible. Works in Node.js and the
  4. browser.
  5. ## Node.js Usage
  6. ```sh
  7. npm install merge --save
  8. ```
  9. ```js
  10. var merge = require('merge'), original, cloned;
  11. console.log(merge({one:'hello'}, {two: 'world'}));
  12. // -> {"one": "hello", "two": "world"}
  13. original = { x: { y: 1 } };
  14. cloned = merge(true, original);
  15. cloned.x.y++;
  16. console.log(original.x.y, cloned.x.y);
  17. // -> 1, 2
  18. console.log(merge.recursive(true, original, { x: { z: 2 } }));
  19. // -> {"x": { "y": 1, "z": 2 } }
  20. ```
  21. ## Browser Usage
  22. ```html
  23. <script src="https://cdn.jsdelivr.net/gh/yeikos/js.merge/merge.js"></script>
  24. <script>
  25. var original, cloned;
  26. console.log(merge({one:'hello'}, {two: 'world'}));
  27. // -> {"one": "hello", "two": "world"}
  28. original = { x: { y: 1 } };
  29. cloned = merge(true, original);
  30. cloned.x.y++;
  31. console.log(original.x.y, cloned.x.y);
  32. // -> 1, 2
  33. console.log(merge.recursive(true, original, { x: { z: 2 } }));
  34. // -> {"x": { "y": 1, "z": 2 } }
  35. </script>
  36. ```
  37. ## Tests
  38. ```sh
  39. npm test
  40. ```