Static to dynamic import converter

I got tired of typing out the conversion when pulling in script examples so I made this quick script to convert them

Open static-to-dynamic in Script Kit

// Name: Static to Dynamic
// Description: Convert static import to dynamic import
// e.g. import { Foo } from "bar";
// to let { Foo } = await import("bar");
// Author: Josh Mabry
// Twitter: @AI_Citizen
import "@johnlindquist/kit";
const text = await getSelectedText();
function convertImportString(input) {
const importRegex = /import\s+({[^}]+})\s+from\s+"([^"]+)";/;
if (!importRegex.test(input)) {
throw new Error("Invalid import string format");
const [_, importList, modulePath] = input.match(importRegex);
const output = `let ${importList} = await import("${modulePath}");`;
return output;
const output = convertImportString(text);
await setSelectedText(output);