aboutsummaryrefslogtreecommitdiff
path: root/node_modules/core-js/internals/flatten-into-array.js
diff options
context:
space:
mode:
authorPriyansh <[email protected]>2020-12-22 17:49:59 +0530
committerPriyansh <[email protected]>2020-12-22 17:49:59 +0530
commite93da8b04da86773247aadb1cbb1912e4f4526b2 (patch)
treeeb4ef3203a92ed3dbd2252ddb1ea23bd2d670c98 /node_modules/core-js/internals/flatten-into-array.js
parenta5743c293dcb435e4b159a4df791f8955a4110ec (diff)
downloadstyx-e93da8b04da86773247aadb1cbb1912e4f4526b2.tar.xz
styx-e93da8b04da86773247aadb1cbb1912e4f4526b2.zip
Rewriting Project
Diffstat (limited to 'node_modules/core-js/internals/flatten-into-array.js')
-rw-r--r--node_modules/core-js/internals/flatten-into-array.js32
1 files changed, 32 insertions, 0 deletions
diff --git a/node_modules/core-js/internals/flatten-into-array.js b/node_modules/core-js/internals/flatten-into-array.js
new file mode 100644
index 0000000..df29916
--- /dev/null
+++ b/node_modules/core-js/internals/flatten-into-array.js
@@ -0,0 +1,32 @@
+'use strict';
+var isArray = require('../internals/is-array');
+var toLength = require('../internals/to-length');
+var bind = require('../internals/function-bind-context');
+
+// `FlattenIntoArray` abstract operation
+// https://tc39.github.io/proposal-flatMap/#sec-FlattenIntoArray
+var flattenIntoArray = function (target, original, source, sourceLen, start, depth, mapper, thisArg) {
+ var targetIndex = start;
+ var sourceIndex = 0;
+ var mapFn = mapper ? bind(mapper, thisArg, 3) : false;
+ var element;
+
+ while (sourceIndex < sourceLen) {
+ if (sourceIndex in source) {
+ element = mapFn ? mapFn(source[sourceIndex], sourceIndex, original) : source[sourceIndex];
+
+ if (depth > 0 && isArray(element)) {
+ targetIndex = flattenIntoArray(target, original, element, toLength(element.length), targetIndex, depth - 1) - 1;
+ } else {
+ if (targetIndex >= 0x1FFFFFFFFFFFFF) throw TypeError('Exceed the acceptable array length');
+ target[targetIndex] = element;
+ }
+
+ targetIndex++;
+ }
+ sourceIndex++;
+ }
+ return targetIndex;
+};
+
+module.exports = flattenIntoArray;