3.0.3 • Published 2 years ago

cfg-reader v3.0.3

Weekly downloads
101
License
ISC
Repository
github
Last release
2 years ago

cfg-reader

NPM Version NPM Downloads Node.js Version

License and copyright notice

alt-config (MIT)

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')
});
...
3.0.3

2 years ago

4.0.0-rc.2

2 years ago

3.0.2

2 years ago

3.0.1

3 years ago

3.0.0

3 years ago

3.0.0-rc6

3 years ago

3.0.0-rc5

3 years ago

3.0.0-rc7

3 years ago

2.3.0-rc.3

3 years ago

2.3.0

3 years ago

2.2.1

3 years ago

2.2.2-rc.0

3 years ago

2.1.0-rc.5

3 years ago

2.1.0-rc.4

3 years ago

2.1.0-rc.3

3 years ago

2.1.0

3 years ago

2.0.0-dev

3 years ago

2.0.0

3 years ago

2.0.0-rc15

3 years ago

2.0.0-rc14

3 years ago

2.0.0-rc11

3 years ago

2.0.0-rc12

3 years ago

2.0.0-rc13

3 years ago

2.0.0-rc10

3 years ago

2.0.0-rc7

3 years ago

1.4.0

3 years ago

2.0.0-rc9

3 years ago

2.0.0-rc8

3 years ago

2.0.0-rc6

3 years ago

2.0.0-alt0

3 years ago

2.0.0-rc5

3 years ago

2.0.0-alt1

3 years ago

1.3.3

3 years ago

2.0.0-alt2

3 years ago

2.0.0-rc4

3 years ago

1.3.2

3 years ago

1.3.1

3 years ago

1.3.0

3 years ago

2.0.0-rc3

3 years ago

2.0.0-rc2

3 years ago

2.0.0-rc1

3 years ago

1.2.0

4 years ago

1.2.1

4 years ago

1.1.0

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago