new ConfigParser()
- Source:
Methods
addSection(section)
Adds a section named section to the instance. If the section already exists, a DuplicateSectionError is thrown.
Parameters:
Name | Type | Description |
---|---|---|
section |
string | Section Name |
- Source:
get(section, key, rawopt) → {string|undefined}
Gets the value for the key in the named section.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
section |
string | Section Name |
||
key |
string | Key Name |
||
raw |
boolean |
<optional> |
false | Whether or not to replace placeholders |
- Source:
Returns:
- Type
- string | undefined
getFloat(section, key) → {number|undefined|NaN}
Coerces value to a float.
Parameters:
Name | Type | Description |
---|---|---|
section |
string | Section Name |
key |
string | Key Name |
- Source:
Returns:
- Type
- number | undefined | NaN
getInt(section, key, radixopt) → {number|undefined|NaN}
Coerces value to an integer of the specified radix.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
section |
string | Section Name |
||
key |
string | Key Name |
||
radix |
int |
<optional> |
10 | An integer between 2 and 36 that represents the base of the string. |
- Source:
Returns:
- Type
- number | undefined | NaN
hasKey(section, key) → {boolean}
Indicates whether the specified key is in the section.
Parameters:
Name | Type | Description |
---|---|---|
section |
string | Section Name |
key |
string | Key Name |
- Source:
Returns:
- Type
- boolean
hasSection(section) → {boolean}
Indicates whether the section is present in the configuration file.
Parameters:
Name | Type | Description |
---|---|---|
section |
string | Section Name |
- Source:
Returns:
- Type
- boolean
items(section) → {Object}
Returns an object with every key, value pair for the named section.
Parameters:
Name | Type | Description |
---|---|---|
section |
string | Section Name |
- Source:
Returns:
- Type
- Object
keys(section) → {Array}
Returns an array of all keys in the specified section.
Parameters:
Name | Type | Description |
---|---|---|
section |
string | Section Name |
- Source:
Returns:
- Type
- Array
read(file)
Reads a file and parses the configuration data.
Parameters:
Name | Type | Description |
---|---|---|
file |
string | Buffer | int | Filename or File Descriptor |
- Source:
readAsync(file)
Reads a file asynchronously and parses the configuration data.
Parameters:
Name | Type | Description |
---|---|---|
file |
string | Buffer | int | Filename or File Descriptor |
- Source:
removeKey(section, key) → {boolean}
Removes the property specified by key in the named section.
Parameters:
Name | Type | Description |
---|---|---|
section |
string | Section Name |
key |
string | Key Name |
- Source:
Returns:
- Type
- boolean
removeSection(section) → {boolean}
Removes the named section (and associated key, value pairs).
Parameters:
Name | Type | Description |
---|---|---|
section |
string | Section Name |
- Source:
Returns:
- Type
- boolean
sections() → {Array}
Returns an array of the sections.
- Source:
Returns:
- Type
- Array
set(section, key, value)
Sets the given key to the specified value.
Parameters:
Name | Type | Description |
---|---|---|
section |
string | Section Name |
key |
string | Key Name |
value |
* | New Key Value |
- Source:
write(file)
Writes the representation of the config file to the specified file. Comments are not preserved.
Parameters:
Name | Type | Description |
---|---|---|
file |
string | Buffer | int | Filename or File Descriptor |
- Source:
writeAsync(file) → {Promise}
Writes the representation of the config file to the specified file asynchronously. Comments are not preserved.
Parameters:
Name | Type | Description |
---|---|---|
file |
string | Buffer | int | Filename or File Descriptor |
- Source:
Returns:
- Type
- Promise