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

Package detail

object-assign-shim

BendingBender258MIT1.0.0

ES6 spec-compliant Object.assign shim. Shims Object constructor automatically.

Object.assign, assign, ES6, extend, $.extend, jQuery, _.extend, Underscore

readme

Object.assign shim

An Object.assign shim for ES5-compliant environments (browsers/node.js/io.js). Is applied only when needed with a few exceptions for non-compliant implementations.

Takes a minimum of 2 arguments: target and source. Takes a variable sized list of source arguments - at least 1, as many as you want. Throws a TypeError if the target argument is null or undefined.

Most common usage:

In node/io.js:

require('object-assign-shim');

In a browser:

<script src="object-assign-shim/index.js"></script>

Example

// Multiple sources!
var target = { a: true };
var source1 = { b: true };
var source2 = { c: true };
var sourceN = { n: true };

var expected = {
    a: true,
    b: true,
    c: true,
    n: true
};

require('object-assign-shim');
var assert = require('assert');

Object.assign(target, source1, source2, sourceN);
assert.deepEqual(target, expected); // AWESOME!
require('object-assign-shim');
var assert = require('assert');
var target = {
    a: true,
    b: true,
    c: true
};
var source1 = {
    c: false,
    d: false
};
var sourceN = {
    e: false
};

var assigned = Object.assign(target, source1, sourceN);
assert.equal(target, assigned); // returns the target object
assert.deepEqual(assigned, {
    a: true,
    b: true,
    c: false,
    d: false,
    e: false
});
var assert = require('assert');
/* when Object.assign is not present */
delete Object.assign;
require('object-assign-shim');
assert.equal(typeof Object.assign, "function");

var target = {
    a: true,
    b: true,
    c: true
};
var source = {
    c: false,
    d: false,
    e: false
};

var assigned = assign(target, source);
assert.deepEqual(Object.assign(target, source), assign(target, source));
var assert = require('assert');
/* when Object.assign is present */
assert.equal(typeof Object.assign, 'function');
var builtinAssign = Object.assign;
require('object-assign-shim');
assert.equal(builtinAssign, Object.assign);

Tests

Simply clone the repo, npm install, and run npm test

changelog

object-assign-shim - 1.0.0 / 2015-04-15

  • removed all calls to require
  • module now has no dependencies, it now only runs in ES5+ environments
  • removed optional shimming, shim is instead applied when necessary

============== Fork ==============

object.assign - 2.0.1 / 2015-04-12

  • Make sure non-enumerable Symbols are excluded.

object.assign - 2.0.0 / 2015-04-12

  • Make sure the shim function overwrites a broken implementation with pending exceptions.
  • Ensure shim is not enumerable using define-properties
  • Ensure Object.assign includes symbols.
  • All grade A-supported node/iojs versions now ship with an npm that understands ^.
  • Run travis-ci tests on iojs and node v0.12; speed up builds; allow 0.8 failures.
  • Add npm run security via nsp
  • Update browserify, jscs, tape, object-keys, is

object.assign - 1.1.1 / 2014-12-14

  • Actually include the browser build in npm

object.assign - 1.1.0 / 2014-12-14

  • Add npm run build, and build an automatic-shimming browser distribution as part of the npm publish process.
  • Update is, jscs

object.assign - 1.0.3 / 2014-11-29

  • Revert "optimize --production installs"

object.assign - 1.0.2 / 2014-11-27

  • Update jscs, is, object-keys, tape
  • Add badges to README
  • Name URLs in README
  • Lock covert to v1.0.0
  • Optimize --production installs

object.assign - 1.0.1 / 2014-08-26

  • Update is, covert

object.assign - 1.0.0 / 2014-08-07

  • Update object-keys, tape

object.assign - 0.5.0 / 2014-07-31

object.assign - 0.4.3 / 2014-07-30

  • Don’t modify vars in the function signature, since it deoptimizes v8

object.assign - 0.4.2 / 2014-07-30

  • Fixing the version number: v0.4.2

object.assign - 0.4.1 / 2014-07-19

  • Revert "Use the native Object.keys if it’s available."

object.assign - 0.4.0 / 2014-07-19

  • Use the native Object.keys if it’s available.
  • Fixes #2.
  • Adding failing tests for #2.
  • Fix indentation.
  • Adding npm run lint
  • Update tape, covert
  • README: Use SVG badge for Travis #1 from mathiasbynens/patch-1

object.assign - 0.3.1 / 2014-04-10

object.assign - 0.3.0 / 2014-04-10

  • Update with newest ES6 behavior - Object.assign now takes a variable number of source objects.
  • Update tape
  • Make sure old and unstable nodes don’t fail Travis

object.assign - 0.2.1 / 2014-03-16

  • Let object-keys handle the fallback
  • Update dependency badges
  • Adding bower.json

object.assign - 0.2.0 / 2014-03-16

  • Use a for loop, because ES3 browsers don’t have "reduce"

object.assign - 0.1.1 / 2014-03-14

  • Updating readme

object.assign - 0.1.0 / 2014-03-14

  • Initial release.