Conveniently manage the configuration file in your command-line project based on Node.js.
It just provides some simple features instead of a strict typecheck and validation cause a lighter package suit me a lot.
Inspiration comes from Tampermonkey
api.
The configuration file will be stored default in C:/Users/USERNAME/AppData/Roaming/PROJECT_NAME/Config/config.json
on Windows
, ~/.config/PROJECT_NAME/config.json
on Linux
and ~/Library/Preferences/PROJECT_NAME/config.json
on macOS
.
npm install vaultify
import Vault from './vault'
const vault = new Vault({
name: 'myproject'
})
// set a value
vault.set('first', 1)
console.log(vault.get('first')) // 1
// delete a value
vault.delete('first')
console.log(vault.get('first')) // undefined
All api is based on the Vault
class.
The Vault
class accepts an options object with the following properties:
The name of your project, it matters to the path of the configuration file.
Guess you want to change the name of the folder where the configuration file stored. It should contain a placeholder [NAME]
which will be replaced by the name
property.
For example, if you set displayNameTemplate
to config-[NAME]
and name
to myproject
, the configuration file will be stored in the folder config-myproject
.
The name of the configuration file. Default is config
.
The extension of the configuration file. Default is json
.
Of course you can set it to haha
or whatever you like, even without an extension.
The configuration will be stored like a json, so whatever you set the extension to, it will be parsed as a json by default.
The default values of the configuration file. It will be merged with the existing configuration file when the Vault
instance is created. The existing values that have the same key will be kept.
Whether to obfuscate the configuration file. Default is false
.
It designed to prevent users from modifying the configuration file manually, maybe useful in some cases?
Set a value to the configuration file.
The dot notation
is supported, which means you can set a nested value like this:
vault.set('a.b.c', 1)
// equals to
vault.set('a', {
b: {
c: 1
}
})
Important
You should ensure the value is not undefined
, Symbol
or other values that cannot be stored in a json file.
Get a value from the configuration file. If the value is not found, it will return the defaultValue
if provided, otherwise undefined
.
Of course, the dot notation is supported.
Delete a value from the configuration file. The dot notation is supported.
Reset all values in the configuration file to the default values. If hard
is true
, all values will be removed.
The data object that stores all values in the configuration file.
It's writable, so you can reassign it to update the configuration file if you want, like this:
vault.store = {
a: 1
}
Important
Be careful, only reassign it can update the configuration file, instead of reassign its properties.
The path of the configuration file.
The path of the folder where the configuration file stored.
The name of the folder where the configuration file stored.
The default values of Vault
.