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 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. [![Build Status][travis-svg]][travis-url]
  2. [![dependency status][deps-svg]][deps-url]
  3. [![dev dependency status][dev-deps-svg]][dev-deps-url]
  4. # extend() for Node.js <sup>[![Version Badge][npm-version-png]][npm-url]</sup>
  5. `node-extend` is a port of the classic extend() method from jQuery. It behaves as you expect. It is simple, tried and true.
  6. Notes:
  7. * Since Node.js >= 4,
  8. [`Object.assign`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign)
  9. now offers the same functionality natively (but without the "deep copy" option).
  10. See [ECMAScript 2015 (ES6) in Node.js](https://nodejs.org/en/docs/es6).
  11. * Some native implementations of `Object.assign` in both Node.js and many
  12. browsers (since NPM modules are for the browser too) may not be fully
  13. spec-compliant.
  14. Check [`object.assign`](https://www.npmjs.com/package/object.assign) module for
  15. a compliant candidate.
  16. ## Installation
  17. This package is available on [npm][npm-url] as: `extend`
  18. ``` sh
  19. npm install extend
  20. ```
  21. ## Usage
  22. **Syntax:** extend **(** [`deep`], `target`, `object1`, [`objectN`] **)**
  23. *Extend one object with one or more others, returning the modified object.*
  24. **Example:**
  25. ``` js
  26. var extend = require('extend');
  27. extend(targetObject, object1, object2);
  28. ```
  29. Keep in mind that the target object will be modified, and will be returned from extend().
  30. If a boolean true is specified as the first argument, extend performs a deep copy, recursively copying any objects it finds. Otherwise, the copy will share structure with the original object(s).
  31. Undefined properties are not copied. However, properties inherited from the object's prototype will be copied over.
  32. Warning: passing `false` as the first argument is not supported.
  33. ### Arguments
  34. * `deep` *Boolean* (optional)
  35. If set, the merge becomes recursive (i.e. deep copy).
  36. * `target` *Object*
  37. The object to extend.
  38. * `object1` *Object*
  39. The object that will be merged into the first.
  40. * `objectN` *Object* (Optional)
  41. More objects to merge into the first.
  42. ## License
  43. `node-extend` is licensed under the [MIT License][mit-license-url].
  44. ## Acknowledgements
  45. All credit to the jQuery authors for perfecting this amazing utility.
  46. Ported to Node.js by [Stefan Thomas][github-justmoon] with contributions by [Jonathan Buchanan][github-insin] and [Jordan Harband][github-ljharb].
  47. [travis-svg]: https://travis-ci.org/justmoon/node-extend.svg
  48. [travis-url]: https://travis-ci.org/justmoon/node-extend
  49. [npm-url]: https://npmjs.org/package/extend
  50. [mit-license-url]: http://opensource.org/licenses/MIT
  51. [github-justmoon]: https://github.com/justmoon
  52. [github-insin]: https://github.com/insin
  53. [github-ljharb]: https://github.com/ljharb
  54. [npm-version-png]: http://versionbadg.es/justmoon/node-extend.svg
  55. [deps-svg]: https://david-dm.org/justmoon/node-extend.svg
  56. [deps-url]: https://david-dm.org/justmoon/node-extend
  57. [dev-deps-svg]: https://david-dm.org/justmoon/node-extend/dev-status.svg
  58. [dev-deps-url]: https://david-dm.org/justmoon/node-extend#info=devDependencies