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

navel-config

v1.0.0-alpha.6

Published

Configuration module for navel

Downloads

7

Readme

Navel Config

Navel Config is a system for parsing configuration files. It was built to suit the requirements of Navel, though it can be used as an independent module for any project.

Installing

You can add this module to your node project with NPM:

npm install --save navel-config

Usage

This section will explain how to use this library.

Basic usage

To load a configuration file you use the module's load method. The load method returns a Future that resolves to a Config instance.

const Config = require('navel-config');
const ROOT_CONFIG_PATH = './config.yml';

Config.load(ROOT_CONFIG_PATH, process.env)
    .fork(console.error, (config) => {
        // config is a Config instance
    })
;

It will also load a remote resource:

const Config = require('navel-config');
const ROOT_CONFIG_URL = 'https://example.com/config.json';

Config.load(ROOT_CONFIG_URL, process.env)
    .fork(console.error, (config) => {
        // config is a Config instance
    })
;

File formats

This module will load files with a .yml, .yaml or .json file extension. Additionally, it will load local files with a .js file extension.

Environment variables

This module will replace any value prefixed with a $ character with a value from the passed in environment.

# config.yml
example:
  var: $EXAMPLE_VAR
const ENV = {EXAMPLE_VAR: 'ok'};
Config.load(pathToConfig, ENV)
    .fork(console.error, (config) => {
        config.get('example/var'); // 'ok'
    })
;

There is also an operator that will achieve the same thing:

# config.yml
example:
  var:
    $env: EXAMPLE_VAR
const ENV = {EXAMPLE_VAR: 'ok'};
Config.load(pathToConfig, ENV)
    .fork(console.error, (config) => {
        config.get('example/var'); // 'ok'
    })
;

You can use a backslash to escape the environment variable:

# config.yml
example:
  var: \$EXAMPLE_VAR
const ENV = {EXAMPLE_VAR: 'ok'};
Config.load(pathToConfig, ENV)
    .fork(console.error, (config) => {
        config.get('example/var'); // '$EXAMPLE_VAR'
    })
;

References

A configuration file can contain a JSON reference. This reference can be a local or remote reference.

# config.yml
example:
  reference:
    $ref: 'https://example.com/config.yml#thing'
# https://example.com/config.yml
thing: value
Config.load(pathToConfig)
    .fork(console.error, (config) => {
        config.get('example/reference'); // 'value'
    })
;

Case Expression

A configuration file may contain a case expression:

# config.yml
example:
  $case:
    of: $color
    cases:
      blue: good
      red: bad
    default: neutral
Config.load(pathToConfig, {color: 'red'})
    .fork(console.error, (config) => {
        config.get('example'); // 'bad'
    })
;

Verbatim

If you want a section of content to be returned without processing, you may use the $verbatim operator.

literal:
  $verbatim:
    $ref: '#/reference'
    $env: 'var'
Config.load(pathToConfig)
    .fork(console.error, (config) => {
        config.get('literal/$ref'); // '#/reference'
    })
;

Running the tests

You can run the project tests with NPM:

npm run lint && npm test

Contributing

Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

Authors

  • Mark Wardle - Initial work - wardlem

License

This project is licensed under the ISC License - see the LICENSE file for details

Acknowledgments

Forthcoming.