Skip to content

Instantly share code, notes, and snippets.

@trevor-atlas
Created June 30, 2023 20:35
Show Gist options
  • Save trevor-atlas/992682a54fa4ec44ccc8cc58e889e026 to your computer and use it in GitHub Desktop.
Save trevor-atlas/992682a54fa4ec44ccc8cc58e889e026 to your computer and use it in GitHub Desktop.
// 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