aboutsummaryrefslogtreecommitdiff
path: root/node_modules/repeat-string/index.js
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/repeat-string/index.js')
-rw-r--r--node_modules/repeat-string/index.js12
1 files changed, 7 insertions, 5 deletions
diff --git a/node_modules/repeat-string/index.js b/node_modules/repeat-string/index.js
index 496c6db26..4459afd80 100644
--- a/node_modules/repeat-string/index.js
+++ b/node_modules/repeat-string/index.js
@@ -40,7 +40,7 @@ module.exports = repeat;
function repeat(str, num) {
if (typeof str !== 'string') {
- throw new TypeError('repeat-string expects a string.');
+ throw new TypeError('expected a string');
}
// cover common, quick use cases
@@ -51,18 +51,20 @@ function repeat(str, num) {
if (cache !== str || typeof cache === 'undefined') {
cache = str;
res = '';
+ } else if (res.length >= max) {
+ return res.substr(0, max);
}
- while (max > res.length && num > 0) {
+ while (max > res.length && num > 1) {
if (num & 1) {
res += str;
}
num >>= 1;
- if (!num) break;
str += str;
}
- return res.substr(0, max);
+ res += str;
+ res = res.substr(0, max);
+ return res;
}
-