aboutsummaryrefslogtreecommitdiff
path: root/node_modules/es5-ext/array/#/copy-within
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/es5-ext/array/#/copy-within')
-rw-r--r--node_modules/es5-ext/array/#/copy-within/implement.js9
-rw-r--r--node_modules/es5-ext/array/#/copy-within/index.js4
-rw-r--r--node_modules/es5-ext/array/#/copy-within/is-implemented.js7
-rw-r--r--node_modules/es5-ext/array/#/copy-within/shim.js45
4 files changed, 65 insertions, 0 deletions
diff --git a/node_modules/es5-ext/array/#/copy-within/implement.js b/node_modules/es5-ext/array/#/copy-within/implement.js
new file mode 100644
index 000000000..20910507a
--- /dev/null
+++ b/node_modules/es5-ext/array/#/copy-within/implement.js
@@ -0,0 +1,9 @@
+"use strict";
+
+if (!require("./is-implemented")()) {
+ Object.defineProperty(Array.prototype, "copyWithin",
+ { value: require("./shim"),
+configurable: true,
+enumerable: false,
+ writable: true });
+}
diff --git a/node_modules/es5-ext/array/#/copy-within/index.js b/node_modules/es5-ext/array/#/copy-within/index.js
new file mode 100644
index 000000000..0919b79b9
--- /dev/null
+++ b/node_modules/es5-ext/array/#/copy-within/index.js
@@ -0,0 +1,4 @@
+"use strict";
+
+module.exports = require("./is-implemented")()
+ ? Array.prototype.copyWithin : require("./shim");
diff --git a/node_modules/es5-ext/array/#/copy-within/is-implemented.js b/node_modules/es5-ext/array/#/copy-within/is-implemented.js
new file mode 100644
index 000000000..40c499e6d
--- /dev/null
+++ b/node_modules/es5-ext/array/#/copy-within/is-implemented.js
@@ -0,0 +1,7 @@
+"use strict";
+
+module.exports = function () {
+ var arr = [1, 2, 3, 4, 5];
+ if (typeof arr.copyWithin !== "function") return false;
+ return String(arr.copyWithin(1, 3)) === "1,4,5,4,5";
+};
diff --git a/node_modules/es5-ext/array/#/copy-within/shim.js b/node_modules/es5-ext/array/#/copy-within/shim.js
new file mode 100644
index 000000000..aad220ca7
--- /dev/null
+++ b/node_modules/es5-ext/array/#/copy-within/shim.js
@@ -0,0 +1,45 @@
+// Taken from: https://github.com/paulmillr/es6-shim/
+
+"use strict";
+
+var toInteger = require("../../../number/to-integer")
+ , toPosInt = require("../../../number/to-pos-integer")
+ , validValue = require("../../../object/valid-value")
+ , objHasOwnProperty = Object.prototype.hasOwnProperty
+ , max = Math.max
+ , min = Math.min;
+
+module.exports = function (target, start /*, end*/) {
+ var arr = validValue(this)
+ , end = arguments[2]
+ , length = toPosInt(arr.length)
+ , to
+ , from
+ , fin
+ , count
+ , direction;
+
+ target = toInteger(target);
+ start = toInteger(start);
+ end = end === undefined ? length : toInteger(end);
+
+ to = target < 0 ? max(length + target, 0) : min(target, length);
+ from = start < 0 ? max(length + start, 0) : min(start, length);
+ fin = end < 0 ? max(length + end, 0) : min(end, length);
+ count = min(fin - from, length - to);
+ direction = 1;
+
+ if (from < to && to < from + count) {
+ direction = -1;
+ from += count - 1;
+ to += count - 1;
+ }
+ while (count > 0) {
+ if (objHasOwnProperty.call(arr, from)) arr[to] = arr[from];
+ else delete arr[from];
+ from += direction;
+ to += direction;
+ count -= 1;
+ }
+ return arr;
+};