Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

assign-deep

Package Overview
Dependencies
Maintainers
2
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

assign-deep - npm Package Compare versions

Comparing version 0.4.7 to 1.0.0

78

index.js
/*!
* assign-deep <https://github.com/jonschlinkert/assign-deep>
*
* Copyright (c) 2017, Jon Schlinkert.
* Copyright (c) 2017-present, Jon Schlinkert.
* Released under the MIT License.

@@ -10,67 +10,29 @@ */

var isPrimitive = require('is-primitive');
var assignSymbols = require('assign-symbols');
var typeOf = require('kind-of');
function assign(target/*, objects*/) {
target = target || {};
var len = arguments.length, i = 0;
if (len === 1) {
return target;
}
while (++i < len) {
var val = arguments[i];
if (isPrimitive(target)) {
target = val;
}
if (isObject(val)) {
extend(target, val);
}
}
return target;
}
/**
* Shallow extend
*/
function extend(target, obj) {
assignSymbols(target, obj);
for (var key in obj) {
if (key !== '__proto__' && hasOwn(obj, key)) {
var val = obj[key];
if (isObject(val)) {
if (typeOf(target[key]) === 'undefined' && typeOf(val) === 'function') {
target[key] = val;
const assignSymbols = require('assign-symbols');
const toString = Object.prototype.toString;
const assign = module.exports = (target, ...args) => {
let i = 0;
if (isPrimitive(target)) target = args[i++];
if (!target) target = {};
for (; i < args.length; i++) {
if (isObject(args[i])) {
for (const key of Object.keys(args[i])) {
if (isObject(target[key]) && isObject(args[i][key])) {
assign(target[key], args[i][key]);
} else {
target[key] = args[i][key];
}
target[key] = assign(target[key] || {}, val);
} else {
target[key] = val;
}
assignSymbols(target, args[i]);
}
}
return target;
}
};
/**
* Returns true if the object is a plain object or a function.
*/
function isObject(obj) {
return typeOf(obj) === 'object' || typeOf(obj) === 'function';
function isObject(val) {
return typeof val === 'function' || toString.call(val) === '[object Object]';
}
/**
* Returns true if the given `key` is an own property of `obj`.
*/
function hasOwn(obj, key) {
return Object.prototype.hasOwnProperty.call(obj, key);
function isPrimitive(val) {
return typeof val === 'object' ? val === null : typeof val !== 'function';
}
/**
* Expose `assign`
*/
module.exports = assign;
{
"name": "assign-deep",
"description": "Deeply assign the enumerable properties and/or es6 Symbol properies of source objects to the target (first) object.",
"version": "0.4.7",
"description": "Deeply assign the values of all enumerable-own-properties and symbols from one or more source objects to a target object. Returns the target object.",
"version": "1.0.0",
"homepage": "https://github.com/jonschlinkert/assign-deep",

@@ -21,3 +21,3 @@ "author": "Jon Schlinkert (https://github.com/jonschlinkert)",

"engines": {
"node": ">=0.10.0"
"node": ">=6"
},

@@ -28,9 +28,7 @@ "scripts": {

"dependencies": {
"assign-symbols": "^0.1.1",
"is-primitive": "^2.0.0",
"kind-of": "^5.0.2"
"assign-symbols": "^2.0.2"
},
"devDependencies": {
"gulp-format-md": "^1.0.0",
"mocha": "^3.5.0"
"mocha": "^5.2.0"
},

@@ -37,0 +35,0 @@ "keywords": [

# assign-deep [![NPM version](https://img.shields.io/npm/v/assign-deep.svg?style=flat)](https://www.npmjs.com/package/assign-deep) [![NPM monthly downloads](https://img.shields.io/npm/dm/assign-deep.svg?style=flat)](https://npmjs.org/package/assign-deep) [![NPM total downloads](https://img.shields.io/npm/dt/assign-deep.svg?style=flat)](https://npmjs.org/package/assign-deep) [![Linux Build Status](https://img.shields.io/travis/jonschlinkert/assign-deep.svg?style=flat&label=Travis)](https://travis-ci.org/jonschlinkert/assign-deep)
> Deeply assign the enumerable properties and/or es6 Symbol properies of source objects to the target (first) object.
> Deeply assign the values of all enumerable-own-properties and symbols from one or more source objects to a target object. Returns the target object.
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

@@ -13,13 +15,42 @@

## Behavior
* This follows the same behavior as [Object.assign()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign), and thus _does not_ deep clone values.
* The first argument is the "target" object.
* To shallow clone, pass an empty object as the first argument.
* One or more additional ("source") objects may be passed.
* When multiple objects are passed, properties in _later_ objects will overwrite same-named properties in _earlier_ objects. Thus, properties in the target object will be overwritten by same-named properties in other objects.
* Only enumerable and own properties are copied.
* String and Symbol properties are copied.
* Sparse arguments are skipped, so this does not throw on `null` or `undefined` source values.
* Like [Object.assign()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign), `[[Get]]` is used on source objects and `[[Set]]` is used on the target, so it will invoke getters and setters. Therefore it assigns properties versus just copying or defining new properties. _Note that this should not be used for merging new properties into a prototype if the merge sources contain getters and you do not want `[[Get]]` to be used on the getters. For copying property definitions and their enumerability into prototypes `Object.getOwnPropertyDescriptor()` and `Object.defineProperty()` should be used instead._
## Usage
```js
var assign = require('assign-deep');
const assign = require('assign-deep');
var one = {b: {c: {d: 'e'}}};
var two = {b: {c: {f: 'g', j: 'i'}}};
var three = {foo: 'bar'};
const config = {
admin: true,
author: {
name: { first: 'Joe' }
}
};
console.log(assign(one, two, three));
//=> {b: {c: {d: 'e', f: 'g', j: 'i'}}, foo: 'bar'}
const locals = {
admin: false,
author: {
name: { last: 'Smith' },
username: 'joesmith'
}
};
console.log(assign(config, locals));
// {
// admin: false,
// author: {
// name: { first: 'Joe', last: 'Smith' },
// username: 'joesmith'
// }
// }
```

@@ -29,23 +60,22 @@

### Related projects
<details>
<summary><strong>Contributing</strong></summary>
You might also be interested in these projects:
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).
* [assign-symbols](https://www.npmjs.com/package/assign-symbols): Assign the enumerable es6 Symbol properties from an object (or objects) to the first object… [more](https://github.com/jonschlinkert/assign-symbols) | [homepage](https://github.com/jonschlinkert/assign-symbols "Assign the enumerable es6 Symbol properties from an object (or objects) to the first object passed on the arguments. Can be used as a supplement to other extend, assign or merge methods as a polyfill for the Symbols part of the es6 Object.assign method.")
* [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.")
* [merge-deep](https://www.npmjs.com/package/merge-deep): Recursively merge values in a javascript object. | [homepage](https://github.com/jonschlinkert/merge-deep "Recursively merge values in a javascript object.")
* [mixin-deep](https://www.npmjs.com/package/mixin-deep): Deeply mix the properties of objects into the first object. Like merge-deep, but doesn't clone. | [homepage](https://github.com/jonschlinkert/mixin-deep "Deeply mix the properties of objects into the first object. Like merge-deep, but doesn't clone.")
</details>
### Contributing
<details>
<summary><strong>Running Tests</strong></summary>
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).
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:
### Contributors
```sh
$ npm install && npm test
```
| **Commits** | **Contributor** |
| --- | --- |
| 23 | [jonschlinkert](https://github.com/jonschlinkert) |
| 11 | [doowb](https://github.com/doowb) |
</details>
### Building docs
<details>
<summary><strong>Building docs</strong></summary>

@@ -60,10 +90,20 @@ _(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.)_

### Running tests
</details>
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:
### Related projects
```sh
$ npm install && npm test
```
You might also be interested in these projects:
* [assign-symbols](https://www.npmjs.com/package/assign-symbols): Assign the enumerable es6 Symbol properties from an object (or objects) to the first object… [more](https://github.com/jonschlinkert/assign-symbols) | [homepage](https://github.com/jonschlinkert/assign-symbols "Assign the enumerable es6 Symbol properties from an object (or objects) to the first object passed on the arguments. Can be used as a supplement to other extend, assign or merge methods as a polyfill for the Symbols part of the es6 Object.assign method.")
* [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.")
* [merge-deep](https://www.npmjs.com/package/merge-deep): Recursively merge values in a javascript object. | [homepage](https://github.com/jonschlinkert/merge-deep "Recursively merge values in a javascript object.")
* [mixin-deep](https://www.npmjs.com/package/mixin-deep): Deeply mix the properties of objects into the first object. Like merge-deep, but doesn't clone… [more](https://github.com/jonschlinkert/mixin-deep) | [homepage](https://github.com/jonschlinkert/mixin-deep "Deeply mix the properties of objects into the first object. Like merge-deep, but doesn't clone. No dependencies.")
### Contributors
| **Commits** | **Contributor** |
| --- | --- |
| 27 | [jonschlinkert](https://github.com/jonschlinkert) |
| 14 | [doowb](https://github.com/doowb) |
### Author

@@ -73,8 +113,9 @@

* [github/jonschlinkert](https://github.com/jonschlinkert)
* [twitter/jonschlinkert](https://twitter.com/jonschlinkert)
* [LinkedIn Profile](https://linkedin.com/in/jonschlinkert)
* [GitHub Profile](https://github.com/jonschlinkert)
* [Twitter Profile](https://twitter.com/jonschlinkert)
### License
Copyright © 2017, [Jon Schlinkert](https://github.com/jonschlinkert).
Copyright © 2018, [Jon Schlinkert](https://github.com/jonschlinkert).
Released under the [MIT License](LICENSE).

@@ -84,2 +125,2 @@

_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on August 03, 2017._
_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on August 07, 2018._

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc