
Security News
/Research
Wallet-Draining npm Package Impersonates Nodemailer to Hijack Crypto Transactions
Malicious npm package impersonates Nodemailer and drains wallets by hijacking crypto transactions across multiple blockchains.
config-locator
Advanced tools
Find the config file from ancestor folders.
npm install config-locator
const {createConfigLocator} = require("config-locator");
/*
- my-config.js
- src:
- index.js
- lib:
- some-file.js
*/
const locator = createConfigLocator({
config: [
"my-config.json",
"my-config.js"
]
});
const result = await locator.findConfig("src/lib/some-file.js");
const result2 = await locator.findConfig("src/index.js");
result.filename === result2.filename; // true
result.config === result2.config; // true
This module exports following members:
findConfig(file, options)
- find config fore file
.createConfigLocator(options)
- create a config locator.async findConfig(file: String, options: Object) => null|Array|Object
This is a shortcut of createConfigLocator(options).findConfig(file)
.
createConfigLocator(options: Object) => locator
options
has following properties:
config: String|Array<String>
- the filename of the config file(s). The locator would check if these files are in the directory.
findAll?: Boolean
- by default, the locator would return the first found config file. If findAll
is true
then find all config files. Default: false
.
stopAtRoot?: Boolean
- stop finding if package.json
is found in the directory. Default: true
.
stopAt?: (dirname: String, pendingConfig: Promise) => shouldStop: Boolean|Promise<Boolean>
- a hook to customize when to stop finding. The function could be async.
extensions?: {extensionName: filename => null|config}
- a plain object that map each extension name (e.g. .js
) to a loader function. The loader function should return null
if filename
doesn't exist. By default, the locator uses node-require-async to load .js
and .json
files.
The loader function may return a promise.
race?: Boolean
- by default, when finding multiple configs in the same directory, the locator reads the file in parallel (but ordered). If a config file is found (i.e. the loader returns a truthy value), the locator returns the config immediately.
If race
is false
, the locator would wait for all loaders to finish and return the first found config.
This option has no effect if config
has only one item or findAll
is true.
Default: true
.
locator
has following methods:
async findConfig(filename) => null|result|Array<result>
- find the config for file
. It's a shortcut to searchDir(path.dirname(file))
.
async searchDir(dirname) => null|result|Array<result>
- start searching the config from dirname
.
result
is an object {filename, config}
that filename
is the filename of the config and config
is the object returned by the loader function registered in options.extensions
.
If options.findAll
is true
then it would be an array of result objects.
clearCache()
- clear the cache. Note that this function only clears the cache of config locator, you may want to remove the module from require.cache
that is created by node-require-async
.
async close()
- make sure all files are closed i.e. all loaders have finished.
0.1.0 (Jun 27, 2018)
FAQs
Find the config file from ancestor folders.
The npm package config-locator receives a total of 15 weekly downloads. As such, config-locator popularity was classified as not popular.
We found that config-locator 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
/Research
Malicious npm package impersonates Nodemailer and drains wallets by hijacking crypto transactions across multiple blockchains.
Security News
This episode explores the hard problem of reachability analysis, from static analysis limits to handling dynamic languages and massive dependency trees.
Security News
/Research
Malicious Nx npm versions stole secrets and wallet info using AI CLI tools; Socket’s AI scanner detected the supply chain attack and flagged the malware.