From 544fa67851125413f84b110a22bb38ba3c243862 Mon Sep 17 00:00:00 2001 From: npezza93 Date: Sat, 27 Jan 2018 22:36:53 -0500 Subject: [PATCH] Move repeat out of generic --- src/handlers/AltClickHandler.ts | 28 ++++++++++++++++++++++++++++ src/utils/Generic.ts | 28 ---------------------------- 2 files changed, 28 insertions(+), 28 deletions(-) diff --git a/src/handlers/AltClickHandler.ts b/src/handlers/AltClickHandler.ts index 94a1a7ecb..6955423ba 100644 --- a/src/handlers/AltClickHandler.ts +++ b/src/handlers/AltClickHandler.ts @@ -251,3 +251,31 @@ export class AltClickHandler { } } } + +/** + * Returns a string repeated a given number of times + * Polyfill from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/repeat + * @param {Number} count The number of times to repeat the string + * @param {String} string The string that is to be repeated + */ +function repeat(count: number, str: string): string { + if (count < 0) throw new RangeError('repeat count must be non-negative'); + if (count === Infinity) throw new RangeError('repeat count must be less than infinity'); + + count = Math.floor(count); + if (str.length === 0 || count === 0) return ''; + + // Ensuring count is a 31-bit integer allows us to heavily optimize the + // main part. But anyway, most current (August 2014) browsers can't handle + // strings 1 << 28 chars or longer, so: + if (str.length * count >= 1 << 28) { + throw new RangeError('repeat count must not overflow maximum string size'); + } + + let rpt = ''; + for (let i = 0; i < count; i++) { + rpt += str; + } + + return rpt; +} diff --git a/src/utils/Generic.ts b/src/utils/Generic.ts index 9f9d2666f..4bc6c487f 100644 --- a/src/utils/Generic.ts +++ b/src/utils/Generic.ts @@ -11,31 +11,3 @@ export function contains(arr: any[], el: any): boolean { return arr.indexOf(el) >= 0; } - -/** - * Returns a string repeated a given number of times - * Polyfill from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/repeat - * @param {Number} count The number of times to repeat the string - * @param {String} string The string that is to be repeated - */ -export function repeat(count: number, str: string): string { - if (count < 0) throw new RangeError('repeat count must be non-negative'); - if (count === Infinity) throw new RangeError('repeat count must be less than infinity'); - - count = Math.floor(count); - if (str.length === 0 || count === 0) return ''; - - // Ensuring count is a 31-bit integer allows us to heavily optimize the - // main part. But anyway, most current (August 2014) browsers can't handle - // strings 1 << 28 chars or longer, so: - if (str.length * count >= 1 << 28) { - throw new RangeError('repeat count must not overflow maximum string size'); - } - - let rpt = ''; - for (let i = 0; i < count; i++) { - rpt += str; - } - - return rpt; -}