0.3.1 • Published 4 months ago

@mateonunez/modulo v0.3.1

Weekly downloads
-
License
MIT
Repository
-
Last release
4 months ago

@mateonunez/modulo

A simple tool to use ESM modules in a CommonJS environment.

Install

npm i @mateonunez/modulo

Usage

Default export

const modulo = require("@mateonunez/modulo");

const myEsmModule = await modulo({ path: "./my-esm-module.mjs" });
const result = myEsmModule();

Named export

const modulo = require("@mateonunez/modulo");

const { namedExportVar, namedExportFunc } = await modulo({
  path: "./my-esm-module.mjs",
});

console.log(namedExportVar);
const result = namedExportFunc();

Error handling

const modulo = require("@mateonunez/modulo");

const myEsmModule = await modulo({ path: "./my-esm-module.mjs" }).catch(
  (err) => {
    console.error(err);
  }
);

Note: if your ESM module exports a default export and named exports, you can use only the default export.

License

MIT

0.3.1

4 months ago

0.3.0

4 months ago

0.2.1

4 months ago

0.2.0

4 months ago

0.1.2

4 months ago

0.1.1

4 months ago

0.1.0

4 months ago