1.1.1 • Published 1 year ago

@mattbrannon/file-loader v1.1.1

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

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-loader

Features

  • 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 module
  • useCache: 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

1.1.1

1 year ago

1.1.0

1 year ago

1.0.0

1 year ago