2 * repeat-string <https://github.com/jonschlinkert/repeat-string>
4 * Copyright (c) 2014-2015, Jon Schlinkert.
5 * Licensed under the MIT License.
21 module.exports = repeat;
24 * Repeat the given `string` the specified `number`
30 * var repeat = require('repeat-string');
35 * @param {String} `string` The string to repeat
36 * @param {Number} `number` The number of times to repeat the string
37 * @return {String} Repeated string
41 function repeat(str, num) {
42 if (typeof str !== 'string') {
43 throw new TypeError('expected a string');
46 // cover common, quick use cases
47 if (num === 1) return str;
48 if (num === 2) return str + str;
50 var max = str.length * num;
51 if (cache !== str || typeof cache === 'undefined') {
54 } else if (res.length >= max) {
55 return res.substr(0, max);
58 while (max > res.length && num > 1) {
68 res = res.substr(0, max);