Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jonschlinkert/config-file
Find and load a YAML or JSON config file from a local project, installed npm module, or the user's home directory.
https://github.com/jonschlinkert/config-file
Last synced: 21 days ago
JSON representation
Find and load a YAML or JSON config file from a local project, installed npm module, or the user's home directory.
- Host: GitHub
- URL: https://github.com/jonschlinkert/config-file
- Owner: jonschlinkert
- License: mit
- Created: 2014-02-09T09:27:28.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2015-12-30T17:49:21.000Z (almost 9 years ago)
- Last Synced: 2024-05-16T20:51:07.893Z (6 months ago)
- Language: JavaScript
- Homepage: https://github.com/jonschlinkert
- Size: 23.4 KB
- Stars: 13
- Watchers: 3
- Forks: 2
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# config-file [![NPM version](https://badge.fury.io/js/config-file.svg)](http://badge.fury.io/js/config-file)
> Find and load a YAML or JSON config file (like .jshintrc, package.json, bower.json etc) from either a local project, installed npm module, or the user's home directory.
## Heads up! Breaking changes
v0.3.0 was a complete refactor. The readme [API](#API) section describes the new API.
## Install
Install with [npm](https://www.npmjs.com/)
```sh
$ npm i config-file --save
```## Usage
```js
var config = require('config-file');
```## API
### [config](index.js#L29)
Returns an object from parsing JSON or YAML from the given config file. Uses `config.resovle` to resolve the filepath. If no filepath is specified, `config.resolve` falls back to 'package.json'
**Params**
* `filename` **{String}**: The name of the file to parse
* `options` **{Object}**: Optionally specify `{parse:'json'}` or `{parse:'yaml'}`
* `returns` **{Object}****Example**
```js
var opts = config('.jshintrc');
```### [.npm](index.js#L53)
Parse a config file located in a locally installed npm package (in `node_modules`).
**Params**
* `moduleName` **{String}**: The name of the npm package to search in `node_modules`
* `filename` **{String}**: Name of the file to find.
* `options` **{Object}****Example**
```js
var data = config.npm('read-data', 'package.json');
//=> { name: "read-data", ... }
```### [.global](index.js#L78)
Parse a config file in a globally installed npm package.
**Params**
* `moduleName` **{String}**: The name of the global module to search
* `filename` **{String}**: Name of the file to find.
* `options` **{Object}****Example**
```js
var data = config.global('verb-cli', 'package.json');
//=> { name: "verb-cli", ... }
```### [.home](index.js#L100)
Return a filepath the user's home directory
**Params**
* `filepath` **{String}**: Filepath to find
* `options` **{Object}****Example**
```js
var data = config.home('.jshintrc');
```### [.resolve](index.js#L120)
Returns the fully resolve path for the specified config file. Searches the local project first, then the user's home directory.
**Params**
* `filepath` **{String}**: Filepath to find
* `options` **{Object}**
* `returns` **{String}**: filepath to config file**Example**
```js
var fp = config.resolve('.jshintrc');
//=> '/Users/jonschlinkert/dev/config-file/package.json'
```### [.parse](index.js#L142)
Parse a config file. Same as using `config()`.
**Params**
* `filename` **{String}**: Name of the file to parse.
* `options` **{Object}**
* `returns` **{Object}****Example**
```js
var data = config.parse('.jshintrc');
```## Related projects
* [global-modules](https://github.com/jonschlinkert/global-modules): The directory used by npm for globally installed npm modules.
* [look-up](https://github.com/jonschlinkert/look-up): Like findup-sync and supports the same features but 20x-40x faster on avg.
* [read-data](https://github.com/jonschlinkert/read-data): Read JSON or YAML files.
* [read-yaml](https://github.com/jonschlinkert/read-yaml): Very thin wrapper around js-yaml for directly reading in YAML files.## Running tests
Install dev dependencies:
```sh
$ npm i -d && npm i -g verb-cli && npm test
```## Contributing
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/jonschlinkert/config-file/issues/new)
## Author
**Jon Schlinkert**
+ [github/jonschlinkert](https://github.com/jonschlinkert)
+ [twitter/jonschlinkert](http://twitter.com/jonschlinkert)## License
Copyright © 2014-2015 [Jon Schlinkert](https://github.com/jonschlinkert)
Released under the MIT license.***
_This file was generated by [verb-cli](https://github.com/assemble/verb-cli) on July 06, 2015._