Last active
July 19, 2019 08:36
-
-
Save OrderAndCh4oS/9df7d82bccdbb9f57ebd8b47221014a4 to your computer and use it in GitHub Desktop.
Switch String Case. Coverts camelCase or PascalCase to kebab-case or snake_case or any delimited string and vice versa,
This file contains 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 camelCaseToDelimitedString = (string, delimiter = '-') => | |
string.replace(/([a-z0-9]|(?<!^)(?=[A-Z]))([A-Z])/g, '$1'+delimiter+'$2').toLowerCase(); | |
const delimitedStringToCamelCase = (string, delimiter = '-') => | |
string.replace(new RegExp(delimiter + '([a-z])', 'g'), (m, c) => c.toUpperCase()); |
Author
OrderAndCh4oS
commented
Jul 19, 2019
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment