assign-symbols
Advanced tools
Comparing version 1.0.0 to 2.0.0
39
index.js
/*! | ||
* assign-symbols <https://github.com/jonschlinkert/assign-symbols> | ||
* | ||
* Copyright (c) 2015, Jon Schlinkert. | ||
* Copyright (c) 2015-present, Jon Schlinkert. | ||
* Licensed under the MIT License. | ||
@@ -10,28 +10,21 @@ */ | ||
module.exports = function(receiver, objects) { | ||
if (receiver === null || typeof receiver === 'undefined') { | ||
throw new TypeError('expected first argument to be an object.'); | ||
} | ||
const toString = Object.prototype.toString; | ||
const isEnumerable = Object.prototype.propertyIsEnumerable; | ||
const getSymbols = Object.getOwnPropertySymbols; | ||
if (typeof objects === 'undefined' || typeof Symbol === 'undefined') { | ||
return receiver; | ||
module.exports = (target, ...args) => { | ||
if (!isObject(target)) { | ||
throw new TypeError('expected the first argument to be an object'); | ||
} | ||
if (typeof Object.getOwnPropertySymbols !== 'function') { | ||
return receiver; | ||
if (args.length === 0 || typeof Symbol !== 'function' || typeof getSymbols !== 'function') { | ||
return target; | ||
} | ||
var isEnumerable = Object.prototype.propertyIsEnumerable; | ||
var target = Object(receiver); | ||
var len = arguments.length, i = 0; | ||
for (let arg of args) { | ||
let names = getSymbols(arg); | ||
while (++i < len) { | ||
var provider = Object(arguments[i]); | ||
var names = Object.getOwnPropertySymbols(provider); | ||
for (var j = 0; j < names.length; j++) { | ||
var key = names[j]; | ||
if (isEnumerable.call(provider, key)) { | ||
target[key] = provider[key]; | ||
for (let key of names) { | ||
if (isEnumerable.call(arg, key)) { | ||
target[key] = arg[key]; | ||
} | ||
@@ -42,1 +35,5 @@ } | ||
}; | ||
function isObject(val) { | ||
return typeof val === 'function' || toString.call(val) === '[object Object]'; | ||
} |
{ | ||
"name": "assign-symbols", | ||
"description": "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.", | ||
"version": "1.0.0", | ||
"description": "Assign the enumerable es6 Symbol properties from one or more 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.", | ||
"version": "2.0.0", | ||
"homepage": "https://github.com/jonschlinkert/assign-symbols", | ||
@@ -17,3 +17,3 @@ "author": "Jon Schlinkert (https://github.com/jonschlinkert)", | ||
"engines": { | ||
"node": ">=0.10.0" | ||
"node": ">=4.0" | ||
}, | ||
@@ -24,19 +24,37 @@ "scripts": { | ||
"devDependencies": { | ||
"mocha": "^3.0.0" | ||
"gulp-format-md": "^1.0.0", | ||
"mocha": "^5.2.0" | ||
}, | ||
"keywords": [ | ||
"assign", | ||
"es6", | ||
"merge", | ||
"mixin", | ||
"polyfill", | ||
"primitive", | ||
"symbol", | ||
"symbols" | ||
], | ||
"verb": { | ||
"toc": false, | ||
"layout": "default", | ||
"tasks": [ | ||
"readme" | ||
], | ||
"plugins": [ | ||
"gulp-format-md" | ||
], | ||
"related": { | ||
"list": [ | ||
"assign-deep", | ||
"mixin-deep", | ||
"clone-deep", | ||
"extend-shallow", | ||
"merge-deep", | ||
"extend-shallow", | ||
"clone-deep" | ||
"mixin-deep" | ||
] | ||
}, | ||
"lint": { | ||
"reflinks": true | ||
} | ||
} | ||
} |
106
README.md
@@ -1,73 +0,107 @@ | ||
# assign-symbols [![NPM version](https://badge.fury.io/js/assign-symbols.svg)](http://badge.fury.io/js/assign-symbols) | ||
# assign-symbols [![NPM version](https://img.shields.io/npm/v/assign-symbols.svg?style=flat)](https://www.npmjs.com/package/assign-symbols) [![NPM monthly downloads](https://img.shields.io/npm/dm/assign-symbols.svg?style=flat)](https://npmjs.org/package/assign-symbols) [![NPM total downloads](https://img.shields.io/npm/dt/assign-symbols.svg?style=flat)](https://npmjs.org/package/assign-symbols) [![Linux Build Status](https://img.shields.io/travis/jonschlinkert/assign-symbols.svg?style=flat&label=Travis)](https://travis-ci.org/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. | ||
> Assign the enumerable es6 Symbol properties from one or more 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. | ||
From the [Mozilla Developer docs for Symbol](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol): | ||
Please consider following this project's author, [Jon Schlinkert](https://github.com/jonschlinkert), and consider starring the project to show your :heart: and support. | ||
> A symbol is a unique and immutable data type and may be used as an identifier for object properties. The symbol object is an implicit object wrapper for the symbol primitive data type. | ||
## Install | ||
Install with [npm](https://www.npmjs.com/) | ||
Install with [npm](https://www.npmjs.com/): | ||
```sh | ||
$ npm i assign-symbols --save | ||
$ npm install --save assign-symbols | ||
``` | ||
## About | ||
> A symbol is a unique and immutable data type and may be used as an identifier for object properties. The symbol object is an implicit object wrapper for the symbol primitive data type. - [Mozilla Developer docs for Symbol](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol) | ||
## Usage | ||
```js | ||
var assignSymbols = require('assign-symbols'); | ||
var obj = {}; | ||
const assignSymbols = require('assign-symbols'); | ||
let target = {}; | ||
var one = {}; | ||
var symbolOne = Symbol('aaa'); | ||
// add a symbol to object "one" | ||
let one = {}; | ||
let symbolOne = Symbol('aaa'); | ||
one[symbolOne] = 'bbb'; | ||
var two = {}; | ||
var symbolTwo = Symbol('ccc'); | ||
// add a symbol to object "two" | ||
let two = {}; | ||
let symbolTwo = Symbol('ccc'); | ||
two[symbolTwo] = 'ddd'; | ||
assignSymbols(obj, one, two); | ||
// assign symbols from objects "one" and "two" to object "target" | ||
assignSymbols(target, one, two); | ||
console.log(obj[symbolOne]); | ||
//=> 'bbb' | ||
console.log(obj[symbolTwo]); | ||
//=> 'ddd' | ||
console.log(target[symbolOne]); //=> 'bbb' | ||
console.log(target[symbolTwo]); //=> 'ddd' | ||
``` | ||
## Similar projects | ||
## About | ||
* [assign-deep](https://www.npmjs.com/package/assign-deep): Deeply assign the enumerable properties of source objects to a destination object. | [homepage](https://github.com/jonschlinkert/assign-deep) | ||
* [clone-deep](https://www.npmjs.com/package/clone-deep): Recursively (deep) clone JavaScript native types, like Object, Array, RegExp, Date as well as primitives. | [homepage](https://github.com/jonschlinkert/clone-deep) | ||
* [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) | ||
* [merge-deep](https://www.npmjs.com/package/merge-deep): Recursively merge values in a javascript object. | [homepage](https://github.com/jonschlinkert/merge-deep) | ||
* [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) | ||
<details> | ||
<summary><strong>Contributing</strong></summary> | ||
## Running tests | ||
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new). | ||
Install dev dependencies: | ||
</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 i -d && npm test | ||
$ npm install && npm test | ||
``` | ||
## Contributing | ||
</details> | ||
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/jonschlinkert/assign-symbols/issues/new). | ||
<details> | ||
<summary><strong>Building docs</strong></summary> | ||
## Author | ||
_(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.)_ | ||
To generate the readme, run the following command: | ||
```sh | ||
$ npm install -g verbose/verb#dev verb-generate-readme && verb | ||
``` | ||
</details> | ||
### Related projects | ||
You might also be interested in these projects: | ||
* [assign-deep](https://www.npmjs.com/package/assign-deep): Deeply assign the enumerable properties and/or es6 Symbol properies of source objects to the target… [more](https://github.com/jonschlinkert/assign-deep) | [homepage](https://github.com/jonschlinkert/assign-deep "Deeply assign the enumerable properties and/or es6 Symbol properies of source objects to the target (first) object.") | ||
* [clone-deep](https://www.npmjs.com/package/clone-deep): Recursively (deep) clone JavaScript native types, like Object, Array, RegExp, Date as well as primitives. | [homepage](https://github.com/jonschlinkert/clone-deep "Recursively (deep) clone JavaScript native types, like Object, Array, RegExp, Date as well as primitives.") | ||
* [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** | | ||
| --- | --- | | ||
| 4 | [jonschlinkert](https://github.com/jonschlinkert) | | ||
| 2 | [phated](https://github.com/phated) | | ||
### Author | ||
**Jon Schlinkert** | ||
+ [github/jonschlinkert](https://github.com/jonschlinkert) | ||
+ [twitter/jonschlinkert](http://twitter.com/jonschlinkert) | ||
* [LinkedIn Profile](https://linkedin.com/in/jonschlinkert) | ||
* [GitHub Profile](https://github.com/jonschlinkert) | ||
* [Twitter Profile](https://twitter.com/jonschlinkert) | ||
## License | ||
### License | ||
Copyright © 2015 Jon Schlinkert | ||
Released under the MIT license. | ||
Copyright © 2018, [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 November 06, 2015._ | ||
_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on August 06, 2018._ |
Sorry, the diff of this file is not supported yet
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
8423
107
0
2
30