Search code examples
visual-studio-codecode-snippetsvscode-snippets

Capitalize doesn't lowercase trailing characters


I have this snippet:

{
  "Creates async dux modules": {
    "prefix": "dux-async",
    "body": [
      "// Duck module",
      "export const ${1:ModuleName}_REQUEST = \"${1}_REQUEST\";",
      "export const ${1}_SUCCESS = \"${1}_SUCCESS\";",
      "export const ${1}_ERROR = \"${1}_ERROR\";",
      "",
      "/**",
      " * State interface formodule",
      " */",
      "export interface ${1/(.*)/${1:/capitalize}/}State {",

When I tab into my snippet, I want to write FOO, and when I tab off, I want the last line of the snippet to be transformed to:

export interface FooState {

It appears capitalize doesn't lowercase the trailing characters, so I end up with:

export interface FOOState

Is there someway to ensure the first character is uppercase and the others are all lowercase?


Solution

  • "export interface ${1/(.)(.*)/${1:/capitalize}${2:/downcase}/}State {"
    

    works. As you have seen ${1:/capitalize} will only affect the first letter - it has no effect on the others. So if you want to change both, you will have to split up your regex unfortunately.