Skip to content

Instantly share code, notes, and snippets.

@tyler36
Forked from natemoo-re/README.md
Created June 19, 2024 03:35
Show Gist options
  • Save tyler36/ae69c5379ca47cde6b8946ba082d096a to your computer and use it in GitHub Desktop.
Save tyler36/ae69c5379ca47cde6b8946ba082d096a to your computer and use it in GitHub Desktop.
Visual Studio Code Snippets – Common Case Transformations

Common Case Transformation Snippets

Visual Studio Code allows Snippets to perform ✨Variable Transforms✨ using Regex.

Here are some common case transformations that you can apply to your snippets. In these examples, I'm using $TM_FILENAME_BASE, but the same transformations should apply to any of the Snippet Variables.

snippets-from-delimited.json can convert filenames like my-file-name, my_file_name, my file name. If your filename is delimited by a dash, underscore, or space, these should work.

snippets-from-mixed-case.json can convert filenames like myFileName and MyFileName. If your filename is in camel or Pascal case, these should work.

{
"ConstantCase": {
"prefix": "filename-constant",
"description": "",
"body": "${TM_FILENAME_BASE/(\\w+)?[-_\\s]+(\\w+)/${1:/upcase}_${2:/upcase}/g}"
},
"SnakeCase": {
"prefix": "filename-snake",
"description": "",
"body": "${TM_FILENAME_BASE/(\\w+)?[-_\\s]+(\\w+)/${1:/downcase}_${2:/downcase}/g}"
},
"KebabCase": {
"prefix": "filename-kebab",
"description": "",
"body": "${TM_FILENAME_BASE/(\\w+)?[-_\\s]+(\\w+)/${1:/downcase}-${2:/downcase}/g}"
},
"CamelCase": {
"prefix": "filename-camel",
"description": "",
"body": "${TM_FILENAME_BASE/(\\w+)?[-_\\s]+(\\w+)/${1:/downcase}${2:/capitalize}/g}"
},
"PascalCase": {
"prefix": "filename-pascal",
"description": "",
"body": "${TM_FILENAME_BASE/(\\w+)?[-_\\s]+(\\w+)/${1:/capitalize}${2:/capitalize}/g}"
}
}
{
"PascalCase": {
"prefix": "filename-pascal",
"description": "",
"body": "${TM_FILENAME_BASE/(\\w)([a-z]+)/${1:/capitalize}${2:/downcase}/g}"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment