Lightweight typescript configuration handler, supporting config files, default values and dot notation paths.
npm install configstore-ts
import ConfigTS from "configstore-ts";
interface IConfig {
foo: string;
bar: string;
}
const config = new ConfigTS<IConfig>(null, {
foo: "foo-value"
});
config.get("foo"); // config-foo
config.get<IConfig["foo"]>("foo"); // config-foo
config.has("foo"); // true
config.has("bar"); // false
config.get("bar"); // throws error
config.set("bar", "bar-value")
config.has("bar"); // true
config.get("bar"); // 123456
config.is("bar", "123456"); // true
config.unset("bar"); // false
config.has("bar"); // false
config.get("bar"); // throws error
config.get("bar", "default-value"); // default-value
// dot-notation usage for nested properties
config.get("foo.bar.baz") // throws error
config.get("foo.bar.baz", "default-value") // default value
config.set("foo", {bar: "baz"});
config.get("foo.bar.baz") // baz
config.get("foo.bar.baz", "default-value") // default valuebaz
Optional. Path to config file to read from or write to. Example: path.join(__dirname, "./config.json") Avoid usage of relative paths!
Optional. Define default values.
Properties from filePath and defaults will be merged, where filePath properties will override defaults duplicate properties.
No value found bt key, will return default value if defined, otherwise throws an error. T is optional.
Is store value strict equal to value param.
Does property exist on store.
Adds new property to store. dont-notation property-keys will throw error if toplevel object is undefined!
Removes key from store.
Returns entire store object
Number of keys in toplevel store object.
Sets store object to empty object
Will write to config file. Throws an error if no filePath is specified.
Returns path to config file.