Skip to content

Instantly share code, notes, and snippets.

@avilde
Last active March 30, 2020 09:11
Show Gist options
  • Save avilde/8367bbe12d9b931cee49b058d7ba1b01 to your computer and use it in GitHub Desktop.
Save avilde/8367bbe12d9b931cee49b058d7ba1b01 to your computer and use it in GitHub Desktop.
Capitalize text and words in text for Nordic countries.
/**
* Swedish/Finnish special characters: åäö
* Danish/Norwegian special characters: æøå
* Latin characters: a-z
* Other special characters: ç (e.g. country Curaçao)
*/
const wordRegex = /[åäöçæøa-z]+/gi;
export const capitalizeWord = (word: string): string =>
word.charAt(0).toUpperCase() + word.substring(1).toLowerCase();
export const capitalizeText = (text: string): string =>
text.replace(wordRegex, word => capitalizeWord(word));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment