Attributes
Includes Deno configuration
Repository
Current version released
a year ago
Dependencies
std
$Import π¦₯ β Powerful Dynamic Import for Deno
β‘ A flexible and efficient utility for loading Deno modules dynamically β one file, many files, or entire folders.
β¨ Features
- π 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
π¦ Installation
import { $Import } from "https://raw.githubusercontent.com/socle-commun/lib-core-deno/main/libs/import/mod.ts";π§ͺ Usage
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);
},
});π§ API
$Import<T>(
metaUrl: string,
path: string | string[],
options?: SlothImportOptions<T>
): Promise<T>;Options
interface SlothImportOptions<T> {
callback?: (mod: T) => Promise<void>;
entryFileName?: string; // default: "main.ts"
allow?: SlothImportAllowedExtension[]; // default: ["ts"]
}βοΈ Global Configuration
$Import.logging = true; // or custom logger function
$Import.fallback = (path, err) => ({ error: true });
$Import.config = {
logging: false,
entryFileName: "entry.ts",
allow: ["ts"],
};π Auto-import main.ts from folders
Folder structure:
features/
ββ feature-a/
β ββ main.ts
ββ feature-b/
β ββ main.tsawait $Import(import.meta.url, "./features/");Each main.ts file will be automatically imported.
π€ Supported Extensions
["ts", "js", "jsx", "tsx", "mts", "cts"]Default to ["ts", "js"]
Customizable via options.allow or config.allow.
π§± Structure
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β Test
deno task testEach internal process has independent tests.
π’ About Sloth
$Import is part of the Sloth π¦₯ utility toolkit β designed to be minimal, lazy, and powerful for Deno developers.
π‘ License
MIT Β© 2025 Mistifiou