lib-esm
v0.4.2
Published
A tiny `esm` snippets interop lib
Downloads
37,619
Readme
lib-esm
A tiny esm
snippets interop lib.
Install
npm i lib-esm
Usage
import libEsm from 'lib-esm'
// or
// const libEsm = require('lib-esm').default
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)
/** Lib to ESM code snippets */
function libEsm(options: {
/**
* IIFE name
*/
window?: string;
/**
* require id
*/
require?: string;
/**
* export members
*/
exports?: string[];
/**
* Prevent name conflicts
*/
conflict?: string;
}): {
/** `window[iife-name]` snippets */
window: string;
/** `require(id)` snippets */
require: string;
/** `export` snippets */
exports: string;
/** Keywords alias */
keywords: Record<string, string>;
}