2 * repeat-string <https://github.com/jonschlinkert/repeat-string>
4 * Copyright (c) 2014-2015, Jon Schlinkert.
5 * Licensed under the MIT License.
14 module.exports = repeat;
17 * Repeat the given `string` the specified `number`
23 * var repeat = require('repeat-string');
28 * @param {String} `string` The string to repeat
29 * @param {Number} `number` The number of times to repeat the string
30 * @return {String} Repeated string
34 function repeat(str, num) {
35 if (typeof str !== 'string') {
36 throw new TypeError('repeat-string expects a string.');
39 if (num === 1) return str;
40 if (num === 2) return str + str;
42 var max = str.length * num;
43 if (cache !== str || typeof cache === 'undefined') {
48 while (max > res.length && num > 0) {
58 return res.substr(0, max);