load-first-avail-module

0.1.1 • Public • Published

load-first-avail-module

Based on a module load function (typically your module's require, or a proxy for your import), create a function that promises to load the first available module from an array of candidate module names, probed in series.

  • Automatically retries each candidate with .mjs added.

Usage

import makeFirstAvailModLoader from 'load-first-avail-module';
const importFirstAvailable = makeFirstAvailModLoader(id => import(id));

async function totallyBogus() {
  const someZip = await importFirstAvailable([
    './7zip',
    './zip',
    './gzip',
  ]);
  return someZip('hello world');
}

Known issues

  • Needs more/better tests and docs.

 

License

ISC

Readme

Keywords

none

Package Sidebar

Install

npm i load-first-avail-module

Weekly Downloads

5

Version

0.1.1

License

ISC

Unpacked Size

2.92 kB

Total Files

3

Last publish

Collaborators

  • mk-pmb