Skip to content

Latest commit

 

History

History
100 lines (79 loc) · 2.4 KB

README.md

File metadata and controls

100 lines (79 loc) · 2.4 KB

y-config

Create public configuration for the project

node Travis Coveralls Known Vulnerabilities David Author license

Usage

Installation

npm install --save y-config

Import Module

javascript:

const Config = require("y-config");

typescript:

import Config = require("y-config");

Load Config File

const config = new Config();
config.addConfigPath('./config.json');
config.addConfigPath('./config.yaml');

Use JSON parse

const config = new Config();
config.addConfigPath('./config', 'json');

Use YAML parse

const config = new Config();
config.addConfigPath('./config', 'yaml');

Use Custom parse

const config = new Config();
config.addParser({
  format: 'ini',
  filter: /\.ini$/,
  handler: (filepath) => {
    const fs = require('fs');
    const ini = require('ini');
    return ini.parse(fs.readFileSync('./config.ini', 'utf-8'))
  }
});

Add Config Data

const config = new Config();
config.addConfig({
  baz: "foo"
});

Export Config

const config = new Config();
// ......
config.getConfig();