From d1291f67551c58168af43698a359cb5ddfd266b0 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Thu, 3 Nov 2016 01:33:53 +0100 Subject: node_modules --- node_modules/repeat-string/index.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'node_modules/repeat-string/index.js') 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; } - -- cgit v1.2.3