1 | 'use strict';
|
---|
2 |
|
---|
3 | // modified from https://github.com/es-shims/es6-shim
|
---|
4 | var keys = require('object-keys');
|
---|
5 | var canBeObject = function (obj) {
|
---|
6 | return typeof obj !== 'undefined' && obj !== null;
|
---|
7 | };
|
---|
8 | var hasSymbols = require('has-symbols/shams')();
|
---|
9 | var callBound = require('call-bind/callBound');
|
---|
10 | var toObject = Object;
|
---|
11 | var $push = callBound('Array.prototype.push');
|
---|
12 | var $propIsEnumerable = callBound('Object.prototype.propertyIsEnumerable');
|
---|
13 | var originalGetSymbols = hasSymbols ? Object.getOwnPropertySymbols : null;
|
---|
14 |
|
---|
15 | // eslint-disable-next-line no-unused-vars
|
---|
16 | module.exports = function assign(target, source1) {
|
---|
17 | if (!canBeObject(target)) { throw new TypeError('target must be an object'); }
|
---|
18 | var objTarget = toObject(target);
|
---|
19 | var s, source, i, props, syms, value, key;
|
---|
20 | for (s = 1; s < arguments.length; ++s) {
|
---|
21 | source = toObject(arguments[s]);
|
---|
22 | props = keys(source);
|
---|
23 | var getSymbols = hasSymbols && (Object.getOwnPropertySymbols || originalGetSymbols);
|
---|
24 | if (getSymbols) {
|
---|
25 | syms = getSymbols(source);
|
---|
26 | for (i = 0; i < syms.length; ++i) {
|
---|
27 | key = syms[i];
|
---|
28 | if ($propIsEnumerable(source, key)) {
|
---|
29 | $push(props, key);
|
---|
30 | }
|
---|
31 | }
|
---|
32 | }
|
---|
33 | for (i = 0; i < props.length; ++i) {
|
---|
34 | key = props[i];
|
---|
35 | value = source[key];
|
---|
36 | if ($propIsEnumerable(source, key)) {
|
---|
37 | objTarget[key] = value;
|
---|
38 | }
|
---|
39 | }
|
---|
40 | }
|
---|
41 | return objTarget;
|
---|
42 | };
|
---|