Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Snippet variables kebabcase transform #145654

Open
RayPS opened this issue Mar 22, 2022 · 2 comments
Open

Snippet variables kebabcase transform #145654

RayPS opened this issue Mar 22, 2022 · 2 comments
Assignees
Labels
feature-request Request for new features or functionality snippets
Milestone

Comments

@RayPS
Copy link

RayPS commented Mar 22, 2022

Currently we have upcase, downcase, capitalize, camelcase, pascalcase transforms.

Example for adding kebabcase transform:

TM_FILENAME_BASE is UserProfileItem

"${TM_FILENAME_BASE/(.*)/${1:/kebabcase}/}"

Result:

user-profile-item

Also suggesting other cases that could be useful.

Case Result Already Have
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
@jrieken jrieken added feature-request Request for new features or functionality snippets labels Mar 22, 2022
@jrieken jrieken added this to the Backlog milestone Mar 22, 2022
@ArturoDent
Copy link

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"]
  },
}

@xianghongai
Copy link

xianghongai commented May 21, 2023

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}"
		]
	},

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request Request for new features or functionality snippets
Projects
None yet
Development

No branches or pull requests

4 participants