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.

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.

v0.3.0 was a complete refactor. The readme API section describes the new API.

Install with npm

$ npm i config-file --save
var config = require('config-file');

config

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

var opts = config('.jshintrc');

.npm

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

var data = config.npm('read-data', 'package.json');
//=> { name: "read-data", ... } 

.global

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

var data = config.global('verb-cli', 'package.json');
//=> { name: "verb-cli", ... } 

.home

Return a filepath the user's home directory

Params

  • filepath {String}: Filepath to find
  • options {Object}

Example

var data = config.home('.jshintrc');

.resolve

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

var fp = config.resolve('.jshintrc');
//=> '/Users/jonschlinkert/dev/config-file/package.json' 

.parse

Parse a config file. Same as using config().

Params

  • filename {String}: Name of the file to parse.
  • options {Object}
  • returns {Object}

Example

var data = config.parse('.jshintrc');
  • global-modules: The directory used by npm for globally installed npm modules.
  • look-up: Like findup-sync and supports the same features but 20x-40x faster on avg.
  • read-data: Read JSON or YAML files.
  • read-yaml: Very thin wrapper around js-yaml for directly reading in YAML files.

Install dev dependencies:

$ npm i -d && npm i -g verb-cli && npm test

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue

Jon Schlinkert

Copyright © 2014-2015 Jon Schlinkert Released under the MIT license.


This file was generated by verb-cli on July 06, 2015.