Skip to content

Commit

Permalink
Update string utils and the randomizer
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergiy Korzh committed Oct 22, 2023
1 parent af92aa2 commit 38aa0b2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
9 changes: 2 additions & 7 deletions easydata.js/packs/core/src/utils/string_utils.ts
Original file line number Diff line number Diff line change
@@ -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{
Expand Down
8 changes: 4 additions & 4 deletions easydata.js/packs/core/src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)]);
Expand All @@ -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]);
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 38aa0b2

Please sign in to comment.