Created
September 23, 2022 13:11
-
-
Save JoepKockelkorn/2899785f302b6a6d2063bb6ccfcfd193 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Name: Change Case | |
// Description: Change casing of selected text | |
const v = await npm("voca"); | |
const text = await getSelectedText(); | |
const pascalCase = (t) => | |
v | |
.camelCase(t) | |
.split("") | |
.map((v, i) => (i === 0 ? v.toUpperCase() : v)) | |
.join(""); | |
const caseMapping = { | |
camelCase: v.camelCase, | |
"kebab-case": v.kebabCase, | |
lowercase: v.lowerCase, | |
UPPERCASE: v.upperCase, | |
snake_case: v.snakeCase, | |
PascalCase: pascalCase, | |
swap: v.swapCase, | |
}; | |
const choices = Object.entries(caseMapping).map(([c, fn]) => ({ | |
value: fn(text), | |
name: fn(text), | |
tag: c, | |
})); | |
const newText = await arg("Select which case", choices); | |
await setSelectedText(newText); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment