shim.js 691 B

123456789101112131415161718192021
  1. // Taken from: https://github.com/paulmillr/es6-shim/
  2. 'use strict';
  3. var toInteger = require('../../../number/to-integer')
  4. , toPosInt = require('../../../number/to-pos-integer')
  5. , validValue = require('../../../object/valid-value')
  6. , max = Math.max, min = Math.min;
  7. module.exports = function (value/*, start, end*/) {
  8. var o = validValue(this), start = arguments[1], end = arguments[2]
  9. , l = toPosInt(o.length), relativeStart, i;
  10. start = (start === undefined) ? 0 : toInteger(start);
  11. end = (end === undefined) ? l : toInteger(end);
  12. relativeStart = start < 0 ? max(l + start, 0) : min(start, l);
  13. for (i = relativeStart; i < l && i < end; ++i) o[i] = value;
  14. return o;
  15. };