blob: ccae0d7c328b09bb8bde77c0097cf1975798270e [file] [log] [blame]
Leo Repp58b9f112021-11-22 11:57:47 +01001'use strict';
2var isFinite = require('is-finite');
3
4module.exports = function (str, n) {
5 if (typeof str !== 'string') {
6 throw new TypeError('Expected `input` to be a string');
7 }
8
9 if (n < 0 || !isFinite(n)) {
10 throw new TypeError('Expected `count` to be a positive finite number');
11 }
12
13 var ret = '';
14
15 do {
16 if (n & 1) {
17 ret += str;
18 }
19
20 str += str;
21 } while ((n >>= 1));
22
23 return ret;
24};