Simple And Modular Storage System
Changelog
Fixed FileStorage#loadSync
You can now use Storage#default as a builder. Example:
Storage.default().add('hello', 'world').add('test', true).end()
. You don't need to save anymore, as long as you useend()
. It's an async function.Few other fixes
SAMSS is easy to use:
- Lightweight
- Contains 3 storage types: Storage, FileStorage and EncryptedStorage.
- Based on promises and async/await, but also contains synchronous methods.
- Uses JSON, but you can create your own custom storage (more informations soon - the API already exists)
Installation
SAMSS requires zero dependencies.
Install SAMSS using npm.
$ npm i samss
How to use
Using the Base Storage
var Storage = require('samss').getStorage();
Storage.set('hello', 'world');
Using the File Storage
var Storage = require('samss').getStorage('FS', 'file.json');
Storage.load().then(() => {
await Storage.default()
.add('hello', 'world')
.add('this', ['is', 'a', 'default', 'value'])
.end();
await Storage.save();
}
Using the Encrypted Storage
var Storage = require('samss').getStorage('Encrypted', 'encrypted_file.random.ext', 'THIS_IS_THE_PASSWORD', 'algorithm');
await Storage.load();
await Storage.default()
.add('hello', 'world')
.add('this', ['is', 'a', 'default', 'value'])
.end();
await Storage.save();
Storage#default()#end() tries to save the storage.
If the file doesn't exist, it gives an empty object, instead of an ENOENT error.
License
This project is licensed under the MIT License. You can check here for more details.