const case in vscode snippets

Viewed 100

Hey i'm looking for a way to make a vscode snippet turn my variable name to const case:

for example

${1:regular}
${1:/constCase/}

if I write heyThisIsVariable in it, it will become:

heyThisIsVariable
HEY_THIS_IS_VARIABLE
1 Answers

Try this in your snippet:

"body": [
  "$1",
  "${1/([a-z]+)|([A-Z][^A-Z]*)/${1:/upcase}${2:+_}${2:/upcase}/g}",
]

It works for any number (1 to infinity) of "words".

Related