source: node_modules/ramda-adjunct/lib/internal/ponyfills/String.repeat.js@ d24f17c

main
Last change on this file since d24f17c was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago

Initial commit

  • Property mode set to 100644
File size: 1.5 KB
Line 
1"use strict";
2
3exports.__esModule = true;
4exports["default"] = void 0;
5var _isNotFinite = _interopRequireDefault(require("../../isNotFinite"));
6var _isNegative = _interopRequireDefault(require("../../isNegative"));
7function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
8var 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};
41var _default = repeat;
42exports["default"] = _default;
Note: See TracBrowser for help on using the repository browser.