@mdaemon/ini-file-cache
v1.0.1
Published
A library for reading, writing, and watching ini files for changes
Downloads
13
Maintainers
Readme
@mdaemon/ini-file-cache, A library for reading, writing, and watching ini files for changes
Not applicable to a browser context.
Install
$ npm install @mdaemon/ini-file-cache --save
Node CommonJS
const IniFileCache = require("@mdaemon/ini-file-cache");
Node Modules
import IniFileCache from "@mdaemon/ini-file-cache";
IniFileCache
// Create a new IniFileCache instance
const iniCache = new IniFileCache("/path/to/file/", "config.ini");
// Read a value from the ini file
const value = iniCache.get("section", "key", "defaultValue");
console.log(value);
// Write a value to the ini file
iniCache.set("section", "key", "new value");
// Save changes to the file
iniCache.save();
// Watch for changes in the ini file
iniCache.watch();
// Stop watching the file
iniCache.unwatch();
// Get all sections
const sections = iniCache.getSections();
console.log(sections);
// Get all keys in a section
const keys = iniCache.getKeys("section");
console.log(keys);
// Check if a section exists
const sectionExists = iniCache.hasSection("section");
console.log(sectionExists);
// Check if a key exists in a section
const keyExists = iniCache.hasKey("section", "key");
console.log(keyExists);
// Remove a key from a section
iniCache.removeKey("section", "key");
// Remove an entire section
iniCache.removeSection("section");
// Reload the file from disk
iniCache.reload();
iniCahe.listener.on("change", (filename) => { });
iniCache.listener.on("error", (error) => { });
iniCache.listener.on("reload", (filePath) => { });
iniCache.listener.on("save", (filePath) => { });
License
Published under the LGPL-2.1 license.
Published by MDaemon Technologies, Ltd. Simple Secure Email https://www.mdaemon.com