npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

find-config

v1.0.0

Published

Find the first config file matching a given name in the current directory or the nearest ancestor directory.

Downloads

614,341

Readme

find-config

NPM version Downloads Build Status Coverage Status Chat Tip

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.

Algorithm

Where X is the current directory:

  1. If X/file.ext exists, return it. STOP
  2. If X/.dir/file.ext exists, return it. STOP
  3. If X has a parent directory, change X to parent. GO TO 1
  4. Return NULL.

Install

With Node.js:

$ npm install find-config

Usage

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');

API

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;

Contribute

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.

Test

$ npm test

© Shannon Moeller [email protected] (shannonmoeller.com)

Licensed under MIT