1.0.0 • Published 19 days ago

als-import v1.0.0

Weekly downloads
-
License
ISC
Repository
-
Last release
19 days ago

als-import

als-import is a Node.js utility designed to facilitate the use of both ESM (ECMAScript Modules) and CommonJS modules. This library enables bundling and importing ESM modules in a CommonJS environment.

Important Notice: Experimental Use Only Important Notice: Not compatible with previous versions

Installation

Install als-import via npm:

npm i als-import

Basic Usage

Create an instance of the Import/Require class to import modules:

const { Require, Import } = require('als-import');
const path = 'full/path/to/module'
const {result,bundle,parents,imports,exportedItems} = new Import(path);
const {result,bundle,parents,imports,exportedItems} = new Require(path);

Caching

All modules imported via als-import are cached for efficiency. The cache can be accessed and manipulated directly:

// Access the cache
const cache = Import.cache; // or moduleFetch.cache

// Remove a module from the cache
delete cache['/path/to/cached/module'];

Caching ensures that modules are not re-imported unnecessarily, improving performance, especially in larger projects.