Sha256: b1e833395d7d07bc6b3c5c5c1257f7b23e13d70128d1a601d5d7622d930cc3b2

Contents?: true

Size: 1.73 KB

Versions: 10

Compression:

Stored size: 1.73 KB

Contents

'use strict';
var bind = require('../internals/bind-context');
var toObject = require('../internals/to-object');
var callWithSafeIterationClosing = require('../internals/call-with-safe-iteration-closing');
var isArrayIteratorMethod = require('../internals/is-array-iterator-method');
var toLength = require('../internals/to-length');
var createProperty = require('../internals/create-property');
var getIteratorMethod = require('../internals/get-iterator-method');

// `Array.from` method implementation
// https://tc39.github.io/ecma262/#sec-array.from
module.exports = function from(arrayLike /* , mapfn = undefined, thisArg = undefined */) {
  var O = toObject(arrayLike);
  var C = typeof this == 'function' ? this : Array;
  var argumentsLength = arguments.length;
  var mapfn = argumentsLength > 1 ? arguments[1] : undefined;
  var mapping = mapfn !== undefined;
  var index = 0;
  var iteratorMethod = getIteratorMethod(O);
  var length, result, step, iterator;
  if (mapping) mapfn = bind(mapfn, argumentsLength > 2 ? arguments[2] : undefined, 2);
  // if the target is not iterable or it's an array with the default iterator - use a simple case
  if (iteratorMethod != undefined && !(C == Array && isArrayIteratorMethod(iteratorMethod))) {
    iterator = iteratorMethod.call(O);
    result = new C();
    for (;!(step = iterator.next()).done; index++) {
      createProperty(result, index, mapping
        ? callWithSafeIterationClosing(iterator, mapfn, [step.value, index], true)
        : step.value
      );
    }
  } else {
    length = toLength(O.length);
    result = new C(length);
    for (;length > index; index++) {
      createProperty(result, index, mapping ? mapfn(O[index], index) : O[index]);
    }
  }
  result.length = index;
  return result;
};

Version data entries

10 entries across 10 versions & 3 rubygems

Version Path
condenser-0.0.8 lib/condenser/processors/node_modules/core-js-pure/internals/array-from.js
jester-data-8.0.0 node_modules/core-js/internals/array-from.js
ezii-os-5.2.1 node_modules/core-js/internals/array-from.js
ezii-os-2.0.1 node_modules/core-js/internals/array-from.js
ezii-os-1.1.0 node_modules/core-js/internals/array-from.js
ezii-os-1.0.0 node_modules/core-js/internals/array-from.js
condenser-0.0.7 lib/condenser/processors/node_modules/core-js-pure/internals/array-from.js
ezii-os-0.0.0.1.0 node_modules/core-js/internals/array-from.js
ezii-os-0.0.0.0.1 node_modules/core-js/internals/array-from.js
condenser-0.0.5 lib/condenser/processors/node_modules/core-js-pure/internals/array-from.js