19 lines
442 B
TypeScript
19 lines
442 B
TypeScript
export function toSlug(text: string): string {
|
|
return encodeURIComponent(
|
|
text
|
|
.toLowerCase()
|
|
.trim()
|
|
.replace(/\s+/g, "-")
|
|
);
|
|
}
|
|
|
|
export function fromSlug(slug: string): string {
|
|
return decodeURIComponent(slug)
|
|
.replace(/-/g, " ")
|
|
.replace(/\b\w/g, c => c.toUpperCase());
|
|
}
|
|
|
|
export function capitalizeWords(text: string): string {
|
|
return text.replace(/\b\w/g, c => c.toUpperCase());
|
|
}
|