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.
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');
}
- Needs more/better tests and docs.
ISC