cfgread v1.1.4
CFGRead ( 1.1.4 )
This is a module for easily generating configuration files. Currently there are two supported formats, one I call "simple", the other is JSON. Besides generating configuration files, this module can also read configuration files.
Functions
format : Object
Kind: global variable
Example
format.SIMPLE
format.JSON
checkConfigFile(path) ⇒ boolean
Kind: global function
Returns: boolean - Returns true if the given configuration file exists, false if not.
Param | Type | Description |
---|---|---|
path | string | The path to the configuration file. |
setFormat(format)
Kind: global function
Throws: Throws when an invalid format has been given.
Param | Type | Description |
---|---|---|
format | format | The format you'd like to use for your configuration file. |
generateConfigFile(path, variables)
Generates a configuration file with a given set of variables. If no arguments are given, a default configuration file will be generated, which is empty.
Kind: global function
Param | Type | Description |
---|---|---|
path | string | The path to the configuration file. If no path has been given, a default path will be selected. |
variables | Array.<string> | The variables that you want people to be able to set in your configuration file. |
Example
// Creates a file with the following content:
// name1=value1
// name2=value2
// name3=
let cfgread = require('cfgread');
cfgread.generateConfigFile("./config.cfg", ["name1", "value1"], ["name2", "value2"], "name3");
setConfigFile(path)
Kind: global function
Throws: Throws when an invalid string has been given.
Param | Type | Description |
---|---|---|
path | string | The path to the configuration file. |
readConfigFile(path) ⇒ Object
Kind: global function
Returns: Object - Returns an object with the contents of the configuration file.
Throws: Throws when an invalid path has been given.
Param | Type | Description |
---|---|---|
path | string | The path to the configuration file. If no path is given, the default path will be used. |
Example
// Output: { name1: 'value1', name2: 'value2', name3: NaN }
cfgread.generateConfigFile("./config.cfg", ["name1", "value1"], ["name2", "value2"], "name3");
let output = cfgread.readConfigFile("./config.cfg");
console.log(output);