Gathering detailed insights and metrics for esmod-pmb
Gathering detailed insights and metrics for esmod-pmb
Gathering detailed insights and metrics for esmod-pmb
Gathering detailed insights and metrics for esmod-pmb
npm install esmod-pmb
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
16 Commits
2 Watching
4 Branches
1 Contributors
Updated on 01 Jun 2021
Minified
Minified + Gzipped
JavaScript (100%)
Cumulative downloads
Total Downloads
Last day
-48.7%
39
Compared to previous day
Last week
-20.3%
263
Compared to previous week
Last month
-25.8%
933
Compared to previous month
Last year
6.2%
14,763
Compared to previous year
Use esm (ES modules, import, export for Node v6) with less boilerplate.
Let's assume you have an ES module like usage.mjs
:
1import dfOnly from './default-export-only'; 2import * as named from './named-exports-only'; 3 4export default dfOnly; 5export const { foo, answer } = named;
… and you want to use it from old node's CommonJS realm.
The esm
module can do it:
1module.exports = require('esm')(module)('./usage.mjs')
But that's still a bit too much boilerplate for my taste.
Don't waste your time micro-managing the filename
and whether you should add .default
to the above formula!
There's a much easier way:
Make a bridge module with almost the same name,
except it ends with .node.js
instead of .mjs
(thus here, usage.node.js
):
1require('esmod-pmb')(module);
It should work out of the box:
1$ nodejs -p "require('./usage.node.js')" 2{ foo: [Getter], answer: [Getter], default: [Getter] }
To see values instead of getters, copy them to another object:
1$ nodejs -p "Object.assign({}, require('./usage.node.js'))" 2{ foo: 23, 3 answer: 42, 4 default: { isDefaultExport: true, bar: 5 } }
For modules that have a default export and no named exports,
like default-export-only.mjs
:
1export default { isDefaultExport: true, bar: 5 };
… your bridge module will export that as the top level:
1$ nodejs -p "require('./default-export-only.node.js')" 2{ isDefaultExport: true, bar: 5 } 3$ nodejs -p "require('esm')(module)('./default-export-only.mjs')" 4{ default: [Getter] }
1// standard: 2require('esmod-pmb')(module); 3 4// custom options: 5require('esmod-pmb')(module, { preferDefaultExport: false }); 6 7// detailed: 8var bridgeBuilder = require('esmod-pmb'); 9var opt = { reexport: false }; 10var esmRequire = bridgeBuilder(module, opt); 11var yourEsModule = esmRequire('./yourmodule.mjs');
This module exports one function:
Returns an ESM-capable require
-like function obtained from esm
.
The optional options object opt
can be used to modify the default
options.
If you need custom options for something you consider "normal"/"usual", please file an issue so we can try to provide better defaults. After all, the purpose of this module is to reduce boilerplate.
That said, bridgeBuilder
uses the same options object as esm
,
so you can use all of its options, and some additional ones:
reexport
: (bool, default: true)
Whether bridgeBuilder
shall do its main magic:
baseModule.exports
.false
to opt-out of the main magic, but still get an esmRqr
with the combined options based on this module's defaults.Options used only when reexport
is enabled:
stripSuffixes
: (regexp) and addSuffix
(string, default: ".mjs"
)
To guess the ES module filename, the bridgeBuilder
removes the part
matched by stripSuffixes
and appends addSuffix
.
resolveImportedValues
: (bool, default: true
)
Whether to resolve (copy) the imported values.
Set to false
if you prefer getter functions.
Sane modules usually shouldn't mutate their exports,
so usually resolving them makes life easier
by reducing the amount of magic involved.
preferDefaultExport
: Determines which of the ESM exports
shall be re-export into CommonJS land.
false
= all of them. The re-export will be a dictionary (object).
If the ES module only has a default export, the dictionary will
contain only one key, default
.true
= only the default export.
If the ES module doesn't have a default export,
the re-export will be undefined
.1
(as a number; also the default) = automatic.
The re-export will be a dictionary with all exports, except in case
there is only one single export and its name is default
; in that case,
that default export will be re-exported directly.
ISC
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
no SAST tool detected
Details
Reason
Found 0/16 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
license file not detected
Details
Reason
branch protection not enabled on development/release branches
Details
Score
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More