2

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
Ivan Solobear
  • 399
  • 1
  • 3
  • 8

1 Answers1

2

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".

Mark
  • 143,421
  • 24
  • 428
  • 436
  • i cant publicly change your score. so FYI I did upvote you. But there is a problem , you regex does not support cases where only one word appears. for example: thisIsTest would become THIS_IS_TEST, but the word : test, would become test instead of TEST – Ivan Solobear Jul 05 '20 at 15:14
  • I made a couple of changes so it now works for any number of "words" in the variable name. [You were unable to upvote before, you need a minimum of 15 reputation.] – Mark Jul 05 '20 at 17:40