]> git.r.bdr.sh - rbdr/dotfiles/blob
8b28e4ae03b70ffa5705406c28dfb7a7867f4b4d
[rbdr/dotfiles] /
1 'use strict';
2
3 var isPlainArray = require('../../is-plain-array')
4 , toPosInt = require('../../../number/to-pos-integer')
5 , isObject = require('../../../object/is-object')
6
7 , isArray = Array.isArray, concat = Array.prototype.concat
8 , forEach = Array.prototype.forEach
9
10 , isSpreadable;
11
12 isSpreadable = function (value) {
13 if (!value) return false;
14 if (!isObject(value)) return false;
15 if (value['@@isConcatSpreadable'] !== undefined) {
16 return Boolean(value['@@isConcatSpreadable']);
17 }
18 return isArray(value);
19 };
20
21 module.exports = function (item/*, …items*/) {
22 var result;
23 if (!this || !isArray(this) || isPlainArray(this)) {
24 return concat.apply(this, arguments);
25 }
26 result = new this.constructor(this.length);
27 forEach.call(this, function (val, i) { result[i] = val; });
28 forEach.call(arguments, function (arg) {
29 var base;
30 if (isSpreadable(arg)) {
31 base = result.length;
32 result.length += toPosInt(arg.length);
33 forEach.call(arg, function (val, i) { result[base + i] = val; });
34 return;
35 }
36 result.push(arg);
37 });
38 return result;
39 };