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

cli-rc

v1.0.12

Published

Run control for command line interfaces

Downloads

44,586

Readme

Run Control

Run control (or runtime configuration) for command line interfaces.

See rc for some interesting information on the etymology of rc.

Install

npm install cli-rc

Test

npm test

Features

  • Support for ini and json rc files
  • Sensible default search paths
  • Logical default naming convention
  • 100% code coverage

Usage

Assuming your program was named prg and your program expects JSON formatted rc files this would search for .prgrc in the package directory followed by the user's home directory:

var rc = require('cli-rc');
rc(function loaded(err, rc) {
  if(err) throw err;
  // do something with rc object
});

If neither file was located the rc parameter will be the empty object, otherwise it will contain the merged contents of all files with precedence in reverse order, ie, properties declared in the last file will override properties loaded by previous files.

You may use the name option to specify an alternative file name, set the type option to INI to indicate that your rc files are ini formatted and configure the directory search paths with the path option.

For example, to search for rc files /usr/local/etc/prg/prg.ini and /usr/local/lib/prg/prg.ini (in that order):

var rc = require('cli-rc');
var opts = {
  type: rc.INI, name: 'prg.ini',
  path: ['/usr/local/etc/prg', '/usr/local/lib/prg']
};
rc(opts, function loaded(err, rc) {
  if(err) throw err;
  // do something with rc object
});

Options

append

A boolean that appends the default search paths to directories specified in path, only applicable if path has been specified as an option. May also be an array of paths to append to the default search path.

base

A path to the directory for the package.

home

A function that may be used to determine the home directory location, default implementation inspects process.env.HOME.

lenient

A boolean that gathers errors into an array and continues processing subsequent rc files, default is false.

name

The name of the rc file to load, default is:

'.' + basename(process.argv[1]) + 'rc'

path

Array of directories to search for rc files, default is the package directory and the user's home directory.

Note that no path entry for the user's home directory will be added if it could not be determined from environment variables, see home().

prepend

A boolean that prepends the default search paths to directories specified in path, only applicable if path has been specified as an option. May also be an array of paths to prepend to the default search path.

resolve

A function that is passed each path and may be used to resolve relative paths to absolute paths.

type

The expected format of rc files, either ini or json, default is json.

API

Module

([options], [callback])

Creates a RunControl instance.

  • options: The configuration options.
  • callback: A callback function.

If callback is specified and is a function then it is passed to RunControl.load().

Returns the RunControl instance.

INI

String constant representing the ini type.

JSON

String constant representing the json type.

RunControl

Reference fo the RunControl class.

RunControl

Class used to load rc files.

RunControl([options])

Creates a RunControl instance.

  • options: The configuration options.

Throws TypeError if options.type is invalid.

load(callback)

Loads rc files.

  • callback: A function to invoke when the load operation is complete.

Throws TypeError if callback is not a function.

The signature for callback is:

function loaded(err, rc)

The rc argument is an object that is the merged result of loading and parsing all rc files that exist and did not trigger an error.

If the lenient option is specified and an error occurs err will be an array of errors.

Errors are decorated with a file property to indicate the file that caused the error condition.

Errors occur under the following circumstances:

  • There was an error parsing a file as JSON (SyntaxError).
  • An error occured while reading a file (Error), this could be permissions (EACCESS) or some other file system related error.

Note that currently the ini module does not throw any errors on malformed file contents, however if that changes they will be passed on to the callback function.

License

Everything is MIT. Read the license if you feel inclined.