
Security News
Axios Supply Chain Attack Reaches OpenAI macOS Signing Pipeline, Forces Certificate Rotation
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.
bare-module-lexer
Advanced tools
Heuristic lexer for detecting imports and exports in JavaScript modules
Heuristic lexer for detecting imports and exports in JavaScript modules. It trades off correctness for performance, aiming to reliably support the most common import and export patterns with as little overhead as possible.
const lex = require('bare-module-lexer')
lex(`
const foo = require('./foo.js')
exports.bar = 42
`)
// {
// imports: [
// { specifier: './foo.js', type: REQUIRE, names: [], position: [ 15, 24, 32 ] }
// ],
// exports: [
// { name: 'bar', position: [ 37, 45, 48 ] }
// ]
// }
const { imports, exports } = lex(source[, encoding][, options])imports is an array of objects with the following shape:
imports = {
specifier: 'string',
type: number,
names: ['string'],
position: [
number, // Import start
number, // Specifier start
number // Specifier end
]
}
exports is an array of objects with the following shape:
exports = {
name: 'string',
position: [
number, // Export start
number, // Name start
number // Name end
]
}
Options are reserved.
lex.constants| Constant | Description |
|---|---|
REQUIRE | CommonJS require(). |
IMPORT | ES module import. |
DYNAMIC | ES module import() if IMPORT is set. |
ADDON | CommonJS require.addon() if REQUIRE is set, or ES module import.meta.addon() if IMPORT is set. |
ASSET | CommonJS require.asset() if REQUIRE is set, or ES module import.meta.asset() if IMPORT is set. |
RESOLVE | CommonJS require.resolve() or require.addon.resolve() if REQUIRE and optionally ADDON are set, or ES module import.meta.resolve() or import.meta.addon.resolve() if IMPORT and optionally ADDON are set. |
REEXPORT | Re-export of a CommonJS require() if REQUIRE is set, or ES module export from if IMPORT is set. |
Apache-2.0
FAQs
Heuristic lexer for detecting imports and exports in JavaScript modules
The npm package bare-module-lexer receives a total of 26,603 weekly downloads. As such, bare-module-lexer popularity was classified as popular.
We found that bare-module-lexer demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.

Security News
Open source is under attack because of how much value it creates. It has been the foundation of every major software innovation for the last three decades. This is not the time to walk away from it.

Security News
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.