ldc-boutique-cnc-sable/resources/ts/modules/strings.ts
2026-10-27 09:58:12 +01:00

50 lines
1.1 KiB
TypeScript

export function titleCase(value: string): string {
return value
.toLowerCase()
.split(" ")
.map(word => word.charAt(0).toUpperCase() + word.slice(1))
.join(" ");
}
export function kebabCase(value: string): string {
return value
.trim()
.toLowerCase()
.replaceAll(/[^a-zA-Z0-9]/g, " ")
.split(/\s+/)
.filter(Boolean)
.join("-");
}
export function snakeCase(value: string): string {
return value
.trim()
.toLowerCase()
.replaceAll(/[^a-zA-Z0-9]/g, " ")
.split(/\s+/)
.filter(Boolean)
.join("_");
}
export function camelCase(value: string): string {
return value
.trim()
.toLowerCase()
.replaceAll(/[^a-zA-Z0-9]/g, " ")
.split(/\s+/)
.filter(Boolean)
.map((word, index) => index === 0 ? word : word.charAt(0).toUpperCase() + word.slice(1))
.join("");
}
export function pascalCase(value: string): string {
if (!value) return "";
return value
.trim()
.toLowerCase()
.replaceAll(/[^a-zA-Z0-9]/g, " ")
.split(/\s+/)
.filter(Boolean)
.map(word => word.charAt(0).toUpperCase() + word.slice(1))
.join("");
}