aboutsummaryrefslogtreecommitdiff
path: root/node_modules/es5-ext/array/#/concat
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2017-08-14 05:01:11 +0200
committerFlorian Dold <florian.dold@gmail.com>2017-08-14 05:02:09 +0200
commit363723fc84f7b8477592e0105aeb331ec9a017af (patch)
tree29f92724f34131bac64d6a318dd7e30612e631c7 /node_modules/es5-ext/array/#/concat
parent5634e77ad96bfe1818f6b6ee70b7379652e5487f (diff)
node_modules
Diffstat (limited to 'node_modules/es5-ext/array/#/concat')
-rw-r--r--node_modules/es5-ext/array/#/concat/implement.js8
-rw-r--r--node_modules/es5-ext/array/#/concat/index.js4
-rw-r--r--node_modules/es5-ext/array/#/concat/is-implemented.js7
-rw-r--r--node_modules/es5-ext/array/#/concat/shim.js48
4 files changed, 67 insertions, 0 deletions
diff --git a/node_modules/es5-ext/array/#/concat/implement.js b/node_modules/es5-ext/array/#/concat/implement.js
new file mode 100644
index 000000000..a5a1a4090
--- /dev/null
+++ b/node_modules/es5-ext/array/#/concat/implement.js
@@ -0,0 +1,8 @@
+"use strict";
+
+if (!require("./is-implemented")()) {
+ Object.defineProperty(Array.prototype, "concat", { value: require("./shim"),
+ configurable: true,
+enumerable: false,
+writable: true });
+}
diff --git a/node_modules/es5-ext/array/#/concat/index.js b/node_modules/es5-ext/array/#/concat/index.js
new file mode 100644
index 000000000..8bbb7bc19
--- /dev/null
+++ b/node_modules/es5-ext/array/#/concat/index.js
@@ -0,0 +1,4 @@
+"use strict";
+
+module.exports = require("./is-implemented")()
+ ? Array.prototype.concat : require("./shim");
diff --git a/node_modules/es5-ext/array/#/concat/is-implemented.js b/node_modules/es5-ext/array/#/concat/is-implemented.js
new file mode 100644
index 000000000..2a3a9fc60
--- /dev/null
+++ b/node_modules/es5-ext/array/#/concat/is-implemented.js
@@ -0,0 +1,7 @@
+"use strict";
+
+var SubArray = require("../../_sub-array-dummy-safe");
+
+module.exports = function () {
+ return (new SubArray()).concat("foo") instanceof SubArray;
+};
diff --git a/node_modules/es5-ext/array/#/concat/shim.js b/node_modules/es5-ext/array/#/concat/shim.js
new file mode 100644
index 000000000..5158dde52
--- /dev/null
+++ b/node_modules/es5-ext/array/#/concat/shim.js
@@ -0,0 +1,48 @@
+"use strict";
+
+var isPlainArray = require("../../is-plain-array")
+ , toPosInt = require("../../../number/to-pos-integer")
+ , isObject = require("../../../object/is-object")
+ , isConcatSpreadable = require("es6-symbol").isConcatSpreadable
+ , isArray = Array.isArray
+ , concat = Array.prototype.concat
+ , forEach = Array.prototype.forEach
+ , isSpreadable;
+
+isSpreadable = function (value) {
+ if (!value) return false;
+ if (!isObject(value)) return false;
+ if (value[isConcatSpreadable] !== undefined) {
+ return Boolean(value[isConcatSpreadable]);
+ }
+ return isArray(value);
+};
+
+// eslint-disable-next-line no-unused-vars
+module.exports = function (item /*, …items*/) {
+ var result;
+ if (!this || !isArray(this) || isPlainArray(this)) {
+ return concat.apply(this, arguments);
+ }
+ result = new this.constructor();
+ if (isSpreadable(this)) {
+ forEach.call(this, function (val, i) {
+ result[i] = val;
+ });
+ } else {
+ result[0] = this;
+ }
+ forEach.call(arguments, function (arg) {
+ var base;
+ if (isSpreadable(arg)) {
+ base = result.length;
+ result.length += toPosInt(arg.length);
+ forEach.call(arg, function (val, i) {
+ result[base + i] = val;
+ });
+ return;
+ }
+ result.push(arg);
+ });
+ return result;
+};