@mattbrannon/file-loader
v1.1.1
Published
Utility for loading modules in both ESM and CJS environments
Readme
file-loader
A utility module for loading modules in both ESM and CJS environments, with support for conditional caching and JSON imports.
Installation
npm install file-loaderFeatures
- Supports both CommonJS and ESM modules
- Conditional module caching
- Support for JSON imports
- Lightweight with no dependencies
Usage
const FileLoader = require("file-loader");
// Load a module with caching (default)
const module1 = await FileLoader.loadModule("./path/to/module");
// Load a module without caching
const module2 = await FileLoader.loadModule("./path/to/module", false);
// Load a JSON file
const jsonData = await FileLoader.loadModule("./path/to/file.json");API
loadModule(moduleName, useCache = true)
moduleName: Path to the moduleuseCache: Boolean to control module caching- Returns: Promise that resolves to the loaded module
resolveModule(moduleName)
moduleName: Path to the module- Returns: Resolved absolute path to the module
isJson(moduleName)
moduleName: Path to the module- Returns: Boolean indicating if the module is a JSON file
License
MIT © Matt Brannon
