⚡ A flexible and efficient utility for loading Deno modules dynamically — one file, many files, or entire folders.
- 📄 Import a single file dynamically
- 📁 Import all
.ts,.js, etc. files in a folder - 🔍 Auto-detect
main.ts(or custom entry) in subdirectories - 🔁 Handle multiple paths
- 🚀 Parallel loading of multiple files for optimal performance
- 🧩 Import callback
- 📜 Filter allowed extensions
- 🔍 Optional logging
- 🧯 Fallback support on error
import { $Import } from "https://raw.githubusercontent.com/socle-commun/lib-core-deno/main/libs/import/mod.ts";const meta = import.meta.url;
// Import a single file
const mod = await $Import(meta, "./services/foo.ts");
// Import multiple files and folders
const all = await $Import(meta, [
"./services/foo.ts",
"./modules/",
]);
// Import with callback
await $Import(meta, "./config.ts", {
callback: async (mod) => {
console.log("Module loaded:", mod);
},
});$Import<T>(
metaUrl: string,
path: string | string[],
options?: SlothImportOptions<T>
): Promise<T>;interface SlothImportOptions<T> {
callback?: (mod: T) => Promise<void>;
entryFileName?: string; // default: "main.ts"
allow?: SlothImportAllowedExtension[]; // default: ["ts"]
}$Import.logging = true; // or custom logger function
$Import.fallback = (path, err) => ({ error: true });
$Import.config = {
logging: false,
entryFileName: "entry.ts",
allow: ["ts"],
};Folder structure:
features/
├─ feature-a/
│ └─ main.ts
├─ feature-b/
│ └─ main.ts
await $Import(import.meta.url, "./features/");Each main.ts file will be automatically imported.
["ts", "js", "jsx", "tsx", "mts", "cts"]
Default to ["ts", "js"]
Customizable via options.allow or config.allow.
libs/import/
├─ mod.ts # Main entrypoint
├─ config.ts # Runtime config
├─ types.ts # Type declarations
├─ constants.ts
├─ processes/
│ ├─ import-file/
│ ├─ import-directory/
│ ├─ resolve-path/
│ ├─ handle-error/
│ └─ log/
└─ _fixtures/ # Test modules
deno task testEach internal process has independent tests.
$Import is part of the Sloth 🦥 utility toolkit — designed to be minimal, lazy, and powerful for Deno developers.
MIT © 2025 Mistifiou