Created
April 17, 2022 22:07
-
-
Save fzn0x/f79dd3ab606520ee047a68fc6f1cd4a9 to your computer and use it in GitHub Desktop.
Convert camelCase to snakeCase without including capital-only word, first capital word like replace(/([A-Z])/g, "_$1").toLowerCase(); to lower case.
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 toSnakeCase = str => | |
str && | |
str | |
.match(/[A-Z]{2,}(?=[A-Z][a-z]+[0-9]*|\b)|[A-Z]?[a-z]+[0-9]*|[A-Z]|[0-9]+/g) | |
.map(x => x.toLowerCase()) | |
.join('_'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment