Sha256: c5829d54792c1b8d39984c0c1c529e15b54e474400b23db44fce7e1b017e4f94

Contents?: true

Size: 1.8 KB

Versions: 13

Compression:

Stored size: 1.8 KB

Contents

'use strict';
var bind = require('../internals/function-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 iteratorMethod = getIteratorMethod(O);
  var index = 0;
  var length, result, step, iterator, next, value;
  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);
    next = iterator.next;
    result = new C();
    for (;!(step = next.call(iterator)).done; index++) {
      value = mapping ? callWithSafeIterationClosing(iterator, mapfn, [step.value, index], true) : step.value;
      createProperty(result, index, value);
    }
  } else {
    length = toLength(O.length);
    result = new C(length);
    for (;length > index; index++) {
      value = mapping ? mapfn(O[index], index) : O[index];
      createProperty(result, index, value);
    }
  }
  result.length = index;
  return result;
};

Version data entries

13 entries across 13 versions & 4 rubygems

Version Path
optimacms-0.1.61 spec/dummy/node_modules/core-js/internals/array-from.js
tang-0.2.1 spec/tang_app/node_modules/core-js/internals/array-from.js
tang-0.2.0 spec/tang_app/node_modules/core-js/internals/array-from.js
tang-0.1.0 spec/tang_app/node_modules/core-js/internals/array-from.js
tang-0.0.9 spec/tang_app/node_modules/core-js/internals/array-from.js
enju_library-0.3.8 spec/dummy/node_modules/core-js/internals/array-from.js
condenser-0.3 lib/condenser/processors/node_modules/core-js-pure/internals/array-from.js
condenser-0.2 lib/condenser/processors/node_modules/core-js-pure/internals/array-from.js
condenser-0.1 lib/condenser/processors/node_modules/core-js-pure/internals/array-from.js
condenser-0.0.12 lib/condenser/processors/node_modules/core-js-pure/internals/array-from.js
condenser-0.0.11 lib/condenser/processors/node_modules/core-js-pure/internals/array-from.js
condenser-0.0.10 lib/condenser/processors/node_modules/core-js-pure/internals/array-from.js
condenser-0.0.9 lib/condenser/processors/node_modules/core-js-pure/internals/array-from.js