Product
Introducing Enhanced Alert Actions and Triage Functionality
Socket now supports four distinct alert actions instead of the previous two, and alert triaging allows users to override the actions taken for all individual alerts.
find-config
Advanced tools
Readme
find-config
Finds the first matching config file, if any, in the current directory, nearest ancestor, or user's home directory. Supports finding files within a subdirectory of an ancestor directory. Configurable with defaults set to support the XDG Base Directory Specification for configuration files.
Because this module is intended to find consistently named configuration files, it is case-sensitive and does not support globs. If you need a more generic solution, see findup-sync or look-up.
Where X is the current directory:
With Node.js:
$ npm install find-config
var findConfig = require('find-config');
// Find the path to the nearest `package.json`
var pkg = findConfig('package.json');
// Find the path to the nearest `.foorc` or `.config/foorc`
var foo = findConfig('.foorc');
// Find the path to the nearest `.foorc` or `.config/.foorc`
var foo = findConfig('.foorc', { dot: true });
// Find the path to the nearest module using Node.js module resolution.
// Will look for `bar.js` or `bar/index.js`, etc.
var foo = findConfig('bar', { module: true });
// Find the path to the nearest `baz.json` or `some/path/baz.json`
var foo = findConfig('baz.json', { dir: 'some/path' });
// Find the path to the nearest `qux.json` or `some/path/qux.json` in
// some other directory or its nearest ancestor directory.
var foo = findConfig('qux.json', { cwd: '/other/dir', dir: 'some/path' });
// Find and require the nearest `package.json`
var pkg = findConfig.require('package.json');
// Find and read the nearest `.foorc` or `.config/foorc`
var foo = findConfig.read('.foorc');
findConfig(filename, [options]) : String|Null
filename
String
- Name of the configuration file to find.options
{Object=}
cwd
{String=}
- Directory in which to start looking. (Default: process.cwd()
)dir
{String=}
- An optional subdirectory to check at each level. (Default: '.config'
)dot
{Boolean=}
- Whether to keep the leading dot in the filename in dir
. (Default: false
)home
{Boolean=}
- Whether to also check the user's home directory. (Default: true
)module
{Boolean=}
- Whether to use Node.js module resolution. (Default: false
)Synchronously find the first config file matching a given name in the current directory or the nearest ancestor directory.
findConfig.obj(filename, [options]) : Object|Null
filename
String
- Name of the configuration file to find.options
{Object=}
- Same as findConfig()
.Finds first matching config file, if any and returns the matched directories and config file path.
findConfig.read(filename, [options]) : String|Null
filename
String
- Name of the configuration file to find.options
{Object=}
- Same as findConfig()
with two additions.
encoding
{String}
- File encoding. (Default: 'utf8'
).flag
{String}
- Flag. (Default: 'r'
).Finds and reads the first matching config file, if any.
var yaml = require('js-yaml');
var travis = yaml.safeLoad(findConfig.read('.travis.yml'));
findConfig.require(filename, [options]) : *
filename
String
- Name of the configuration file to find.options
{Object=}
- Same as findConfig()
.Finds and requires the first matching config file, if any. Implies module
is true
.
var version = findConfig.require('package.json').version;
Standards for this project, including tests, code coverage, and semantics are enforced with a build tool. Pull requests must include passing tests with 100% code coverage and no linting errors.
$ npm test
Š Shannon Moeller me@shannonmoeller.com (shannonmoeller.com)
Licensed under MIT
FAQs
Find the first config file matching a given name in the current directory or the nearest ancestor directory.
The npm package find-config receives a total of 142,853 weekly downloads. As such, find-config popularity was classified as popular.
We found that find-config 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.
Product
Socket now supports four distinct alert actions instead of the previous two, and alert triaging allows users to override the actions taken for all individual alerts.
Security News
Polyfill.io has been serving malware for months via its CDN, after the project's open source maintainer sold the service to a company based in China.
Security News
OpenSSF is warning open source maintainers to stay vigilant against reputation farming on GitHub, where users artificially inflate their status by manipulating interactions on closed issues and PRs.