mem-storage-area
v1.0.3
Published
A WebExtension like StorageArea in memory
Downloads
5,236
Maintainers
Readme
mem-storage-area
A WebExtension like StorageArea in memory
https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/storage
For testing and whatever.
Install
npm install mem-storage-area
Usage
const storage = require('mem-storage-area')
storage.onChanged.addListener((changes, areaName) => {
console.log(`storage.${areaName} changed: ${changes}`)
})
await storage.local.set({ foo: 'bar' })
console.log(await storage.local.get('foo')) // { foo: 'bar' }
// also storage.sync and read-only storage.managed
Advanced
You can access the Storage, StorageArea and Emitter objects:
// If you need another storage - { local, sync, managed, onChanged }
const Storage = require('mem-storage-area/Storage')
const storage = new Storage()
// If you need an emitter
const Emitter = require('mem-storage-area/Emitter')
const onChanged = new Emitter()
// onChanged.addListener, onChanged.removeListener, onChanged.hasListener etc.
// To emit, call onChanged(arg0, arg1...)
// If you need a storage area (with optional emitter)
const StorageArea = require('mem-storage-area/StorageArea')
const area = new StorageArea({ name: 'myArea', onChanged, readOnly: false })
API
Contribute
Feel free to dive in! Open an issue or submit PRs.
License
MIT © Alan Shaw