[Pkg-javascript-commits] [node-extend-shallow] 01/04: Import Upstream version 2.0.1
Praveen Arimbrathodiyil
praveen at moszumanska.debian.org
Mon Oct 17 12:01:45 UTC 2016
This is an automated email from the git hooks/post-receive script.
praveen pushed a commit to branch master
in repository node-extend-shallow.
commit 42da98c669056c83310377b8008dc4104d498f34
Author: Praveen Arimbrathodiyil <praveen at debian.org>
Date: Mon Oct 17 17:13:12 2016 +0530
Import Upstream version 2.0.1
---
.editorconfig | 17 +++++++++
.gitattributes | 10 ++++++
.gitignore | 53 ++++++++++++++++++++++++++++
.jshintrc | 18 ++++++++++
.travis.yml | 8 +++++
.verb.md | 39 +++++++++++++++++++++
LICENSE | 21 +++++++++++
README.md | 61 ++++++++++++++++++++++++++++++++
benchmark/check.js | 21 +++++++++++
benchmark/code/1-1-4.js | 36 +++++++++++++++++++
benchmark/code/_current.js | 3 ++
benchmark/code/assign.js | 25 +++++++++++++
benchmark/code/for-arguments-in.js | 28 +++++++++++++++
benchmark/code/for-arguments.js | 21 +++++++++++
benchmark/code/for-each.js | 22 ++++++++++++
benchmark/code/for-negative.js | 23 ++++++++++++
benchmark/code/for-own-lib.js | 21 +++++++++++
benchmark/code/for-own-slice-call.js | 20 +++++++++++
benchmark/code/for-own.js | 23 ++++++++++++
benchmark/code/for-prop-in.js | 21 +++++++++++
benchmark/code/for-slice-call-in.js | 18 ++++++++++
benchmark/code/for.js | 20 +++++++++++
benchmark/code/reduce.js | 19 ++++++++++
benchmark/code/while-arguments-in.js | 20 +++++++++++
benchmark/code/while-for-own.js | 26 ++++++++++++++
benchmark/code/while-for.js | 24 +++++++++++++
benchmark/code/while-while.js | 24 +++++++++++++
benchmark/code/while-while2.js | 24 +++++++++++++
benchmark/code/while.js | 24 +++++++++++++
benchmark/fixtures/basic.js | 1 +
benchmark/fixtures/nested.js | 7 ++++
benchmark/index.js | 23 ++++++++++++
benchmark/support.js | 31 ++++++++++++++++
bower.json | 47 +++++++++++++++++++++++++
index.js | 33 +++++++++++++++++
package.json | 56 +++++++++++++++++++++++++++++
test.js | 68 ++++++++++++++++++++++++++++++++++++
37 files changed, 956 insertions(+)
diff --git a/.editorconfig b/.editorconfig
new file mode 100644
index 0000000..2eed47c
--- /dev/null
+++ b/.editorconfig
@@ -0,0 +1,17 @@
+# http://editorconfig.org
+root = true
+
+[*]
+indent_style = space
+indent_size = 2
+end_of_line = lf
+charset = utf-8
+trim_trailing_whitespace = true
+insert_final_newline = true
+
+[*.md]
+trim_trailing_whitespace = false
+
+[test/fixtures/*]
+insert_final_newline = false
+trim_trailing_whitespace = false
\ No newline at end of file
diff --git a/.gitattributes b/.gitattributes
new file mode 100644
index 0000000..4a3f1d3
--- /dev/null
+++ b/.gitattributes
@@ -0,0 +1,10 @@
+# Enforce Unix newlines
+* text eol=lf
+
+# binaries
+*.ai binary
+*.psd binary
+*.jpg binary
+*.gif binary
+*.png binary
+*.jpeg binary
\ No newline at end of file
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..92139bd
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,53 @@
+# Numerous always-ignore extensions
+*.DS_Store
+*.csv
+*.dat
+*.diff
+*.err
+*.gz
+*.log
+*.orig
+*.out
+*.pid
+*.rar
+*.rej
+*.seed
+*.swo
+*.swp
+*.vi
+*.yo-rc.json
+*.zip
+*~
+.ruby-version
+lib-cov
+npm-debug.log
+
+# Always-ignore dirs
+/bower_components/
+/node_modules/
+/temp/
+/tmp/
+/vendor/
+_gh_pages
+
+# OS or Editor folders
+*.esproj
+*.komodoproject
+.komodotools
+*.sublime-*
+._*
+.cache
+.DS_Store
+.idea
+.project
+.settings
+.tmproj
+nbproject
+Thumbs.db
+
+# grunt-html-validation
+validation-status.json
+validation-report.json
+
+# misc
+TODO.md
\ No newline at end of file
diff --git a/.jshintrc b/.jshintrc
new file mode 100644
index 0000000..6e5a84a
--- /dev/null
+++ b/.jshintrc
@@ -0,0 +1,18 @@
+{
+ "asi": false,
+ "boss": true,
+ "curly": true,
+ "eqeqeq": true,
+ "eqnull": true,
+ "esnext": true,
+ "immed": true,
+ "latedef": false,
+ "laxcomma": false,
+ "mocha": true,
+ "newcap": true,
+ "noarg": true,
+ "node": true,
+ "sub": true,
+ "undef": true,
+ "unused": true
+}
\ No newline at end of file
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..f9cffe6
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,8 @@
+sudo: false
+language: node_js
+node_js:
+ - "0.10"
+ - "0.12"
+ - "iojs"
+git:
+ depth: 10
diff --git a/.verb.md b/.verb.md
new file mode 100644
index 0000000..b194a4f
--- /dev/null
+++ b/.verb.md
@@ -0,0 +1,39 @@
+# {%= name %} {%= badge("fury") %} {%= badge("travis") %}
+
+> {%= description %}
+
+## Install
+{%= include("install-npm", {save: true}) %}
+
+## Usage
+
+```js
+var extend = require('{%= name %}');
+
+extend({a: 'b'}, {c: 'd'})
+//=> {a: 'b', c: 'd'}
+```
+
+Pass an empty object to shallow clone:
+
+```js
+var obj = {};
+extend(obj, {a: 'b'}, {c: 'd'})
+//=> {a: 'b', c: 'd'}
+```
+
+## Related
+{%= related(['is-plain-object', 'kind-of', 'for-own', 'extend-shallow', 'isobject', 'for-in']) %}
+## Running tests
+{%= include("tests") %}
+
+## Author
+{%= include("author") %}
+
+## License
+{%= copyright() %}
+{%= license() %}
+
+***
+
+{%= include("footer") %}
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..fa30c4c
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,21 @@
+The MIT License (MIT)
+
+Copyright (c) 2014-2015, Jon Schlinkert.
+
+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/README.md b/README.md
new file mode 100644
index 0000000..cdc45d4
--- /dev/null
+++ b/README.md
@@ -0,0 +1,61 @@
+# extend-shallow [![NPM version](https://badge.fury.io/js/extend-shallow.svg)](http://badge.fury.io/js/extend-shallow) [![Build Status](https://travis-ci.org/jonschlinkert/extend-shallow.svg)](https://travis-ci.org/jonschlinkert/extend-shallow)
+
+> Extend an object with the properties of additional objects. node.js/javascript util.
+
+## Install
+
+Install with [npm](https://www.npmjs.com/)
+
+```sh
+$ npm i extend-shallow --save
+```
+
+## Usage
+
+```js
+var extend = require('extend-shallow');
+
+extend({a: 'b'}, {c: 'd'})
+//=> {a: 'b', c: 'd'}
+```
+
+Pass an empty object to shallow clone:
+
+```js
+var obj = {};
+extend(obj, {a: 'b'}, {c: 'd'})
+//=> {a: 'b', c: 'd'}
+```
+
+## Related
+
+* [extend-shallow](https://github.com/jonschlinkert/extend-shallow): Extend an object with the properties of additional objects. node.js/javascript util.
+* [for-own](https://github.com/jonschlinkert/for-own): Iterate over the own enumerable properties of an object, and return an object with properties… [more](https://github.com/jonschlinkert/for-own)
+* [for-in](https://github.com/jonschlinkert/for-in): Iterate over the own and inherited enumerable properties of an objecte, and return an object… [more](https://github.com/jonschlinkert/for-in)
+* [is-plain-object](https://github.com/jonschlinkert/is-plain-object): Returns true if an object was created by the `Object` constructor.
+* [isobject](https://github.com/jonschlinkert/isobject): Returns true if the value is an object and not an array or null.
+* [kind-of](https://github.com/jonschlinkert/kind-of): Get the native type of a value.
+
+## Running tests
+
+Install dev dependencies:
+
+```sh
+$ npm i -d && npm test
+```
+
+## Author
+
+**Jon Schlinkert**
+
++ [github/jonschlinkert](https://github.com/jonschlinkert)
++ [twitter/jonschlinkert](http://twitter.com/jonschlinkert)
+
+## License
+
+Copyright © 2015 Jon Schlinkert
+Released under the MIT license.
+
+***
+
+_This file was generated by [verb-cli](https://github.com/assemble/verb-cli) on June 29, 2015._
\ No newline at end of file
diff --git a/benchmark/check.js b/benchmark/check.js
new file mode 100644
index 0000000..1905305
--- /dev/null
+++ b/benchmark/check.js
@@ -0,0 +1,21 @@
+'use strict';
+
+var fs = require('fs');
+var path = require('path');
+var chalk = require('chalk');
+var glob = require('glob');
+
+var fixtures = __dirname + '/fixtures';
+var code = __dirname + '/code';
+
+glob.sync('*.js', {cwd: code}).forEach(function (fp) {
+ var fn = require(path.resolve(code, fp));
+ var name = path.basename(fp, path.extname(fp));
+
+ glob.sync('nested.js', {cwd: fixtures}).forEach(function (fixture) {
+ fixture = path.resolve(fixtures, fixture);
+
+ var base = path.basename(fixture, path.extname(fixture));
+ console.log(chalk.bold(name + ' [' + base + ']') + ':', fn.apply(fn, require(fixture)));
+ });
+});
diff --git a/benchmark/code/1-1-4.js b/benchmark/code/1-1-4.js
new file mode 100644
index 0000000..fbe513d
--- /dev/null
+++ b/benchmark/code/1-1-4.js
@@ -0,0 +1,36 @@
+'use strict';
+
+var typeOf = require('kind-of');
+
+/**
+ * Expose `extend`
+ */
+
+module.exports = extend;
+
+/**
+ * Extend `o` with properties of other `objects`.
+ *
+ * @param {Object} `o` The target object. Pass an empty object to shallow clone.
+ * @param {Object} `objects`
+ * @return {Object}
+ */
+
+function extend(o) {
+ if (typeOf(o) !== 'object') { return {}; }
+ var args = arguments;
+ var len = args.length - 1;
+
+ for (var i = 0; i < len; i++) {
+ var obj = args[i + 1];
+
+ if (typeOf(obj) === 'object' && typeOf(obj) !== 'regexp') {
+ for (var key in obj) {
+ if (obj.hasOwnProperty(key)) {
+ o[key] = obj[key];
+ }
+ }
+ }
+ }
+ return o;
+};
diff --git a/benchmark/code/_current.js b/benchmark/code/_current.js
new file mode 100644
index 0000000..0f85e82
--- /dev/null
+++ b/benchmark/code/_current.js
@@ -0,0 +1,3 @@
+'use strict';
+
+module.exports = require('../..');
\ No newline at end of file
diff --git a/benchmark/code/assign.js b/benchmark/code/assign.js
new file mode 100644
index 0000000..1499638
--- /dev/null
+++ b/benchmark/code/assign.js
@@ -0,0 +1,25 @@
+
+var isObject = require('is-plain-object');
+
+module.exports = function extend(a, b) {
+ if (!a) return {};
+ if (!b) return a;
+
+ var len = arguments.length - 1, i = 1;
+ while (len--) {
+ var obj = arguments[i++];
+ if (isObject(obj)) {
+ assign(a, obj);
+ }
+ }
+ return a;
+};
+
+function assign(o, obj) {
+ for (var key in obj) {
+ if (obj.hasOwnProperty(key)) {
+ o[key] = obj[key];
+ }
+ }
+ return o;
+}
\ No newline at end of file
diff --git a/benchmark/code/for-arguments-in.js b/benchmark/code/for-arguments-in.js
new file mode 100644
index 0000000..98b9743
--- /dev/null
+++ b/benchmark/code/for-arguments-in.js
@@ -0,0 +1,28 @@
+'use strict';
+
+var isObject = require('is-extendable');
+
+module.exports = function extend(o, objects) {
+ if (!isObject(o)) { o = {}; }
+
+ var len = arguments.length;
+ for (var i = 1; i < len; i++) {
+ var obj = arguments[i];
+
+ if (isObject(obj)) {
+ assign(o, obj);
+
+ // for (var key in obj) {
+ // o[key] = obj[key];
+ // }
+ }
+ }
+ return o;
+};
+
+
+function assign(a, b) {
+ for (var key in b) {
+ a[key] = b[key];
+ }
+}
diff --git a/benchmark/code/for-arguments.js b/benchmark/code/for-arguments.js
new file mode 100644
index 0000000..83b77ac
--- /dev/null
+++ b/benchmark/code/for-arguments.js
@@ -0,0 +1,21 @@
+'use strict';
+
+var isObject = require('is-plain-object');
+
+module.exports = function extend(o, objects) {
+ if (!o || !objects) { return o || {}; }
+
+ var len = arguments.length - 1;
+ for (var i = 0; i < len; i++) {
+ var obj = arguments[i + 1];
+
+ if (isObject(obj)) {
+ for (var key in obj) {
+ if (obj.hasOwnProperty(key)) {
+ o[key] = obj[key];
+ }
+ }
+ }
+ }
+ return o;
+};
diff --git a/benchmark/code/for-each.js b/benchmark/code/for-each.js
new file mode 100644
index 0000000..7a802ac
--- /dev/null
+++ b/benchmark/code/for-each.js
@@ -0,0 +1,22 @@
+'use strict';
+
+var isObject = require('is-extendable');
+
+module.exports = function extend(o, objects) {
+ if (!isObject(o)) {o = {};}
+
+ var args = [].slice.call(arguments);
+
+ args.forEach(function (obj) {
+ if (isObject(obj)) {
+ for (var key in obj) {
+ if (obj.hasOwnProperty(key)) {
+ o[key] = obj[key];
+ }
+ }
+ }
+ });
+
+ return o;
+};
+
diff --git a/benchmark/code/for-negative.js b/benchmark/code/for-negative.js
new file mode 100644
index 0000000..d6892f3
--- /dev/null
+++ b/benchmark/code/for-negative.js
@@ -0,0 +1,23 @@
+'use strict';
+
+var slice = require('array-slice');
+
+module.exports = function extend(o, objects) {
+ if (o == null) { return {}; }
+ if (objects == null) { return o; }
+
+ var args = slice(arguments, 1);
+ var len = args.length - 1;
+
+ for (var i = len; i >= 0; i--) {
+ var obj = args[i];
+
+ for (var key in obj) {
+ if (obj.hasOwnProperty(key)) {
+ o[key] = obj[key];
+ }
+ }
+ }
+
+ return o;
+};
\ No newline at end of file
diff --git a/benchmark/code/for-own-lib.js b/benchmark/code/for-own-lib.js
new file mode 100644
index 0000000..294213f
--- /dev/null
+++ b/benchmark/code/for-own-lib.js
@@ -0,0 +1,21 @@
+'use strict';
+
+var slice = require('array-slice');
+var forOwn = require('for-own');
+
+module.exports = function extend(o, objects) {
+ if (o == null) { return {}; }
+ if (objects == null) { return o; }
+
+ var args = slice(arguments, 1);
+ var len = args.length;
+
+ for (var i = 0; i < len; i++) {
+ var obj = args[i];
+ forOwn(obj, function (value, key) {
+ this[key] = value;
+ }, o);
+ }
+
+ return o;
+};
diff --git a/benchmark/code/for-own-slice-call.js b/benchmark/code/for-own-slice-call.js
new file mode 100644
index 0000000..ad0e434
--- /dev/null
+++ b/benchmark/code/for-own-slice-call.js
@@ -0,0 +1,20 @@
+'use strict';
+
+module.exports = function extend(o, objects) {
+ if (o == null) { return {}; }
+ if (objects == null) { return o; }
+
+ var args = [].slice.call([], arguments, 1);
+ var len = args.length;
+
+ for (var i = 0; i < len; i++) {
+ var obj = args[i];
+
+ for (var key in obj) {
+ if (obj.hasOwnProperty(key)) {
+ o[key] = obj[key];
+ }
+ }
+ }
+ return o;
+};
diff --git a/benchmark/code/for-own.js b/benchmark/code/for-own.js
new file mode 100644
index 0000000..afd6b2f
--- /dev/null
+++ b/benchmark/code/for-own.js
@@ -0,0 +1,23 @@
+'use strict';
+
+var slice = require('array-slice');
+
+module.exports = function extend(o, objects) {
+ if (o == null) { return {}; }
+ if (objects == null) { return o; }
+
+ var args = slice(arguments, 1);
+ var len = args.length;
+
+ for (var i = 0; i < len; i++) {
+ var obj = args[i];
+
+ for (var key in obj) {
+ if (obj.hasOwnProperty(key)) {
+ o[key] = obj[key];
+ }
+ }
+ }
+
+ return o;
+};
diff --git a/benchmark/code/for-prop-in.js b/benchmark/code/for-prop-in.js
new file mode 100644
index 0000000..ae8d141
--- /dev/null
+++ b/benchmark/code/for-prop-in.js
@@ -0,0 +1,21 @@
+'use strict';
+
+var slice = require('array-slice');
+
+module.exports = function extend(o, objects) {
+ if (o == null) { return {}; }
+ if (objects == null) { return o; }
+
+ var args = slice(arguments, 1);
+ var len = args.length;
+
+ for (var i = 0; i < len; i++) {
+ var obj = args[i];
+
+ for (var key in obj) {
+ o[key] = obj[key];
+ }
+ }
+
+ return o;
+};
diff --git a/benchmark/code/for-slice-call-in.js b/benchmark/code/for-slice-call-in.js
new file mode 100644
index 0000000..dee8f2d
--- /dev/null
+++ b/benchmark/code/for-slice-call-in.js
@@ -0,0 +1,18 @@
+'use strict';
+
+module.exports = function extend(o, objects) {
+ if (o == null) { return {}; }
+ if (objects == null) { return o; }
+
+ var args = [].slice.call([], arguments, 1);
+ var len = args.length;
+
+ for (var i = 0; i < len; i++) {
+ var obj = args[i];
+
+ for (var key in obj) {
+ o[key] = obj[key];
+ }
+ }
+ return o;
+};
diff --git a/benchmark/code/for.js b/benchmark/code/for.js
new file mode 100644
index 0000000..7e56118
--- /dev/null
+++ b/benchmark/code/for.js
@@ -0,0 +1,20 @@
+'use strict';
+
+var isObject = require('is-extendable');
+
+module.exports = function extend(o, objects) {
+ if (!isObject(o)) {o = {};}
+ var len = arguments.length;
+
+ for (var i = 1; i < len; i++) {
+ var obj = arguments[i];
+ if (isObject(obj)) {
+ for (var key in obj) {
+ if (obj.hasOwnProperty(key)) {
+ o[key] = obj[key];
+ }
+ }
+ }
+ }
+ return o;
+};
diff --git a/benchmark/code/reduce.js b/benchmark/code/reduce.js
new file mode 100644
index 0000000..a260dd9
--- /dev/null
+++ b/benchmark/code/reduce.js
@@ -0,0 +1,19 @@
+'use strict';
+
+var isObject = require('is-extendable');
+
+module.exports = function extend(o, objects) {
+ if (!isObject(o)) {o = {};}
+ var args = [].slice.call(arguments, 1);
+
+ return args.reduce(function (acc, val, i) {
+ if (isObject(val)) {
+ for (var key in val) {
+ if (val.hasOwnProperty(key)) {
+ acc[key] = val[key];
+ }
+ }
+ }
+ return acc;
+ }, o);
+};
diff --git a/benchmark/code/while-arguments-in.js b/benchmark/code/while-arguments-in.js
new file mode 100644
index 0000000..c0c3665
--- /dev/null
+++ b/benchmark/code/while-arguments-in.js
@@ -0,0 +1,20 @@
+'use strict';
+
+var isObject = require('is-extendable');
+
+module.exports = function extend(o, objects) {
+ if (!isObject(o)) { o = {}; }
+
+ var len = arguments.length, i = 1;
+ while (len--) {
+ var obj = arguments[i++];
+
+ if (isObject(obj)) {
+
+ for (var key in obj) {
+ o[key] = obj[key];
+ }
+ }
+ }
+ return o;
+};
diff --git a/benchmark/code/while-for-own.js b/benchmark/code/while-for-own.js
new file mode 100644
index 0000000..adf4a5d
--- /dev/null
+++ b/benchmark/code/while-for-own.js
@@ -0,0 +1,26 @@
+'use strict';
+
+var isObject = require('is-extendable');
+
+module.exports = function extend(o, objects) {
+ if (!isObject(o)) {o = {};}
+
+ var len = arguments.length;
+ var i = 1;
+
+ while (len--) {
+ var obj = arguments[i++];
+ if (isObject(obj)) {
+ var keys = Object.keys(obj);
+ var klen = keys.length;
+
+ for (var j = 0; j < klen; j++) {
+ var key = keys[j];
+ if (obj.hasOwnProperty(key)) {
+ o[key] = obj[key];
+ }
+ }
+ }
+ }
+ return o;
+};
diff --git a/benchmark/code/while-for.js b/benchmark/code/while-for.js
new file mode 100644
index 0000000..1fbd1aa
--- /dev/null
+++ b/benchmark/code/while-for.js
@@ -0,0 +1,24 @@
+'use strict';
+
+var isObject = require('is-extendable');
+
+module.exports = function extend(o, objects) {
+ if (!isObject(o)) {o = {};}
+
+ var len = arguments.length;
+ var i = 1;
+
+ while (len--) {
+ var obj = arguments[i++];
+ if (isObject(obj)) {
+ var keys = Object.keys(obj);
+ var klen = keys.length;
+
+ for (var j = 0; j < klen; j++) {
+ var key = keys[j];
+ o[key] = obj[key];
+ }
+ }
+ }
+ return o;
+};
diff --git a/benchmark/code/while-while.js b/benchmark/code/while-while.js
new file mode 100644
index 0000000..3dcc842
--- /dev/null
+++ b/benchmark/code/while-while.js
@@ -0,0 +1,24 @@
+'use strict';
+
+var isObject = require('is-extendable');
+
+module.exports = function extend(o, objects) {
+ if (!isObject(o)) {o = {};}
+
+ var len = arguments.length;
+ var i = 1;
+
+ while (len--) {
+ var obj = arguments[i++];
+ if (isObject(obj)) {
+ var keys = Object.keys(obj);
+ var klen = keys.length, j = 0;
+
+ while (klen--) {
+ var key = keys[j++];
+ o[key] = obj[key];
+ }
+ }
+ }
+ return o;
+};
diff --git a/benchmark/code/while-while2.js b/benchmark/code/while-while2.js
new file mode 100644
index 0000000..fb071b9
--- /dev/null
+++ b/benchmark/code/while-while2.js
@@ -0,0 +1,24 @@
+'use strict';
+
+var isObject = require('is-extendable');
+
+module.exports = function extend(o, objects) {
+ if (!isObject(o)) {o = {};}
+
+ var len = arguments.length;
+ var i = 1;
+
+ while (len--) {
+ var obj = arguments[i++];
+ if (isObject(obj)) {
+ var keys = Object.keys(obj);
+ var klen = keys.length, j = 0;
+ var key;
+
+ while (key = keys[j++]) {
+ o[key] = obj[key];
+ }
+ }
+ }
+ return o;
+};
diff --git a/benchmark/code/while.js b/benchmark/code/while.js
new file mode 100644
index 0000000..e2a79a8
--- /dev/null
+++ b/benchmark/code/while.js
@@ -0,0 +1,24 @@
+'use strict';
+
+var isObject = require('is-extendable');
+
+module.exports = extend;
+
+function extend(o, objects) {
+ if (!isObject(o)) {
+ o = {};
+ }
+ var len = arguments.length, i = 1;
+ while (len--) {
+ var obj = arguments[i++];
+
+ if (isObject(obj)) {
+ for (var key in obj) {
+ if (obj.hasOwnProperty(key)) {
+ o[key] = obj[key];
+ }
+ }
+ }
+ }
+ return o;
+}
diff --git a/benchmark/fixtures/basic.js b/benchmark/fixtures/basic.js
new file mode 100644
index 0000000..8906710
--- /dev/null
+++ b/benchmark/fixtures/basic.js
@@ -0,0 +1 @@
+module.exports = [{a: 'b'}, {c: 'd'}, {e: 'f'}];
diff --git a/benchmark/fixtures/nested.js b/benchmark/fixtures/nested.js
new file mode 100644
index 0000000..fd9951d
--- /dev/null
+++ b/benchmark/fixtures/nested.js
@@ -0,0 +1,7 @@
+module.exports = [
+ {a: 'a', m: {x: 'x'}},
+ {b: 'b', m: {x: 'q'}},
+ {c: 'c', m: {y: 'y'}},
+ {d: 'd', m: {z: 'z'}},
+ {d: 'e'}
+];
\ No newline at end of file
diff --git a/benchmark/index.js b/benchmark/index.js
new file mode 100644
index 0000000..e8cb11d
--- /dev/null
+++ b/benchmark/index.js
@@ -0,0 +1,23 @@
+'use strict';
+
+var path = require('path');
+var argv = require('minimist')(process.argv.slice(2));
+// var code = 'code/*.js';
+
+// if (argv && argv._) {
+// code = name(argv._[0]);
+// }
+
+var Suite = require('benchmarked');
+var suite = new Suite({
+ result: true,
+ fixtures: 'fixtures/*.js',
+ add: 'code/{{while,for}-arguments-in,_current}.js',
+ cwd: __dirname
+});
+
+suite.run();
+
+function name(str) {
+ return 'code/{_current,' + str + '}{,*}';
+}
diff --git a/benchmark/support.js b/benchmark/support.js
new file mode 100644
index 0000000..36ee4f4
--- /dev/null
+++ b/benchmark/support.js
@@ -0,0 +1,31 @@
+/**
+ * Sources:
+ * - http://jsperf.com/array-unique2/15
+ *
+ */
+
+function randoms(n) {
+ var values = [];
+ var rand;
+ while (n--) {
+ rand = Math.random() * n * 2 | 0;
+ if (rand < values.length)
+ values.push(values[rand]);
+ else {
+ switch (Math.random() * 3 | 0) {
+ case 0:
+ values.push(Math.random() * 1e10 | 0);
+ break;
+ case 1:
+ values.push((Math.random() * 1e32).toString(36));
+ break;
+ case 2:
+ values.push({});
+ break;
+ }
+ }
+ }
+ return values;
+}
+
+var vals = randoms(10000);
diff --git a/bower.json b/bower.json
new file mode 100644
index 0000000..ade3095
--- /dev/null
+++ b/bower.json
@@ -0,0 +1,47 @@
+{
+ "name": "extend-shallow",
+ "description": "Extend an object with the properties of additional objects. node.js/javascript util.",
+ "repository": "jonschlinkert/extend-shallow",
+ "license": "MIT",
+ "homepage": "https://github.com/jonschlinkert/extend-shallow",
+ "authors": [
+ "Jon Schlinkert (https://github.com/jonschlinkert)"
+ ],
+ "main": [
+ "index.js"
+ ],
+ "dependencies": {
+ "is-extendable": "^0.1.0"
+ },
+ "devDependencies": {
+ "array-slice": "^0.2.3",
+ "benchmarked": "^0.1.4",
+ "chalk": "^1.0.0",
+ "for-own": "^0.1.3",
+ "glob": "^5.0.12",
+ "is-plain-object": "^2.0.1",
+ "kind-of": "^2.0.0",
+ "minimist": "^1.1.1",
+ "mocha": "^2.2.5",
+ "should": "^7.0.1"
+ },
+ "keywords": [
+ "assign",
+ "extend",
+ "javascript",
+ "js",
+ "keys",
+ "merge",
+ "obj",
+ "object",
+ "prop",
+ "properties",
+ "property",
+ "props",
+ "shallow",
+ "util",
+ "utility",
+ "utils",
+ "value"
+ ]
+}
\ No newline at end of file
diff --git a/index.js b/index.js
new file mode 100644
index 0000000..92a067f
--- /dev/null
+++ b/index.js
@@ -0,0 +1,33 @@
+'use strict';
+
+var isObject = require('is-extendable');
+
+module.exports = function extend(o/*, objects*/) {
+ if (!isObject(o)) { o = {}; }
+
+ var len = arguments.length;
+ for (var i = 1; i < len; i++) {
+ var obj = arguments[i];
+
+ if (isObject(obj)) {
+ assign(o, obj);
+ }
+ }
+ return o;
+};
+
+function assign(a, b) {
+ for (var key in b) {
+ if (hasOwn(b, key)) {
+ a[key] = b[key];
+ }
+ }
+}
+
+/**
+ * Returns true if the given `key` is an own property of `obj`.
+ */
+
+function hasOwn(obj, key) {
+ return Object.prototype.hasOwnProperty.call(obj, key);
+}
diff --git a/package.json b/package.json
new file mode 100644
index 0000000..b42e01c
--- /dev/null
+++ b/package.json
@@ -0,0 +1,56 @@
+{
+ "name": "extend-shallow",
+ "description": "Extend an object with the properties of additional objects. node.js/javascript util.",
+ "version": "2.0.1",
+ "homepage": "https://github.com/jonschlinkert/extend-shallow",
+ "author": "Jon Schlinkert (https://github.com/jonschlinkert)",
+ "repository": "jonschlinkert/extend-shallow",
+ "bugs": {
+ "url": "https://github.com/jonschlinkert/extend-shallow/issues"
+ },
+ "license": "MIT",
+ "files": [
+ "index.js"
+ ],
+ "main": "index.js",
+ "engines": {
+ "node": ">=0.10.0"
+ },
+ "scripts": {
+ "test": "mocha"
+ },
+ "dependencies": {
+ "is-extendable": "^0.1.0"
+ },
+ "devDependencies": {
+ "array-slice": "^0.2.3",
+ "benchmarked": "^0.1.4",
+ "chalk": "^1.0.0",
+ "for-own": "^0.1.3",
+ "glob": "^5.0.12",
+ "is-plain-object": "^2.0.1",
+ "kind-of": "^2.0.0",
+ "minimist": "^1.1.1",
+ "mocha": "^2.2.5",
+ "should": "^7.0.1"
+ },
+ "keywords": [
+ "assign",
+ "extend",
+ "javascript",
+ "js",
+ "keys",
+ "merge",
+ "obj",
+ "object",
+ "prop",
+ "properties",
+ "property",
+ "props",
+ "shallow",
+ "util",
+ "utility",
+ "utils",
+ "value"
+ ]
+}
\ No newline at end of file
diff --git a/test.js b/test.js
new file mode 100644
index 0000000..83260d5
--- /dev/null
+++ b/test.js
@@ -0,0 +1,68 @@
+/*!
+ * extend-shallow <https://github.com/jonschlinkert/extend-shallow>
+ *
+ * Copyright (c) 2014-2015, Jon Schlinkert.
+ * Licensed under the MIT License.
+ */
+
+'use strict';
+
+/* deps: mocha */
+var path = require('path');
+var argv = require('minimist')(process.argv.slice(2));
+var extend = require('./');
+require('should');
+
+if (argv && argv.lib) {
+ extend = require(path.resolve('benchmark/code', argv.lib));
+}
+
+describe('extend', function () {
+ it('should extend the first object with the properties of the other objects.', function () {
+ extend({a: 'b'}, {c: 'd'}).should.eql({a: 'b', c: 'd'});
+ extend({a: 'b', c: 'd'}, {c: 'e'}).should.eql({a: 'b', c: 'e'});
+ });
+
+ it('should skip over non-plain objects.', function () {
+ extend({a: 'b'}, 'foo', {c: 'd'}).should.eql({a: 'b', c: 'd'});
+ extend({a: 'b'}, null, {c: 'd'}).should.eql({a: 'b', c: 'd'});
+ extend({a: 'b'}, new Date(), {c: 'd'}).should.eql({a: 'b', c: 'd'});
+ extend({a: 'b', c: 'd'}, 'bar', {c: 'e'}).should.eql({a: 'b', c: 'e'});
+ });
+
+ it('should extend a regex.', function () {
+ var fixture = /foo/;
+ extend(fixture, {a: 'b'}, new Date(), {c: 'd'});
+ fixture.a.should.equal('b');
+ fixture.c.should.equal('d');
+ });
+
+ it('should extend a function.', function () {
+ var fixture = function() {};
+ extend(fixture, {a: 'b'}, new Date(), {c: 'd'});
+ fixture.a.should.equal('b');
+ fixture.c.should.equal('d');
+ });
+
+ it('should extend an array.', function () {
+ var arr = [];
+ extend(arr, {a: 'b'}, new Date(), {c: 'd'});
+ arr.a.should.equal('b');
+ arr.c.should.equal('d');
+ });
+
+ it('should return an empty object when args are undefined.', function () {
+ extend(null).should.eql({});
+ extend(undefined).should.eql({});
+ });
+
+ describe('.extend():', function () {
+ it('should extend object a with object b:', function () {
+ extend({a: {b: 'b'}}, {b: {c: 'c'}}).should.eql({a: {b: 'b'}, b: {c: 'c'}});
+ });
+
+ it('should return an empty object when args are undefined:', function () {
+ extend().should.eql({});
+ });
+ });
+});
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-extend-shallow.git
More information about the Pkg-javascript-commits
mailing list