Research
Security News
Threat Actor Exposes Playbook for Exploiting npm to Build Blockchain-Powered Botnets
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
dir-requirer
Advanced tools
dir-requirer是一个对nodejs自身的require方法的封装,使用它可以直接require一个目录,它会帮助你require指定目录下的 所有文件,并且返回一个与目录结构相同的对象,目录中被require的文件名即对象的方法名。
比如在当前目录下的dir文件夹的结构如下:
|-- inner2 -- d.json
|-- inner -- |
| |-- e.js
|-- a.js
dir -- |-- b.js
|-- c.json
var dr = require('dir-requirer')(__dirname);
var myDir = dr('./dir');
myDir.inner.e(); //调用e.js中exports出的方法/对象,相当于myDir.inner.e = require('./dir/inner/e');
cJson = myDir.c;//也可以调用json文件
$ npm install dir-requirer
var dr = require('dir-requirer')(__dirname);
比如在当前目录下的dir文件夹的结构如下:
|-- inner2 -- d.json
|-- inner -- |
| |-- e.js
|-- a.js
dir -- |-- b.js
|-- c.json
参数:
path(String)
- 指定要导入的路径options(Object)
- 可选的配置选项options可选属性:
ext(Array)
- 只导入指定扩展名的文件,如['.json'],默认为['.js','.json','.node']dirBlackList(Array)
- 不导入指定目录名下的所有文件,如['inner2'],默认为[]fileBlackList(Array)
- 不导入指定文件,如['e.js'],默认为[]var dr = require('dir-requirer')(__dirname);
var myDir = dr('./dir')
//myDir对象将会拥有与'./dir'目录相同的结构,可以直接调用 myDir.a (即a.js文件exports出的对象/方法) ,
//myDir.c , myDir.inner.e , myDir.inner.inner2.d
var myDir = dr('./dir',{ext:['.json']});
//将只会require目录下的所有json文件,如 myDir.inner.inner2.d , myDir.c
var myDir = dr('./dir',{dirBlackList:['inner2']});
//将不会require在inner2目录下的所有文件(包括子目录)
var myDir = dr('./dir',{dirBlackList:['inner'],fileBlackList:['c.json']});
//将不会require在inner目录下的所有文件(包括子目录),以及名为c.json的单独文件
FAQs
require指定目录下的所有文件,返回与目录结构相同的对象
The npm package dir-requirer receives a total of 0 weekly downloads. As such, dir-requirer popularity was classified as not popular.
We found that dir-requirer 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.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
Security News
NVD’s backlog surpasses 20,000 CVEs as analysis slows and NIST announces new system updates to address ongoing delays.
Security News
Research
A malicious npm package disguised as a WhatsApp client is exploiting authentication flows with a remote kill switch to exfiltrate data and destroy files.