Last active
March 30, 2020 09:11
-
-
Save avilde/8367bbe12d9b931cee49b058d7ba1b01 to your computer and use it in GitHub Desktop.
Capitalize text and words in text for Nordic countries.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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