Created
September 16, 2022 07:53
-
-
Save vogelino/7dfe97dc4732a6e2637b7640061016ac to your computer and use it in GitHub Desktop.
Script Kit - Change Text Case
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 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!`); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment