import "@johnlindquist/kit";
const changeCase = await npm("change-case");
let text = await getSelectedText();
if (text.length <= 1) {
text = await arg("No text selected. What text should be transformed?");
}
const method = await arg(
"What transformation would you like to apply to your text?",
[
{
name: "Camel",
description: `test string -> testString`,
value: "camelCase",
},
{
name: "Capital",
description: `test string -> Test String`,
value: "capitalCase",
},
{
name: "Constant",
description: `test string -> TEST_STRING`,
value: "constantCase",
},
{
name: "Dot",
description: `test string -> test.string`,
value: "dotCase",
},
{
name: "Header",
description: `test string -> Test-String`,
value: "headerCase",
},
{
name: "Lower Case",
description: `test string -> test string`,
value: "noCase",
},
{
name: "Slugify (dashes)",
description: `test string -> test-string`,
value: "paramCase",
},
{
name: "Pascal",
description: `test string -> TestString`,
value: "pascalCase",
},
{
name: "Path",
description: `test string -> test/string`,
value: "pathCase",
},
{
name: "Sentence",
description: `test string -> Test string`,
value: "sentenceCase",
},
{
name: "Snake (underscore)",
description: `test string -> test_string`,
value: "snakeCase",
},
]
);
if (!method in changeCase) {
notify("The selected method '${method}' is not available");
} else {
const transformedText = changeCase[method](text);
await Promise.all([setSelectedText(transformedText), copy(transformedText)]);
notify(`The text was pasted and copied to the clipboard!`);
}