Sha256: bafdfbef3e11cbfefbae497da07eb828ce3217579cd939e72e4f275196c7d8a4
Contents?: true
Size: 1.26 KB
Versions: 66
Compression:
Stored size: 1.26 KB
Contents
'use strict'; // https://tc39.github.io/proposal-flatMap/#sec-FlattenIntoArray var isArray = require('./_is-array'); var isObject = require('./_is-object'); var toLength = require('./_to-length'); var ctx = require('./_ctx'); var IS_CONCAT_SPREADABLE = require('./_wks')('isConcatSpreadable'); function flattenIntoArray(target, original, source, sourceLen, start, depth, mapper, thisArg) { var targetIndex = start; var sourceIndex = 0; var mapFn = mapper ? ctx(mapper, thisArg, 3) : false; var element, spreadable; while (sourceIndex < sourceLen) { if (sourceIndex in source) { element = mapFn ? mapFn(source[sourceIndex], sourceIndex, original) : source[sourceIndex]; spreadable = false; if (isObject(element)) { spreadable = element[IS_CONCAT_SPREADABLE]; spreadable = spreadable !== undefined ? !!spreadable : isArray(element); } if (spreadable && depth > 0) { targetIndex = flattenIntoArray(target, original, element, toLength(element.length), targetIndex, depth - 1) - 1; } else { if (targetIndex >= 0x1fffffffffffff) throw TypeError(); target[targetIndex] = element; } targetIndex++; } sourceIndex++; } return targetIndex; } module.exports = flattenIntoArray;
Version data entries
66 entries across 30 versions & 8 rubygems