2023-08-19 16:56:22 +01:00
|
|
|
export default class StringTools {
|
|
|
|
public static Capitalise(str: string): string {
|
|
|
|
const words = str.split(" ");
|
2024-01-05 19:26:44 +00:00
|
|
|
const result: string[] = [];
|
2023-08-19 16:56:22 +01:00
|
|
|
|
|
|
|
words.forEach(word => {
|
|
|
|
const firstLetter = word.substring(0, 1).toUpperCase();
|
|
|
|
const rest = word.substring(1);
|
|
|
|
|
|
|
|
result.push(firstLetter + rest);
|
|
|
|
});
|
|
|
|
|
|
|
|
return result.join(" ");
|
|
|
|
}
|
|
|
|
|
|
|
|
public static CapitaliseArray(str: string[]): string[] {
|
|
|
|
const res: string[] = [];
|
|
|
|
|
|
|
|
str.forEach(s => {
|
|
|
|
res.push(StringTools.Capitalise(s));
|
|
|
|
});
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static RandomString(length: number) {
|
|
|
|
let result = "";
|
|
|
|
|
2024-01-05 19:26:44 +00:00
|
|
|
const characters = "abcdefghkmnpqrstuvwxyz23456789";
|
2023-08-19 16:56:22 +01:00
|
|
|
const charactersLength = characters.length;
|
|
|
|
|
2024-01-05 19:26:44 +00:00
|
|
|
for ( let i = 0; i < length; i++ ) {
|
|
|
|
result += characters.charAt(Math.floor(Math.random() * charactersLength));
|
2023-08-19 16:56:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static ReplaceAll(str: string, find: string, replace: string) {
|
2024-01-05 19:26:44 +00:00
|
|
|
return str.replace(new RegExp(find, "g"), replace);
|
2023-08-19 16:56:22 +01:00
|
|
|
}
|
|
|
|
}
|