y-config
Create public configuration for the project
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();