UNPKG

580 BJavaScriptView Raw
1'use strict';
2var toInteger = require('../internals/to-integer');
3var requireObjectCoercible = require('../internals/require-object-coercible');
4
5// `String.prototype.repeat` method implementation
6// https://tc39.github.io/ecma262/#sec-string.prototype.repeat
7module.exports = ''.repeat || function repeat(count) {
8 var str = String(requireObjectCoercible(this));
9 var result = '';
10 var n = toInteger(count);
11 if (n < 0 || n == Infinity) throw RangeError('Wrong number of repetitions');
12 for (;n > 0; (n >>>= 1) && (str += str)) if (n & 1) result += str;
13 return result;
14};