cfg-reader v3.0.3
cfg-reader
License and copyright notice
Installation
npm i --save cfg-reader
How to use
const { Config } = require('cfg-reader');
const myCfg = new Config('config.cfg');
myCfg.Get('test');
//with the get method you can easiely filter the lines you need
const { Config, Type } = require('cfg-reader');
const testCfg = new Config('test.cfg');
// If you know which type the value you want to get has you can use
// GetOfType(key: string, type: number).
// It directly converts the value to the right type
// and does not have to iterate over all possible types.
// -> little faster
testCfg.GetOfType('test', Type.String);
Differences between v1
Removed:
- Config.load()
- Config.fromJson()
- Config.fromObject()
- Config.path
- Config#has()
Renamed:
- Config#get() to Config#Get()
- Config#set() to Config#Set()
- Config#save() to Config#Save()
Added:
- Config#GetOfType()
The cfg-reader is now using the open source alt-config parser from the altMP Team. It should be way faster than my own parser in v1. Additionally is this module now a native node addon. If you find a memory leak make sure to create an issue at this repo. Contributions are welcome.
Note
- The setter method isn't working rn
- Lists and Dicts arent support atm
Example
config.cfg
mysql_host: 127.0.0.1,
mysql_user: root,
mysql_password: test123,
mysql_database: db
or
This is not working until its possible to get dicts
mysql: {
host: 127.0.0.1,
user: root,
password: test123,
database: db
}
index.js This is not working until its possible to get dicts
const mysql = require('mysql2');
const config = new require('cfg-reader')('config.cfg');
const con = mysql.createConnection(config.Get('mysql'));
...
Workaround while its not possible to get dicts
const mysql = require('mysql2');
const config = new require('cfg-reader')('config.cfg');
const con = mysql.createConnection({
host: config.Get('mysql_host'),
user: config.Get('mysql_user'),
password: config.Get('mysql_password'),
database: config.Get('mysql_database')
});
...
2 years ago
2 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago