39 lines
1.0 KiB
TypeScript
39 lines
1.0 KiB
TypeScript
|
|
const randomChars = () => {
|
||
|
|
const uppercaseAsciiStart = 65;
|
||
|
|
const letterIndex = Math.floor(Math.random() * 26);
|
||
|
|
const letter = String.fromCharCode(uppercaseAsciiStart + letterIndex);
|
||
|
|
|
||
|
|
return letter;
|
||
|
|
};
|
||
|
|
|
||
|
|
const generateNumberPlate = () => {
|
||
|
|
const numberPlateLetters = new Array(4);
|
||
|
|
const characters: string[] = [];
|
||
|
|
for (let index = 0; index <= numberPlateLetters.length; index++) {
|
||
|
|
const letter = randomChars();
|
||
|
|
characters.push(letter);
|
||
|
|
}
|
||
|
|
const number = Math.floor(Math.random() * 99);
|
||
|
|
characters.splice(2, 0, number + " ");
|
||
|
|
const numberPlate = characters.join("");
|
||
|
|
|
||
|
|
return numberPlate;
|
||
|
|
};
|
||
|
|
|
||
|
|
export const generateNumberPlateList = (numberofSightings = 5) => {
|
||
|
|
const numberPlates = [];
|
||
|
|
|
||
|
|
for (let i = 0; i <= numberofSightings; i++) {
|
||
|
|
numberPlates.push(generateNumberPlate());
|
||
|
|
}
|
||
|
|
|
||
|
|
return numberPlates;
|
||
|
|
};
|
||
|
|
|
||
|
|
export const formatNumberPlate = (plate: string) => {
|
||
|
|
const splittedPlate = plate?.split("");
|
||
|
|
splittedPlate?.splice(4, 0, " ");
|
||
|
|
const formattedPlate = splittedPlate?.join("");
|
||
|
|
return formattedPlate;
|
||
|
|
};
|