summaryrefslogtreecommitdiff
path: root/src/node_modules/es-abstract/2019/FlattenIntoArray.js
diff options
context:
space:
mode:
authorMinteck <contact@minteck.org>2021-12-21 16:52:28 +0100
committerMinteck <contact@minteck.org>2021-12-21 16:52:28 +0100
commit46e43f4bde4a35785b4997b81e86cd19f046b69b (patch)
treec53c2f826f777f9d6b2d249dab556feb72a6c3a6 /src/node_modules/es-abstract/2019/FlattenIntoArray.js
downloadlangdetect-46e43f4bde4a35785b4997b81e86cd19f046b69b.tar.gz
langdetect-46e43f4bde4a35785b4997b81e86cd19f046b69b.tar.bz2
langdetect-46e43f4bde4a35785b4997b81e86cd19f046b69b.zip
Commit
Diffstat (limited to 'src/node_modules/es-abstract/2019/FlattenIntoArray.js')
-rw-r--r--src/node_modules/es-abstract/2019/FlattenIntoArray.js58
1 files changed, 58 insertions, 0 deletions
diff --git a/src/node_modules/es-abstract/2019/FlattenIntoArray.js b/src/node_modules/es-abstract/2019/FlattenIntoArray.js
new file mode 100644
index 0000000..5d6254e
--- /dev/null
+++ b/src/node_modules/es-abstract/2019/FlattenIntoArray.js
@@ -0,0 +1,58 @@
+'use strict';
+
+var GetIntrinsic = require('../GetIntrinsic');
+
+var $TypeError = GetIntrinsic('%TypeError%');
+
+var MAX_SAFE_INTEGER = require('../helpers/maxSafeInteger');
+
+var Call = require('./Call');
+var CreateDataPropertyOrThrow = require('./CreateDataPropertyOrThrow');
+var Get = require('./Get');
+var HasProperty = require('./HasProperty');
+var IsArray = require('./IsArray');
+var ToLength = require('./ToLength');
+var ToString = require('./ToString');
+
+// https://ecma-international.org/ecma-262/10.0/#sec-flattenintoarray
+
+// eslint-disable-next-line max-params
+module.exports = function FlattenIntoArray(target, source, sourceLen, start, depth) {
+ var mapperFunction;
+ if (arguments.length > 5) {
+ mapperFunction = arguments[5];
+ }
+
+ var targetIndex = start;
+ var sourceIndex = 0;
+ while (sourceIndex < sourceLen) {
+ var P = ToString(sourceIndex);
+ var exists = HasProperty(source, P);
+ if (exists === true) {
+ var element = Get(source, P);
+ if (typeof mapperFunction !== 'undefined') {
+ if (arguments.length <= 6) {
+ throw new $TypeError('Assertion failed: thisArg is required when mapperFunction is provided');
+ }
+ element = Call(mapperFunction, arguments[6], [element, sourceIndex, source]);
+ }
+ var shouldFlatten = false;
+ if (depth > 0) {
+ shouldFlatten = IsArray(element);
+ }
+ if (shouldFlatten) {
+ var elementLen = ToLength(Get(element, 'length'));
+ targetIndex = FlattenIntoArray(target, element, elementLen, targetIndex, depth - 1);
+ } else {
+ if (targetIndex >= MAX_SAFE_INTEGER) {
+ throw new $TypeError('index too large');
+ }
+ CreateDataPropertyOrThrow(target, ToString(targetIndex), element);
+ targetIndex += 1;
+ }
+ }
+ sourceIndex += 1;
+ }
+
+ return targetIndex;
+};