From 38aa0b2bb93bb1dc414664078f698b6ff87460e0 Mon Sep 17 00:00:00 2001 From: Sergiy Korzh Date: Sun, 22 Oct 2023 10:27:11 +0300 Subject: [PATCH] Update string utils and the randomizer --- easydata.js/packs/core/src/utils/string_utils.ts | 9 ++------- easydata.js/packs/core/src/utils/utils.ts | 8 ++++---- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/easydata.js/packs/core/src/utils/string_utils.ts b/easydata.js/packs/core/src/utils/string_utils.ts index cc5eee38..7c144197 100644 --- a/easydata.js/packs/core/src/utils/string_utils.ts +++ b/easydata.js/packs/core/src/utils/string_utils.ts @@ -1,10 +1,5 @@ -export function repeatString(str: string, times: number): string{ - let result = ""; - for(let i = 0; i < times; i++){ - result += str; - } - - return result; +export function repeatString(str: string, times: number): string { + return str.repeat(times); } export function reverseString(str: string): string{ diff --git a/easydata.js/packs/core/src/utils/utils.ts b/easydata.js/packs/core/src/utils/utils.ts index 5413eeea..8cbff17a 100644 --- a/easydata.js/packs/core/src/utils/utils.ts +++ b/easydata.js/packs/core/src/utils/utils.ts @@ -350,7 +350,7 @@ export namespace utils { } //adding 2 random symbols - var randValue = strf.repeatString("", 2);; + var randValue = strf.repeatString(' ', 2); const maxSymbolIndex = symbols.length - 1; randValue = replaceAtString(randValue, 0, symbols[getRandomInt(0, maxSymbolIndex)]); @@ -364,7 +364,7 @@ export namespace utils { function intToNum36(value: number) { const targetBase = 36; let i = 14; - var buffer = strf.repeatString("", i); + var buffer = strf.repeatString(' ', i); var rest = value; do { buffer = replaceAtString(buffer, i--, symbols[rest % targetBase]); @@ -415,8 +415,8 @@ export namespace utils { } } - function replaceAtString(str: string, index: number, value: string): string { - return str.substr(0, index) + value + str.substr(index + value.length); + function replaceAtString(str: string, index: number, replacement: string): string { + return str.substring(0, index) + replacement + str.substring(index + replacement.length); } function getRandomInt(min, max) {