[Pkg-javascript-commits] [node-object-assign] 01/03: Import Upstream version 4.1.0

Sruthi Chandran srud-guest at moszumanska.debian.org
Mon Aug 29 07:24:49 UTC 2016


This is an automated email from the git hooks/post-receive script.

srud-guest pushed a commit to branch master
in repository node-object-assign.

commit c53ae884af8dedc340dfab519ecd73954690ad33
Author: Sruthi <srud at disroot.org>
Date:   Mon Aug 29 11:54:38 2016 +0530

    Import Upstream version 4.1.0
---
 .editorconfig  |  12 +++++++
 .gitattributes |   1 +
 .gitignore     |   1 +
 .travis.yml    |   7 ++++
 bench.js       |  55 ++++++++++++++++++++++++++++
 index.js       |  83 ++++++++++++++++++++++++++++++++++++++++++
 license        |  21 +++++++++++
 package.json   |  42 ++++++++++++++++++++++
 readme.md      |  56 +++++++++++++++++++++++++++++
 test.js        | 111 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 10 files changed, 389 insertions(+)

diff --git a/.editorconfig b/.editorconfig
new file mode 100644
index 0000000..98a761d
--- /dev/null
+++ b/.editorconfig
@@ -0,0 +1,12 @@
+root = true
+
+[*]
+indent_style = tab
+end_of_line = lf
+charset = utf-8
+trim_trailing_whitespace = true
+insert_final_newline = true
+
+[{package.json,*.yml}]
+indent_style = space
+indent_size = 2
diff --git a/.gitattributes b/.gitattributes
new file mode 100644
index 0000000..176a458
--- /dev/null
+++ b/.gitattributes
@@ -0,0 +1 @@
+* text=auto
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..3c3629e
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+node_modules
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..a78e23d
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,7 @@
+sudo: false
+language: node_js
+node_js:
+  - '5'
+  - '4'
+  - '0.12'
+  - '0.10'
diff --git a/bench.js b/bench.js
new file mode 100644
index 0000000..a9df2d1
--- /dev/null
+++ b/bench.js
@@ -0,0 +1,55 @@
+'use strict';
+/* globals bench suite */
+var lodash = require('lodash');
+var objectAssign = require('./');
+
+var source1 = {
+	a: 1,
+	b: 2,
+	c: 3
+};
+
+var source2 = {
+	c: 3,
+	d: 4,
+	e: 5,
+	f: 6,
+	g: 7,
+	h: 8,
+	i: 9,
+	j: 10,
+	k: 11,
+	l: 12,
+	m: 13,
+	n: 15,
+	o: 15,
+	p: 16
+};
+
+suite('object-assign', function () {
+	bench('small', function () {
+		objectAssign({foo: 0}, {bar: 1});
+	});
+
+	bench('default options', function () {
+		objectAssign({}, {foo: 0}, {foo: 1});
+	});
+
+	bench('big', function () {
+		objectAssign({}, source1, source2);
+	});
+});
+
+suite('lodash', function () {
+	bench('small', function () {
+		lodash.assign({foo: 0}, {bar: 1});
+	});
+
+	bench('default options', function () {
+		lodash.assign({}, {foo: 0}, {foo: 1});
+	});
+
+	bench('big', function () {
+		lodash.assign({}, source1, source2);
+	});
+});
diff --git a/index.js b/index.js
new file mode 100644
index 0000000..5085048
--- /dev/null
+++ b/index.js
@@ -0,0 +1,83 @@
+'use strict';
+/* eslint-disable no-unused-vars */
+var hasOwnProperty = Object.prototype.hasOwnProperty;
+var propIsEnumerable = Object.prototype.propertyIsEnumerable;
+
+function toObject(val) {
+	if (val === null || val === undefined) {
+		throw new TypeError('Object.assign cannot be called with null or undefined');
+	}
+
+	return Object(val);
+}
+
+function shouldUseNative() {
+	try {
+		if (!Object.assign) {
+			return false;
+		}
+
+		// Detect buggy property enumeration order in older V8 versions.
+
+		// https://bugs.chromium.org/p/v8/issues/detail?id=4118
+		var test1 = new String('abc');  // eslint-disable-line
+		test1[5] = 'de';
+		if (Object.getOwnPropertyNames(test1)[0] === '5') {
+			return false;
+		}
+
+		// https://bugs.chromium.org/p/v8/issues/detail?id=3056
+		var test2 = {};
+		for (var i = 0; i < 10; i++) {
+			test2['_' + String.fromCharCode(i)] = i;
+		}
+		var order2 = Object.getOwnPropertyNames(test2).map(function (n) {
+			return test2[n];
+		});
+		if (order2.join('') !== '0123456789') {
+			return false;
+		}
+
+		// https://bugs.chromium.org/p/v8/issues/detail?id=3056
+		var test3 = {};
+		'abcdefghijklmnopqrst'.split('').forEach(function (letter) {
+			test3[letter] = letter;
+		});
+		if (Object.keys(Object.assign({}, test3)).join('') !==
+				'abcdefghijklmnopqrst') {
+			return false;
+		}
+
+		return true;
+	} catch (e) {
+		// We don't expect any of the above to throw, but better to be safe.
+		return false;
+	}
+}
+
+module.exports = shouldUseNative() ? Object.assign : function (target, source) {
+	var from;
+	var to = toObject(target);
+	var symbols;
+
+	for (var s = 1; s < arguments.length; s++) {
+		from = Object(arguments[s]);
+
+		for (var key in from) {
+			if (hasOwnProperty.call(from, key)) {
+				to[key] = from[key];
+			}
+		}
+
+		if (Object.getOwnPropertySymbols) {
+			symbols = Object.getOwnPropertySymbols(from);
+			for (var i = 0; i < symbols.length; i++) {
+				if (propIsEnumerable.call(from, symbols[i])) {
+					to[symbols[i]] = from[symbols[i]];
+				}
+			}
+		}
+	}
+
+	return to;
+};
diff --git a/license b/license
new file mode 100644
index 0000000..654d0bf
--- /dev/null
+++ b/license
@@ -0,0 +1,21 @@
+The MIT License (MIT)
+
+Copyright (c) Sindre Sorhus <sindresorhus at gmail.com> (sindresorhus.com)
+
+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.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
diff --git a/package.json b/package.json
new file mode 100644
index 0000000..a25d428
--- /dev/null
+++ b/package.json
@@ -0,0 +1,42 @@
+{
+  "name": "object-assign",
+  "version": "4.1.0",
+  "description": "ES2015 Object.assign() ponyfill",
+  "license": "MIT",
+  "repository": "sindresorhus/object-assign",
+  "author": {
+    "name": "Sindre Sorhus",
+    "email": "sindresorhus at gmail.com",
+    "url": "sindresorhus.com"
+  },
+  "engines": {
+    "node": ">=0.10.0"
+  },
+  "scripts": {
+    "test": "xo && mocha",
+    "bench": "matcha bench.js"
+  },
+  "files": [
+    "index.js"
+  ],
+  "keywords": [
+    "object",
+    "assign",
+    "extend",
+    "properties",
+    "es2015",
+    "ecmascript",
+    "harmony",
+    "ponyfill",
+    "prollyfill",
+    "polyfill",
+    "shim",
+    "browser"
+  ],
+  "devDependencies": {
+    "lodash": "^4.8.2",
+    "matcha": "^0.7.0",
+    "mocha": "*",
+    "xo": "*"
+  }
+}
diff --git a/readme.md b/readme.md
new file mode 100644
index 0000000..13c0977
--- /dev/null
+++ b/readme.md
@@ -0,0 +1,56 @@
+# object-assign [![Build Status](https://travis-ci.org/sindresorhus/object-assign.svg?branch=master)](https://travis-ci.org/sindresorhus/object-assign)
+
+> ES2015 [`Object.assign()`](http://www.2ality.com/2014/01/object-assign.html) ponyfill
+
+> Ponyfill: A polyfill that doesn't overwrite the native method
+
+
+## Install
+
+```
+$ npm install --save object-assign
+```
+
+
+## Usage
+
+```js
+const objectAssign = require('object-assign');
+
+objectAssign({foo: 0}, {bar: 1});
+//=> {foo: 0, bar: 1}
+
+// multiple sources
+objectAssign({foo: 0}, {bar: 1}, {baz: 2});
+//=> {foo: 0, bar: 1, baz: 2}
+
+// overwrites equal keys
+objectAssign({foo: 0}, {foo: 1}, {foo: 2});
+//=> {foo: 2}
+
+// ignores null and undefined sources
+objectAssign({foo: 0}, null, {bar: 1}, undefined);
+//=> {foo: 0, bar: 1}
+```
+
+
+## API
+
+### objectAssign(target, source, [source, ...])
+
+Assigns enumerable own properties of `source` objects to the `target` object and returns the `target` object. Additional `source` objects will overwrite previous ones.
+
+
+## Resources
+
+- [ES2015 spec - Object.assign](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-object.assign)
+
+
+## Related
+
+- [deep-assign](https://github.com/sindresorhus/deep-assign) - Recursive `Object.assign()`
+
+
+## License
+
+MIT © [Sindre Sorhus](https://sindresorhus.com)
diff --git a/test.js b/test.js
new file mode 100644
index 0000000..9719c2c
--- /dev/null
+++ b/test.js
@@ -0,0 +1,111 @@
+'use strict';
+/* eslint-env mocha */
+var assert = require('assert');
+Object.assign = undefined;
+var objectAssign = require('./');
+
+it('should have the correct length', function () {
+	assert.equal(objectAssign.length, 2);
+});
+
+it('should throw when target is not an object', function () {
+	assert.throws(function () {
+		objectAssign(null);
+	}, TypeError);
+	assert.throws(function () {
+		objectAssign(undefined);
+	}, TypeError);
+});
+
+it('should objectAssign own enumerable properties from source to target object', function () {
+	assert.deepEqual(objectAssign({foo: 0}, {bar: 1}), {foo: 0, bar: 1});
+	assert.deepEqual(objectAssign({foo: 0}, null, undefined), {foo: 0});
+	assert.deepEqual(objectAssign({foo: 0}, null, undefined, {bar: 1}, null), {foo: 0, bar: 1});
+});
+
+it('should throw on null/undefined target', function () {
+	assert.throws(function () {
+		objectAssign(null, {});
+	});
+
+	assert.throws(function () {
+		objectAssign(undefined, {});
+	});
+
+	assert.throws(function () {
+		objectAssign(undefined, undefined);
+	});
+});
+
+it('should not throw on null/undefined sources', function () {
+	assert.doesNotThrow(function () {
+		objectAssign({}, null);
+	});
+
+	assert.doesNotThrow(function () {
+		objectAssign({}, undefined);
+	});
+
+	assert.doesNotThrow(function () {
+		objectAssign({}, undefined, null);
+	});
+});
+
+it('should support multiple sources', function () {
+	assert.deepEqual(objectAssign({foo: 0}, {bar: 1}, {bar: 2}), {foo: 0, bar: 2});
+	assert.deepEqual(objectAssign({}, {}, {foo: 1}), {foo: 1});
+});
+
+it('should only iterate own keys', function () {
+	var Unicorn = function () {};
+	Unicorn.prototype.rainbows = 'many';
+	var unicorn = new Unicorn();
+	unicorn.bar = 1;
+
+	assert.deepEqual(objectAssign({foo: 1}, unicorn), {foo: 1, bar: 1});
+});
+
+it('should return the modified target object', function () {
+	var target = {};
+	var returned = objectAssign(target, {a: 1});
+	assert.equal(returned, target);
+});
+
+it('should support `Object.create(null)` objects', function () {
+	var obj = Object.create(null);
+	obj.foo = true;
+	assert.deepEqual(objectAssign({}, obj), {foo: true});
+});
+
+it('should preserve property order', function () {
+	var letters = 'abcdefghijklmnopqrst';
+	var source = {};
+	letters.split('').forEach(function (letter) {
+		source[letter] = letter;
+	});
+	var target = objectAssign({}, source);
+	assert.equal(Object.keys(target).join(''), letters);
+});
+
+if (typeof Symbol !== 'undefined') {
+	it('should support symbol properties', function () {
+		var target = {};
+		var source = {};
+		var sym = Symbol('foo');
+		source[sym] = 'bar';
+		objectAssign(target, source);
+		assert.equal(target[sym], 'bar');
+	});
+
+	it('should only copy enumerable symbols', function () {
+		var target = {};
+		var source = {};
+		var sym = Symbol('foo');
+		Object.defineProperty(source, sym, {
+			enumerable: false,
+			value: 'bar'
+		});
+		objectAssign(target, source);
+		assert.equal(target[sym], undefined);
+	});
+}

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-object-assign.git



More information about the Pkg-javascript-commits mailing list