Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

extend

justmoon92.2mMIT3.0.2TypeScript support: definitely-typed

Port of jQuery.extend for node.js and the browser

extend, clone, merge

readme

Build Status dependency status dev dependency status

extend() for Node.js Version Badge

node-extend is a port of the classic extend() method from jQuery. It behaves as you expect. It is simple, tried and true.

Notes:

  • Since Node.js >= 4, Object.assign now offers the same functionality natively (but without the "deep copy" option). See ECMAScript 2015 (ES6) in Node.js.
  • Some native implementations of Object.assign in both Node.js and many browsers (since NPM modules are for the browser too) may not be fully spec-compliant. Check object.assign module for a compliant candidate.

Installation

This package is available on npm as: extend

npm install extend

Usage

Syntax: extend (** [deep], target, object1, [objectN] **)

Extend one object with one or more others, returning the modified object.

Example:

var extend = require('extend');
extend(targetObject, object1, object2);

Keep in mind that the target object will be modified, and will be returned from extend().

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). Undefined properties are not copied. However, properties inherited from the object's prototype will be copied over. Warning: passing false as the first argument is not supported.

Arguments

  • deep Boolean (optional) If set, the merge becomes recursive (i.e. deep copy).
  • target Object The object to extend.
  • object1 Object The object that will be merged into the first.
  • objectN Object (Optional) More objects to merge into the first.

License

node-extend is licensed under the MIT License.

Acknowledgements

All credit to the jQuery authors for perfecting this amazing utility.

Ported to Node.js by Stefan Thomas with contributions by Jonathan Buchanan and Jordan Harband.

changelog

3.0.2 / 2018-07-19

  • [Fix] Prevent merging __proto__ property (#48)
  • [Dev Deps] update eslint, @ljharb/eslint-config, tape
  • [Tests] up to node v10.7, v9.11, v8.11, v7.10, v6.14, v4.9; use nvm install-latest-npm

3.0.1 / 2017-04-27

  • [Fix] deep extending should work with a non-object (#46)
  • [Dev Deps] update tape, eslint, @ljharb/eslint-config
  • [Tests] up to node v7.9, v6.10, v4.8; improve matrix
  • [Docs] Switch from vb.teelaun.ch to versionbadg.es for the npm version badge SVG.
  • [Docs] Add example to readme (#34)

3.0.0 / 2015-07-01

  • [Possible breaking change] Use global "strict" directive (#32)
  • [Tests] int is an ES3 reserved word
  • [Tests] Test up to io.js v2.3
  • [Tests] Add npm run eslint
  • [Dev Deps] Update covert, jscs

2.0.1 / 2015-04-25

  • Use an inline isArray check, for ES3 browsers. (#27)
  • Some old browsers fail when an identifier is toString
  • Test latest node and io.js versions on travis-ci; speed up builds
  • Add license info to package.json (#25)
  • Update tape, jscs
  • Adding a CHANGELOG

2.0.0 / 2014-10-01

  • Increase code coverage to 100%; run code coverage as part of tests
  • Add npm run lint; Run linter as part of tests
  • Remove nodeType and setInterval checks in isPlainObject
  • Updating tape, jscs, covert
  • General style and README cleanup

1.3.0 / 2014-06-20

  • Add component.json for browser support (#18)
  • Use SVG for badges in README (#16)
  • Updating tape, covert
  • Updating travis-ci to work with multiple node versions
  • Fix deep === false bug (returning target as {}) (#14)
  • Fixing constructor checks in isPlainObject
  • Adding additional test coverage
  • Adding npm run coverage
  • Add LICENSE (#13)
  • Adding a warning about false, per #11
  • General style and whitespace cleanup

1.2.1 / 2013-09-14

  • Fixing hasOwnProperty bugs that would only have shown up in specific browsers. Fixes #8
  • Updating tape

1.2.0 / 2013-09-02

  • Updating the README: add badges
  • Adding a missing variable reference.
  • Using tape instead of buster for tests; add more tests (#7)
  • Adding node 0.10 to Travis CI (#6)
  • Enabling "npm test" and cleaning up package.json (#5)
  • Add Travis CI.

1.1.3 / 2012-12-06

  • Added unit tests.
  • Ensure extend function is named. (Looks nicer in a stack trace.)
  • README cleanup.

1.1.1 / 2012-11-07

  • README cleanup.
  • Added installation instructions.
  • Added a missing semicolon

1.0.0 / 2012-04-08

  • Initial commit