Created
June 30, 2023 20:35
-
-
Save trevor-atlas/992682a54fa4ec44ccc8cc58e889e026 to your computer and use it in GitHub Desktop.
This file contains 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
// Menu: De-Acronym-ify | |
// Description: Replace acronyms with their full names | |
// Author: Trevor Atlas | |
// Twitter: @trevoratlas | |
// Shortcut: cmd ctrl opt shift a | |
// Group: work | |
import '@johnlindquist/kit'; | |
let text = ''; | |
const clipboardValue = await paste(); | |
const selection = await getSelectedText(); | |
if (selection) { | |
text = selection; | |
console.log('use selection', selection); | |
} | |
if (clipboardValue && !selection) { | |
text = clipboardValue; | |
console.log('use clipboard', text); | |
} | |
if (!text) { | |
text = await arg('Enter text to de-acronym-ify'); | |
console.log('use prompt', text); | |
} | |
const acronyms: Array<[string | RegExp, string]> = [ | |
['PD', 'Product Design'], | |
['PM', 'Product Management'], | |
['JS', 'JavaScript'], | |
['TS', 'TypeScript'], | |
]; | |
const result = acronyms.reduce( | |
(acc, [acronym, expansion]) => acc.replace(acronym, expansion), | |
text | |
); | |
if (!selection) { | |
copy(result); | |
} else { | |
await setSelectedText(result); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment