Javascript ConfigFile
Configuration File handling object.
Constructor
- new ConfigFile()
- new ConfigFile(path)
- new ConfigFile(path,warn)
Where:
- path - Relative or absolute path to the Configuration file like "/path/to/file.conf"
- warn - True to warn if the file does not exist
# To allow Yate to detect where to read from: var conf = new ConfigFile(Engine.configFile("regfile")); # When using absolute path: var conf = new ConfigFile("/usr/local/etc/yate/regfile.conf");
Methods
- name()
Returns the path of the Configuration file.
- name(path)
Sets a new file path
- load(warn)
Loads the file content, optionally warns if it doesn't exist.
Returns true on success or false if the file does not exist.
- save()
Saves the file overwriting any existing content.
Returns true on success or false if the file could not be written.
- count()
Returns the number of sections in the file.
- sections()
Returns an associative Array containing ConfigSection objects representing each file section.
- getSection(name)
Returns a ConfigSection object for the section name.
Returns null if the section does not exist.
- getSection(name,create)
Returns a ConfigSection object for the section name, creates it if create is true.
Returns null if the section could not be created.
- getValue(section,key)
Retrieves the value of key in section. Returns undefined if the key or section does not exist.
- getValue(section,key,defValue)
Retrieves the value of key in section. Returns defValue if the key or section does not exist.
- getIntValue(section,key)
Retrieves the integer value of key in section. Returns 0 if the key or section does not exist.
- getIntValue(section,key,defValue)
Retrieves the integer value of key in section. Returns defValue if the key or section does not exist.
- getBoolValue(section,key)
Retrieves the boolean value of key in section. Returns false if the key or section does not exist.
- getBoolValue(section,key,defValue)
Retrieves the boolean value of key in section. Returns defValue if the key or section does not exist.
- setValue(section,key,value)
Sets the value for key in specified file section.
- addValue(section,key,value)
Add a new value for key in specified file section.
- clearSection(section)
Deletes the given section. Deletes all sections if section is undefined, null or empty
- clearKey(section,key)
Deletes the key from specified file section.
- keys(section)
Returns a numbered (non-associative) Array containing all the key names in section.
Notes
- Boolean
You may see that some parameters use true/false, on/off, enable/disable, t/f as values. This are all internally used as boolean values, so it is possible to use any of this values for boolean properties.
Example:
var prop = true == on == enable == t
var prop = false == off == disable == f
Note that this will not work: enable === true