Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

njet-configuration

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

njet-configuration

Configuration handler for nodejs projects

  • 1.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

njet-configuration Build Status

Configuration handler for projects. Njet configuration is responsible for loading yaml configuration files.

Installation

npm install njet-configuration

Usage

First load njet configuration

var njetConfiguration = require('njet-configuration');

and create first configuration:

var config = njetConfiguration.create();

Getting data

To get Your configuration use:

config.get('x'); // to get specific value
config.getConfiguration(); // to get all values as json object

Set values from json objects

There are three ways to set configuration values.

config.set('x', 5);

will set "x" to 5. Now when You get Your configuration You will receive:

{ "x": 5 }

You can also replace whole configuration using load:

config.load({
    y: 6
});

This will replace Your configuration and You will receive:

{ "y": 6 }

Or You can merge two objects together:

config.merge({
    z: 1
});

To get:

{ "y": 6, "z": 1 }

Merging

Merge will always do deep copy of the objects. For example:

config.load({
    x: 1,
    y: ["a"]
});

config.merge({
    y: ["b"],
    z: 3
});

Will result:

{ "x": 1, "y": ["a", "b"], "z": 3 }

Validating

There are two ways to validate objects. You can add validators:

config.addValidator(function (config) {
    if (config.key === undefined) {
        return false;
    }
    return true;
});

Or schema:

config.schema({
    x: config.expect.number()
});

To validate configuration, simply use:

config.validate();
config.isValid();

For more information about schema validation visit https://github.com/cruks/cruks-lib-config

Yaml configuration files

You can load yaml files and directories containing yaml files like this:

config.load('/path/to/directory');
config.load('/path/to/file.yml');
config.merge('/path/to/another_file.yml');
config.merge('/path/to/another/directory');

Configuration

You cann pass options to njet configuration constructor. Like this:

var config = njetConfiguration.create({
    varbosity: 1,
    expect: expect,
    loader: loader
});
  • Verbosity above 0 (default 0) allow njet configuration to print error messages on standard output if configuration validation fails.
  • expect is a module to validate configuration. It should have .schema() method that return object with .asset() method. Assert should take configuration json object as first parameter.
  • loader is a module for loading data. As first argument, loader take either data object or path to file. By default loader only load .yml files.

Keywords

FAQs

Package last updated on 22 Jun 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc