1.1.2 • Published 6 years ago
global-key-value-store v1.1.2
Global Key Value Store
Small and lightweight key value store that makes the stored values globally available. This works in Node.js as well as in the browser across modules and Javascript files. Each value can be assigned to a key. Multi-values are also supported via a separate API. A callback API can be used to receive notifications when values are changed or removed.
Install
npm i global-key-value-store
Examples
Set, get and remove a single value
const store = require('global-key-value-store');
store.set('message', 'Hello World!');
console.log(store.get('message')); // Hello World!
store.remove('message');
console.log(store.get('message')); // undefined
Set, get and remove multiple values for a key
const store = require('global-key-value-store');
store.push('messages', 'Hello World!');
store.push('messages', 'Goodbye!');
console.log(store.get('messages')); // [ Hello World!, Goodbye! ]
store.remove('messages');
console.log(store.get('messages')); // undefined
Clear all values
const store = require('global-key-value-store');
store.clear();
Subscribe and unsubscribe callback functions
const store = require('global-key-value-store');
var callback = () => console.log('Message has changed!');
store.subscribe('message', callback);
store.set('message', 'Hello World!'); // Message has changed!
store.set('message', 'Goodbye!'); // Message has changed!
store.unsubscribe('message', callback);
store.remove('message'); // (silent)