lib-esm
A tiny esm
snippets interop lib.
![NPM Downloads](https://img.shields.io/npm/dm/lib-esm.svg)
Install
npm i lib-esm
Usage
import libEsm from 'lib-esm'
const snippets = libEsm({
window: 'lib-name',
require: 'lib-name',
exports: [
'foo',
'bar',
],
})
console.log(`${snippets.window}\n${snippets.exports}`)
console.log(`${snippets.require}\n${snippets.exports}`)
snippets.window
const _M_ = window["lib-name"];
snippets.require
import _M_node_module from "node:module";
const _M_ = _M_node_module.createRequire(import.meta.url)("lib-name");
snippets.exports
export const foo = _M_.foo;
export const bar = _M_.bar;
const keyword_default = _M_.default || _M_;
export {
keyword_default as default,
};
API (Define)
function libEsm(options: {
/**
* IIFE name
*/
window?: string;
/**
* require id
*/
require?: string;
/**
* export members
*/
exports?: string[];
/**
* Prevent name conflicts
*/
conflict?: string;
}): {
window: string;
require: string;
exports: string;
keywords: Record<string, string>;
}