Skip to content

Instantly share code, notes, and snippets.

@JoepKockelkorn
Created September 23, 2022 13:11
Show Gist options
  • Save JoepKockelkorn/2899785f302b6a6d2063bb6ccfcfd193 to your computer and use it in GitHub Desktop.
Save JoepKockelkorn/2899785f302b6a6d2063bb6ccfcfd193 to your computer and use it in GitHub Desktop.
// 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