Skip to content

Commit

Permalink
fix(random): refactor alpha function to resolve failing test
Browse files Browse the repository at this point in the history
  • Loading branch information
jackfiszr committed Dec 19, 2024
1 parent e6df171 commit 128e0e3
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lib/random.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,17 +272,19 @@ class Random {
upcase?: boolean;
} | number,
): string => {
if (typeof options === "number") options = { count: options };
// Extract options with safe defaults
const { count = 1, upcase = false } = typeof options === "number"
? { count: options }
: options || {};

options = options || { count: 1, upcase: false };
const letters = "abcdefghijklmnopqrstuvwxyz";
let wholeString = "";

for (let i = 0; i < options.count!; i++) {
for (let i = 0; i < count; i++) {
wholeString += this.faker.random.arrayElement(letters.split(""));
}

return options.upcase ? wholeString.toUpperCase() : wholeString;
return upcase ? wholeString.toUpperCase() : wholeString;
};

/**
Expand Down

0 comments on commit 128e0e3

Please sign in to comment.