Security News
The Dark Side of Open Source
At Node Congress, Socket CEO Feross Aboukhadijeh uncovers the darker aspects of open source, where applications that rely heavily on third-party dependencies can be exploited in supply chain attacks.
requireindex
Advanced tools
Readme
Write minimal node index.js files that require and export siblings by file basename
1.2.0
npm install requireindex
or in package.json
{
...
"dependencies": {
"requireindex": "1.1.x"
}
}
Check the test directory for example usage. The test/lib looks like:
lib/
index.js
Foo.js
bar/
index.js
f.js
fing.js
fed/
again.js
ignored.js
index.js
somemore.js
bam.js
_private.js
The index.js files in test/lib/ and test/lib/bar/ contain:
module.exports = require('requireindex')(__dirname);
and the index.js file in test/lib/bar/fed/ contains:
module.exports = require('requireindex')(__dirname, ['again', 'somemore']);
The optional second argument allows you to explicitly specify the required files using their basename. In this example test/lib/bar/fed/ignored.js is not included as a public module. The other way to make a module/file private without the need for explicitly naming all the other included files is to prefix the filename with an underscore, as demonstrated by test/lib/_private.js which is not exported.
So, with these index.js files, the result of
require('lib');
is:
{
bam: {
m: [Function],
n: [Function]
},
bar: {
f: [Function],
fed: {
again: [Function],
somemore: [Function]
},
fing: [Function]
},
Foo: {
l: [Function],
ls: [Function]
}
}
FAQs
Write minimal node index.js files that require and export siblings by file basename
The npm package requireindex receives a total of 4,954,300 weekly downloads. As such, requireindex popularity was classified as popular.
We found that requireindex demonstrated a not healthy version release cadence and project activity because the last version was released 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
At Node Congress, Socket CEO Feross Aboukhadijeh uncovers the darker aspects of open source, where applications that rely heavily on third-party dependencies can be exploited in supply chain attacks.
Research
Security News
The Socket Research team found this npm package includes code for collecting sensitive developer information, including your operating system username, Git username, and Git email.
Security News
OpenJS is warning of social engineering takeovers targeting open source projects after receiving a credible attempt on the foundation.