Open RayPS opened 2 years ago
In the meantime as a workaround, this extension Find and Transform use the built-in editor.action.transformToKebabcase
command (in a keybinding, not a snippet) together with any snippet variable, like ${fileBasenameNoExtension}
to accomplish what you want. For example, this keybinding (in keybindings.json
) would insert the kebabed-case version of ${fileBasenameNoExtension}
at the cursor:
{
"key": "alt+s", // whatever keybinding you want
"command": "findInCurrentFile",
"args": {
"replace": "${fileBasenameNoExtension}",
"postCommands": ["editor.action.transformToKebabcase", "cancelSelection"]
},
}
The following rules are not implemented by chatGPT. Need official native support:
Input:
foo__bar-baz-qux
FooBarBazQux
fooBarBazQux
foo-bar-baz-qux
foo_bar_baz_qux
foo.bar.baz.qux
FOO_BAR_BAZ_QUX
foo/bar/baz/qux
foo bar baz qux
Output: foo-bar-baz-qux
"kebab-case": {
"prefix": "kc",
// "${CLIPBOARD/(\\w+)?[-_\\s]+(\\w+)/${1:/downcase}-${2:/downcase}/g}"
// "${CLIPBOARD/(\\s+)|([A-Z]+)|[^\\w\\s]/${1:/downcase}-${2:/downcase}/g}"
// "${CLIPBOARD/([A-Z]+)|([^\\w\\s])|([\\s_]+)/${1:/downcase}${2:+-}${3:/downcase}/g}"
// "${CLIPBOARD/([^\\w\\s])|([\\s_]+)|([A-Z]+[^A-Z\\s]+)/${1:+-}${2:+-}${3:/downcase}/g}" // "${CLIPBOARD/(\\s+)|([A-Z]+)|([\\s_/\\.-]+)|([^\\w\\s])|([a-z]+[^\\w\\s]*)/${1:+-}${2:+-}${3:+-}${4:+-}${5:/downcase}/gi}"
// "${CLIPBOARD/[^a-zA-Z0-9]+/-/g}"
"body": [
"${CLIPBOARD/([A-Z]+|[A-Z]?[a-z]+)(?=$|\\W)/${1:/downcase}-/g}"
]
},
Currently we have
upcase
,downcase
,capitalize
,camelcase
,pascalcase
transforms.Example for adding
kebabcase
transform:TM_FILENAME_BASE
isUserProfileItem
Result:
camelcase
userProfileItem
pascalcase
UserProfileItem
kebabcase
user-profile-item
snakecase
user_profile_item
dotcase
user.profile.item
slashcase
user/profile/item
titlecase
User Profile Item
sentencecase
User profile item