[Pkg-javascript-commits] [node-extend-shallow] 01/05: New upstream version 3.0.1
Julien Puydt
julien.puydt at laposte.net
Sat Nov 25 18:32:01 UTC 2017
This is an automated email from the git hooks/post-receive script.
jpuydt-guest pushed a commit to branch master
in repository node-extend-shallow.
commit 797fe7823574623501c315b90fb2d2b3cf8cd26e
Author: Julien Puydt <julien.puydt at laposte.net>
Date: Sat Nov 25 18:33:46 2017 +0100
New upstream version 3.0.1
---
.editorconfig | 15 ++---
.eslintrc.json | 117 +++++++++++++++++++++++++++++++++++++
.gitignore | 70 ++++++++--------------
.jshintrc | 18 ------
.travis.yml | 17 ++++--
.verb.md | 23 --------
LICENSE | 2 +-
README.md | 76 +++++++++++++++++-------
benchmark/check.js | 21 -------
benchmark/code/_current.js | 3 -
benchmark/code/assign.js | 5 +-
benchmark/code/extend-shallow.js | 3 +
benchmark/code/for-arguments-in.js | 4 --
benchmark/code/object-assign.js | 3 +
benchmark/fixtures/sparse.js | 8 +++
benchmark/index.js | 34 +++++------
benchmark/support.js | 31 ----------
bower.json | 48 ++++++++++-----
index.js | 25 ++++----
package.json | 60 +++++++++++++------
test.js | 97 ++++++++++++++++++------------
21 files changed, 396 insertions(+), 284 deletions(-)
diff --git a/.editorconfig b/.editorconfig
index 2eed47c..449f0da 100644
--- a/.editorconfig
+++ b/.editorconfig
@@ -1,17 +1,14 @@
-# http://editorconfig.org
+# http://editorconfig.org/
root = true
[*]
-indent_style = space
-indent_size = 2
-end_of_line = lf
charset = utf-8
-trim_trailing_whitespace = true
+end_of_line = lf
+indent_size = 2
+indent_style = space
insert_final_newline = true
+trim_trailing_whitespace = true
-[*.md]
+[{**/{actual,fixtures,expected,templates}/**,*.md}]
trim_trailing_whitespace = false
-
-[test/fixtures/*]
insert_final_newline = false
-trim_trailing_whitespace = false
\ No newline at end of file
diff --git a/.eslintrc.json b/.eslintrc.json
new file mode 100644
index 0000000..61e8895
--- /dev/null
+++ b/.eslintrc.json
@@ -0,0 +1,117 @@
+{
+ "env": {
+ "browser": false,
+ "es6": true,
+ "node": true,
+ "mocha": true
+ },
+
+ "globals": {
+ "document": false,
+ "navigator": false,
+ "window": false
+ },
+
+ "rules": {
+ "accessor-pairs": 2,
+ "arrow-spacing": [2, { "before": true, "after": true }],
+ "block-spacing": [2, "always"],
+ "brace-style": [2, "1tbs", { "allowSingleLine": true }],
+ "comma-dangle": [2, "never"],
+ "comma-spacing": [2, { "before": false, "after": true }],
+ "comma-style": [2, "last"],
+ "constructor-super": 2,
+ "curly": [2, "multi-line"],
+ "dot-location": [2, "property"],
+ "eol-last": 2,
+ "eqeqeq": [2, "allow-null"],
+ "generator-star-spacing": [2, { "before": true, "after": true }],
+ "handle-callback-err": [2, "^(err|error)$" ],
+ "indent": [2, 2, { "SwitchCase": 1 }],
+ "key-spacing": [2, { "beforeColon": false, "afterColon": true }],
+ "keyword-spacing": [2, { "before": true, "after": true }],
+ "new-cap": [2, { "newIsCap": true, "capIsNew": false }],
+ "new-parens": 2,
+ "no-array-constructor": 2,
+ "no-caller": 2,
+ "no-class-assign": 2,
+ "no-cond-assign": 2,
+ "no-const-assign": 2,
+ "no-control-regex": 2,
+ "no-debugger": 2,
+ "no-delete-var": 2,
+ "no-dupe-args": 2,
+ "no-dupe-class-members": 2,
+ "no-dupe-keys": 2,
+ "no-duplicate-case": 2,
+ "no-empty-character-class": 2,
+ "no-eval": 2,
+ "no-ex-assign": 2,
+ "no-extend-native": 2,
+ "no-extra-bind": 2,
+ "no-extra-boolean-cast": 2,
+ "no-extra-parens": [2, "functions"],
+ "no-fallthrough": 2,
+ "no-floating-decimal": 2,
+ "no-func-assign": 2,
+ "no-implied-eval": 2,
+ "no-inner-declarations": [2, "functions"],
+ "no-invalid-regexp": 2,
+ "no-irregular-whitespace": 2,
+ "no-iterator": 2,
+ "no-label-var": 2,
+ "no-labels": 2,
+ "no-lone-blocks": 2,
+ "no-mixed-spaces-and-tabs": 2,
+ "no-multi-spaces": 2,
+ "no-multi-str": 2,
+ "no-multiple-empty-lines": [2, { "max": 1 }],
+ "no-native-reassign": 0,
+ "no-negated-in-lhs": 2,
+ "no-new": 2,
+ "no-new-func": 2,
+ "no-new-object": 2,
+ "no-new-require": 2,
+ "no-new-wrappers": 2,
+ "no-obj-calls": 2,
+ "no-octal": 2,
+ "no-octal-escape": 2,
+ "no-proto": 0,
+ "no-redeclare": 2,
+ "no-regex-spaces": 2,
+ "no-return-assign": 2,
+ "no-self-compare": 2,
+ "no-sequences": 2,
+ "no-shadow-restricted-names": 2,
+ "no-spaced-func": 2,
+ "no-sparse-arrays": 2,
+ "no-this-before-super": 2,
+ "no-throw-literal": 2,
+ "no-trailing-spaces": 0,
+ "no-undef": 2,
+ "no-undef-init": 2,
+ "no-unexpected-multiline": 2,
+ "no-unneeded-ternary": [2, { "defaultAssignment": false }],
+ "no-unreachable": 2,
+ "no-unused-vars": [2, { "vars": "all", "args": "none" }],
+ "no-useless-call": 0,
+ "no-with": 2,
+ "one-var": [0, { "initialized": "never" }],
+ "operator-linebreak": [0, "after", { "overrides": { "?": "before", ":": "before" } }],
+ "padded-blocks": [0, "never"],
+ "quotes": [2, "single", "avoid-escape"],
+ "radix": 2,
+ "semi": [2, "always"],
+ "semi-spacing": [2, { "before": false, "after": true }],
+ "space-before-blocks": [2, "always"],
+ "space-before-function-paren": [2, "never"],
+ "space-in-parens": [2, "never"],
+ "space-infix-ops": 2,
+ "space-unary-ops": [2, { "words": true, "nonwords": false }],
+ "spaced-comment": [0, "always", { "markers": ["global", "globals", "eslint", "eslint-disable", "*package", "!", ","] }],
+ "use-isnan": 2,
+ "valid-typeof": 2,
+ "wrap-iife": [2, "any"],
+ "yoda": [2, "never"]
+ }
+}
diff --git a/.gitignore b/.gitignore
index 92139bd..4bf0a60 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,53 +1,29 @@
-# Numerous always-ignore extensions
+# always ignore files
*.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
+.idea
+*.sublime-*
-# Always-ignore dirs
-/bower_components/
-/node_modules/
-/temp/
-/tmp/
-/vendor/
-_gh_pages
+# test related, or directories generated by tests
+test/actual
+actual
+coverage
+.nyc*
-# OS or Editor folders
-*.esproj
-*.komodoproject
-.komodotools
-*.sublime-*
-._*
-.cache
-.DS_Store
-.idea
-.project
-.settings
-.tmproj
-nbproject
-Thumbs.db
+# npm
+node_modules
+npm-debug.log
-# grunt-html-validation
-validation-status.json
-validation-report.json
+# yarn
+yarn.lock
+yarn-error.log
# misc
-TODO.md
\ No newline at end of file
+_gh_pages
+_draft
+_drafts
+bower_components
+vendor
+temp
+tmp
+TODO.md
+package-lock.json
\ No newline at end of file
diff --git a/.jshintrc b/.jshintrc
deleted file mode 100644
index 6e5a84a..0000000
--- a/.jshintrc
+++ /dev/null
@@ -1,18 +0,0 @@
-{
- "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
index f9cffe6..1686664 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,8 +1,15 @@
sudo: false
+os:
+ - linux
+ - osx
language: node_js
node_js:
- - "0.10"
- - "0.12"
- - "iojs"
-git:
- depth: 10
+ - node
+ - '9'
+ - '8'
+ - '7'
+ - '6'
+ - '5'
+ - '4'
+ - '0.12'
+ - '0.10'
diff --git a/.verb.md b/.verb.md
index b194a4f..76e368f 100644
--- a/.verb.md
+++ b/.verb.md
@@ -1,10 +1,3 @@
-# {%= name %} {%= badge("fury") %} {%= badge("travis") %}
-
-> {%= description %}
-
-## Install
-{%= include("install-npm", {save: true}) %}
-
## Usage
```js
@@ -21,19 +14,3 @@ 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
index fa30c4c..99c9369 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,6 +1,6 @@
The MIT License (MIT)
-Copyright (c) 2014-2015, Jon Schlinkert.
+Copyright (c) 2014-2015, 2017, 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
diff --git a/README.md b/README.md
index cdc45d4..dee226f 100644
--- a/README.md
+++ b/README.md
@@ -1,13 +1,15 @@
-# 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-shallow [![NPM version](https://img.shields.io/npm/v/extend-shallow.svg?style=flat)](https://www.npmjs.com/package/extend-shallow) [![NPM monthly downloads](https://img.shields.io/npm/dm/extend-shallow.svg?style=flat)](https://npmjs.org/package/extend-shallow) [![NPM total downloads](https://img.shields.io/npm/dt/extend-shallow.svg?style=flat)](https://npmjs.org/package/extend-shallow) [![Linux Build Status](https://img.shields.io/travis/jonschlinkert/extend-shallow.svg?style=fl [...]
> Extend an object with the properties of additional objects. node.js/javascript util.
+Please consider following this project's author, [Jon Schlinkert](https://github.com/jonschlinkert), and consider starring the project to show your :heart: and support.
+
## Install
-Install with [npm](https://www.npmjs.com/)
+Install with [npm](https://www.npmjs.com/):
```sh
-$ npm i extend-shallow --save
+$ npm install --save extend-shallow
```
## Usage
@@ -27,35 +29,69 @@ extend(obj, {a: 'b'}, {c: 'd'})
//=> {a: 'b', c: 'd'}
```
-## Related
+## About
+
+<details>
+<summary><strong>Contributing</strong></summary>
+
+Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).
+
+</details>
+
+<details>
+<summary><strong>Running Tests</strong></summary>
+
+Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:
+
+```sh
+$ npm install && npm test
+```
+
+</details>
-* [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.
+<details>
+<summary><strong>Building docs</strong></summary>
-## Running tests
+_(This project's readme.md is generated by [verb](https://github.com/verbose/verb-generate-readme), please don't edit the readme directly. Any changes to the readme must be made in the [.verb.md](.verb.md) readme template.)_
-Install dev dependencies:
+To generate the readme, run the following command:
```sh
-$ npm i -d && npm test
+$ npm install -g verbose/verb#dev verb-generate-readme && verb
```
-## Author
+</details>
+
+### Related projects
+
+You might also be interested in these projects:
+
+* [extend-shallow](https://www.npmjs.com/package/extend-shallow): Extend an object with the properties of additional objects. node.js/javascript util. | [homepage](https://github.com/jonschlinkert/extend-shallow "Extend an object with the properties of additional objects. node.js/javascript util.")
+* [for-in](https://www.npmjs.com/package/for-in): Iterate over the own and inherited enumerable properties of an object, and return an object… [more](https://github.com/jonschlinkert/for-in) | [homepage](https://github.com/jonschlinkert/for-in "Iterate over the own and inherited enumerable properties of an object, and return an object with properties that evaluate to true from the callback. Exit early by returning `false`. JavaScript/Node.js")
+* [for-own](https://www.npmjs.com/package/for-own): Iterate over the own enumerable properties of an object, and return an object with properties… [more](https://github.com/jonschlinkert/for-own) | [homepage](https://github.com/jonschlinkert/for-own "Iterate over the own enumerable properties of an object, and return an object with properties that evaluate to true from the callback. Exit early by returning `false`. JavaScript/Node.js.")
+* [is-plain-object](https://www.npmjs.com/package/is-plain-object): Returns true if an object was created by the `Object` constructor. | [homepage](https://github.com/jonschlinkert/is-plain-object "Returns true if an object was created by the `Object` constructor.")
+* [isobject](https://www.npmjs.com/package/isobject): Returns true if the value is an object and not an array or null. | [homepage](https://github.com/jonschlinkert/isobject "Returns true if the value is an object and not an array or null.")
+* [kind-of](https://www.npmjs.com/package/kind-of): Get the native type of a value. | [homepage](https://github.com/jonschlinkert/kind-of "Get the native type of a value.")
+
+### Contributors
+
+| **Commits** | **Contributor** |
+| --- | --- |
+| 33 | [jonschlinkert](https://github.com/jonschlinkert) |
+| 1 | [pdehaan](https://github.com/pdehaan) |
+
+### Author
**Jon Schlinkert**
-+ [github/jonschlinkert](https://github.com/jonschlinkert)
-+ [twitter/jonschlinkert](http://twitter.com/jonschlinkert)
+* [github/jonschlinkert](https://github.com/jonschlinkert)
+* [twitter/jonschlinkert](https://twitter.com/jonschlinkert)
-## License
+### License
-Copyright © 2015 Jon Schlinkert
-Released under the MIT license.
+Copyright © 2017, [Jon Schlinkert](https://github.com/jonschlinkert).
+Released under the [MIT License](LICENSE).
***
-_This file was generated by [verb-cli](https://github.com/assemble/verb-cli) on June 29, 2015._
\ No newline at end of file
+_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on November 19, 2017._
\ No newline at end of file
diff --git a/benchmark/check.js b/benchmark/check.js
deleted file mode 100644
index 1905305..0000000
--- a/benchmark/check.js
+++ /dev/null
@@ -1,21 +0,0 @@
-'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/_current.js b/benchmark/code/_current.js
deleted file mode 100644
index 0f85e82..0000000
--- a/benchmark/code/_current.js
+++ /dev/null
@@ -1,3 +0,0 @@
-'use strict';
-
-module.exports = require('../..');
\ No newline at end of file
diff --git a/benchmark/code/assign.js b/benchmark/code/assign.js
index 1499638..abf8484 100644
--- a/benchmark/code/assign.js
+++ b/benchmark/code/assign.js
@@ -1,10 +1,9 @@
-var isObject = require('is-plain-object');
+var isObject = require('is-extendable');
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++];
@@ -22,4 +21,4 @@ function assign(o, obj) {
}
}
return o;
-}
\ No newline at end of file
+}
diff --git a/benchmark/code/extend-shallow.js b/benchmark/code/extend-shallow.js
new file mode 100644
index 0000000..3e20024
--- /dev/null
+++ b/benchmark/code/extend-shallow.js
@@ -0,0 +1,3 @@
+'use strict';
+
+module.exports = require('../..');
diff --git a/benchmark/code/for-arguments-in.js b/benchmark/code/for-arguments-in.js
index 98b9743..9a97311 100644
--- a/benchmark/code/for-arguments-in.js
+++ b/benchmark/code/for-arguments-in.js
@@ -11,10 +11,6 @@ module.exports = function extend(o, objects) {
if (isObject(obj)) {
assign(o, obj);
-
- // for (var key in obj) {
- // o[key] = obj[key];
- // }
}
}
return o;
diff --git a/benchmark/code/object-assign.js b/benchmark/code/object-assign.js
new file mode 100644
index 0000000..91d5df7
--- /dev/null
+++ b/benchmark/code/object-assign.js
@@ -0,0 +1,3 @@
+'use strict';
+
+module.exports = require('object-assign');
diff --git a/benchmark/fixtures/sparse.js b/benchmark/fixtures/sparse.js
new file mode 100644
index 0000000..071551f
--- /dev/null
+++ b/benchmark/fixtures/sparse.js
@@ -0,0 +1,8 @@
+module.exports = [
+ {a: 'a', m: {x: 'x'}},
+ {b: 'b', m: {x: 'q'}},
+ '',
+ {d: 'd', m: {z: 'z'}},
+ null,
+ {d: 'e'}
+];
\ No newline at end of file
diff --git a/benchmark/index.js b/benchmark/index.js
index e8cb11d..15cf38f 100644
--- a/benchmark/index.js
+++ b/benchmark/index.js
@@ -1,23 +1,15 @@
'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 + '}{,*}';
-}
+const path = require('path');
+const argv = require('minimist')(process.argv.slice(2));
+const suite = require('benchmarked');
+const glob = argv._[0] || '*';
+
+suite.run({code: `code/${glob}.js`, fixtures: `fixtures/*.js`})
+ .then(function(stats) {
+ stats.forEach(function(target) {
+ target.fastest = target.fastest || ['n/a'];
+ });
+ console.log(suite.render(stats));
+ })
+ .catch(console.error);
diff --git a/benchmark/support.js b/benchmark/support.js
deleted file mode 100644
index 36ee4f4..0000000
--- a/benchmark/support.js
+++ /dev/null
@@ -1,31 +0,0 @@
-/**
- * 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
index ade3095..2d0db6e 100644
--- a/bower.json
+++ b/bower.json
@@ -11,29 +11,28 @@
"index.js"
],
"dependencies": {
- "is-extendable": "^0.1.0"
+ "is-extendable": "^1.0.1"
},
"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"
+ "array-slice": "^1.0.0",
+ "benchmarked": "^2.0.0",
+ "for-own": "^1.0.0",
+ "gulp-format-md": "^1.0.0",
+ "is-plain-object": "^2.0.4",
+ "kind-of": "^6.0.1",
+ "minimist": "^1.2.0",
+ "mocha": "^3.5.3",
+ "object-assign": "^4.1.1"
},
"keywords": [
"assign",
+ "clone",
"extend",
- "javascript",
- "js",
- "keys",
"merge",
"obj",
"object",
+ "object-assign",
+ "object.assign",
"prop",
"properties",
"property",
@@ -43,5 +42,26 @@
"utility",
"utils",
"value"
+ ],
+ "version": "2.0.1",
+ "bugs": {
+ "url": "https://github.com/jonschlinkert/extend-shallow/issues"
+ },
+ "files": [
+ "index.js"
+ ],
+ "ignore": [
+ "actual",
+ "bower_components",
+ "fixtures",
+ "node_modules",
+ "temp",
+ "test",
+ "test.js",
+ "tmp"
+ ],
+ "contributors": [
+ "Jon Schlinkert (http://twitter.com/jonschlinkert)",
+ "Peter deHaan (http://about.me/peterdehaan)"
]
}
\ No newline at end of file
diff --git a/index.js b/index.js
index 92a067f..4326d27 100644
--- a/index.js
+++ b/index.js
@@ -1,19 +1,18 @@
'use strict';
-var isObject = require('is-extendable');
+var isExtendable = 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);
+module.exports = Object.assign || function(obj/*, objects*/) {
+ if (obj === null || typeof obj === 'undefined') {
+ throw new TypeError('expected an object');
+ }
+ for (var i = 1; i < arguments.length; i++) {
+ var val = arguments[i];
+ if (isObject(val)) {
+ assign(obj, val);
}
}
- return o;
+ return obj;
};
function assign(a, b) {
@@ -24,6 +23,10 @@ function assign(a, b) {
}
}
+function isObject(val) {
+ return (val && typeof val === 'object') || isExtendable(val);
+}
+
/**
* Returns true if the given `key` is an own property of `obj`.
*/
diff --git a/package.json b/package.json
index b42e01c..7364877 100644
--- a/package.json
+++ b/package.json
@@ -1,9 +1,13 @@
{
"name": "extend-shallow",
"description": "Extend an object with the properties of additional objects. node.js/javascript util.",
- "version": "2.0.1",
+ "version": "3.0.1",
"homepage": "https://github.com/jonschlinkert/extend-shallow",
"author": "Jon Schlinkert (https://github.com/jonschlinkert)",
+ "contributors": [
+ "Jon Schlinkert (http://twitter.com/jonschlinkert)",
+ "Peter deHaan (http://about.me/peterdehaan)"
+ ],
"repository": "jonschlinkert/extend-shallow",
"bugs": {
"url": "https://github.com/jonschlinkert/extend-shallow/issues"
@@ -20,29 +24,28 @@
"test": "mocha"
},
"dependencies": {
- "is-extendable": "^0.1.0"
+ "is-extendable": "^1.0.1"
},
"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"
+ "array-slice": "^1.0.0",
+ "benchmarked": "^2.0.0",
+ "for-own": "^1.0.0",
+ "gulp-format-md": "^1.0.0",
+ "is-plain-object": "^2.0.4",
+ "kind-of": "^6.0.1",
+ "minimist": "^1.2.0",
+ "mocha": "^3.5.3",
+ "object-assign": "^4.1.1"
},
"keywords": [
"assign",
+ "clone",
"extend",
- "javascript",
- "js",
- "keys",
"merge",
"obj",
"object",
+ "object-assign",
+ "object.assign",
"prop",
"properties",
"property",
@@ -52,5 +55,28 @@
"utility",
"utils",
"value"
- ]
-}
\ No newline at end of file
+ ],
+ "verb": {
+ "toc": false,
+ "layout": "default",
+ "tasks": [
+ "readme"
+ ],
+ "related": {
+ "list": [
+ "extend-shallow",
+ "for-in",
+ "for-own",
+ "is-plain-object",
+ "isobject",
+ "kind-of"
+ ]
+ },
+ "plugins": [
+ "gulp-format-md"
+ ],
+ "lint": {
+ "reflinks": true
+ }
+ }
+}
diff --git a/test.js b/test.js
index 83260d5..1e7c7ac 100644
--- a/test.js
+++ b/test.js
@@ -7,62 +7,87 @@
'use strict';
-/* deps: mocha */
-var path = require('path');
-var argv = require('minimist')(process.argv.slice(2));
-var extend = require('./');
-require('should');
+require('mocha');
+const hasSymbol = typeof global.Symbol === 'function';
+const path = require('path');
+const argv = require('minimist')(process.argv.slice(2));
+const assert = require('assert');
+const extend = require('./');
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'});
+describe('extend', function() {
+ it('should extend the first object with the properties of the other objects', function() {
+ assert.deepEqual(extend({a: 'b'}, {c: 'd'}), {a: 'b', c: 'd'});
+ assert.deepEqual(extend({a: 'b', c: 'd'}, {c: 'e'}), {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 handle non-plain objects', function() {
+ assert.deepEqual(extend({a: 'b'}, 'foo', {c: 'd'}), {0: 'f', 1: 'o', 2: 'o', a: 'b', c: 'd'});
+ assert.deepEqual(extend({a: 'b'}, null, {c: 'd'}), {a: 'b', c: 'd'});
+ assert.deepEqual(extend({a: 'b'}, new Date(), {c: 'd'}), {a: 'b', c: 'd'});
});
- it('should extend a regex.', function () {
- var fixture = /foo/;
+ it('should extend a regex', function() {
+ const fixture = /foo/;
extend(fixture, {a: 'b'}, new Date(), {c: 'd'});
- fixture.a.should.equal('b');
- fixture.c.should.equal('d');
+ assert.equal(fixture.a, 'b');
+ assert.equal(fixture.c, 'd');
});
- it('should extend a function.', function () {
- var fixture = function() {};
+ it('should extend a function', function() {
+ const fixture = function() {};
extend(fixture, {a: 'b'}, new Date(), {c: 'd'});
- fixture.a.should.equal('b');
- fixture.c.should.equal('d');
+ assert.equal(fixture.a, 'b');
+ assert.equal(fixture.c, 'd');
});
- it('should extend an array.', function () {
- var arr = [];
+ it('should extend an array', function() {
+ const arr = [];
extend(arr, {a: 'b'}, new Date(), {c: 'd'});
- arr.a.should.equal('b');
- arr.c.should.equal('d');
+ assert.equal(arr.a, 'b');
+ assert.equal(arr.c, 'd');
});
- it('should return an empty object when args are undefined.', function () {
- extend(null).should.eql({});
- extend(undefined).should.eql({});
+ it('should throw when the first arg is invalid', function() {
+ assert.throws(function() {
+ extend(null);
+ });
+ assert.throws(function() {
+ extend(undefined);
+ });
+ assert.throws(function() {
+ extend();
+ });
});
- 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 non-object is passed', function() {
+ assert.deepEqual(extend(123), {});
+ });
- it('should return an empty object when args are undefined:', function () {
- extend().should.eql({});
- });
+ it('should not extend non-enumerable symbols', function() {
+ if (!hasSymbol) return this.skip();
+ const fixture = {};
+ const obj = {};
+ const symbol = Symbol('foo');
+ Object.defineProperty(obj, symbol, {enumerable: false, value: 'bar'});
+ extend(fixture, obj);
+ const other = extend({}, obj);
+ assert.equal(typeof fixture[symbol], 'undefined');
+ assert.equal(typeof other[symbol], 'undefined');
+ });
+
+ it('should extend symbol properties', function() {
+ if (!hasSymbol) return this.skip();
+ const fixture = {};
+ const obj = {};
+ const symbol = Symbol('foo');
+ obj[symbol] = 'bar';
+ extend(fixture, obj);
+ const other = extend({}, obj);
+ assert.equal(fixture[symbol], 'bar');
+ assert.equal(other[symbol], 'bar');
});
});
--
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