0.1.1 • Published 5 years ago

load-first-avail-module v0.1.1

Weekly downloads
2
License
ISC
Repository
github
Last release
5 years ago

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