šŸ”” Change case of selected text šŸ” 

https://user-images.githubusercontent.com/2759340/190588006-c7734d44-18d8-46b8-839d-8fc5805b76d4.mov

Install on Script Kit


šŸ”” ā†’ šŸ”  Apply some text case transformation to the selected text or enter it yourself. šŸ”  ā†’ āœ‚ļø The text is then pasted in place and copied to the clipboard.


// Name: Change case of selected text
// Description: Choose a transformation method (eg. camelCase) to transform the selected text in-place (Or some text input)
// Author: Vogelino
// Twitter: @soyvogelino
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!`);
}