Random case vaultId

This commit is contained in:
Andras Schmelczer 2025-04-07 22:23:23 +01:00
parent a86a056888
commit ff02fee6a5
No known key found for this signature in database
GPG key ID: FC8F2C3D3D1A718C
5 changed files with 49 additions and 24 deletions

View file

@ -0,0 +1,11 @@
import { randomCasing } from "./random-casing";
describe("randomCasing", () => {
it("simple test", () => {
const input =
"hello, this is a really long string with a lot of characters";
const result = randomCasing(input);
expect(result.toLowerCase()).toBe(input.toLowerCase());
expect(result).not.toBe(input);
});
});

View file

@ -0,0 +1,10 @@
export function randomCasing(str: string): string {
const chars = str.split("");
const randomCasedChars = chars.map((char) => {
if (Math.random() < 0.5) {
return char.toUpperCase();
}
return char.toLowerCase();
});
return randomCasedChars.join("");
}