Last active
June 10, 2021 23:50
-
-
Save jpalomar/2bcd6093965ec15ec587a80bab13dd46 to your computer and use it in GitHub Desktop.
convert a string to SCREAMING_SNAKE_CASE
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
const toScreamingSnakeCase = ( | |
str: string, | |
{ WORD_SEPARATORS, CAPITALS } = { | |
WORD_SEPARATORS: /[\s\u2000-\u206F\u2E00-\u2E7F\\'!"#$%&()*+,\-.\/:;<=>?@\[\]^_`{|}~]+/, | |
CAPITALS: /[A-Z\u00C0-\u00D6\u00D9-\u00DD]/g, | |
} | |
): string => | |
str | |
.replace(CAPITALS, (match) => ' ' + (match.toUpperCase() || match)) | |
.trim() | |
.split(WORD_SEPARATORS) | |
.join('_'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment