1 var toInteger = require('./toInteger'),
2 toString = require('./toString');
4 /** Used as references for various `Number` constants. */
5 var MAX_SAFE_INTEGER = 9007199254740991;
7 /* Built-in method references for those with the same name as other `lodash` methods. */
8 var nativeFloor = Math.floor;
11 * Repeats the given string `n` times.
16 * @param {string} [string=''] The string to repeat.
17 * @param {number} [n=0] The number of times to repeat the string.
18 * @returns {string} Returns the repeated string.
30 function repeat(string, n) {
31 string = toString(string);
35 if (!string || n < 1 || n > MAX_SAFE_INTEGER) {
38 // Leverage the exponentiation by squaring algorithm for a faster repeat.
39 // See https://en.wikipedia.org/wiki/Exponentiation_by_squaring for more details.
44 n = nativeFloor(n / 2);
51 module.exports = repeat;