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

config-sp

v0.1.2

Published

A simple, zero-dependency library helps you make a configuration for your library or module.

Downloads

8

Readme

Config-SP

Node Version Npm Package Version License NodeJS Package Dependencies Build Status Code Climate Test Coverage

A simple, zero-dependency library helps you make a configuration for your library or module.

It helps you define a set of default parameters(in default.js), and extend them(in local.js or others files) recursively.

It is highly recommended to use lorenwest/node-config when you are willing to build an application rather than a library. It is a pretty awesome library and provides many useful features.

Document Translations

简体中文

TOC

Installation

npm install --save config-sp

Quick Start

  1. mkdir a folder.

    mkdir config
  2. edit the default configuration via vim config/default.js.

    {
        a: {
            b: {
                c: 'hello',
                c2: 'world',
                c3: 1,
            },
            d: [1, 2, 3],
        },
        e: false,
        f: null,
        g: 1,
    }
  3. edit the local configuration via vim config/local.js.

    {
        a: {
            b: {
                c: 'bye',
                c3: 0,
            },
            d: [],
        },
        e: true,
        g: undefined,
        h: null,
    }
  4. edit the index file to indicate the default and local files via vim config/index.js.

    var Config = require('config-sp');
    // the default.js and local.js are relative path to __dirname
    var config = Config.load(__dirname, ['default.js', 'local.js'], {
        ignores: 'local.js',   // local.js is allowed to be missing
    });
    
    // the config will be:
    // {
    //     a: {
    //         b: {
    //             c: 'bye',
    //             c2: 'world',
    //             c3: 0,
    //         },
    //         d: [],
    //     },
    //     e: true,
    //     f: null,
    //     g: 1,
    //     h: null,
    // }
    
    // to get a child config
    var c = config.get('a.b.c');
    // or
    c = config.a.b.c;
    
    var a = config.get('a');
    // the child config returned by `get` method, will also have `get` method
    c = a.get('b.c');
    
    var b = config.a.b;
    // c = b.get('c');  // will throw an error, because `b` has no `get` method
    
    // var d = config.get('d');  // it will throw an error, because `d` is missing

Config Object

The config object returned by load and create function will have get method, which is used to get a child config.

get method will throw an exception for undefined value to help catch typos and missing values.

Reserved Words

the following configuration names cannot be used as config key:

  • get

Environment Variables

CONFIG_SP_LOAD_FILE_MISSING

supported values:

  • 'warn': console.warn the error message
  • 'error': console.error the error message
  • 'ignore': neither print anything nor throw an error

If CONFIG_SP_LOAD_FILE_MISSING is not set, it will throw an error when the file is missing.

API

see http://adoyle.me/config-sp/

Versioning

The versioning follows the rules of SemVer 2.0.0.

BUT, anything may have BREAKING CHANGES at ANY TIME when major version is zero (0.y.z), which is for initial development and the public API should not be considered stable.

For more information on SemVer, please visit http://semver.org/.

Copyright and License

Copyright (c) 2015-2016 ADoyle. The project is licensed under the Apache License Version 2.0.

See the LICENSE file for the specific language governing permissions and limitations under the License.

See the NOTICE file distributed with this work for additional information regarding copyright ownership.