[d24f17c] | 1 | "use strict";
|
---|
| 2 |
|
---|
| 3 | exports.__esModule = true;
|
---|
| 4 | exports["default"] = void 0;
|
---|
| 5 | var _isNotFinite = _interopRequireDefault(require("../../isNotFinite"));
|
---|
| 6 | var _isNegative = _interopRequireDefault(require("../../isNegative"));
|
---|
| 7 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
---|
| 8 | var repeat = function repeat(value, count) {
|
---|
| 9 | var validCount = Number(count);
|
---|
| 10 | if (validCount !== count) {
|
---|
| 11 | validCount = 0;
|
---|
| 12 | }
|
---|
| 13 | if ((0, _isNegative["default"])(validCount)) {
|
---|
| 14 | throw new RangeError('repeat count must be non-negative');
|
---|
| 15 | }
|
---|
| 16 | if ((0, _isNotFinite["default"])(validCount)) {
|
---|
| 17 | throw new RangeError('repeat count must be less than infinity');
|
---|
| 18 | }
|
---|
| 19 | validCount = Math.floor(validCount);
|
---|
| 20 | if (value.length === 0 || validCount === 0) {
|
---|
| 21 | return '';
|
---|
| 22 | }
|
---|
| 23 |
|
---|
| 24 | // Ensuring validCount is a 31-bit integer allows us to heavily optimize the
|
---|
| 25 | // main part. But anyway, most current (August 2014) browsers can't handle
|
---|
| 26 | // strings 1 << 28 chars or longer, so:
|
---|
| 27 | // eslint-disable-next-line no-bitwise
|
---|
| 28 | if (value.length * validCount >= 1 << 28) {
|
---|
| 29 | throw new RangeError('repeat count must not overflow maximum string size');
|
---|
| 30 | }
|
---|
| 31 | var maxCount = value.length * validCount;
|
---|
| 32 | validCount = Math.floor(Math.log(validCount) / Math.log(2));
|
---|
| 33 | var result = value;
|
---|
| 34 | while (validCount) {
|
---|
| 35 | result += value;
|
---|
| 36 | validCount -= 1;
|
---|
| 37 | }
|
---|
| 38 | result += result.substring(0, maxCount - result.length);
|
---|
| 39 | return result;
|
---|
| 40 | };
|
---|
| 41 | var _default = repeat;
|
---|
| 42 | exports["default"] = _default; |
---|