mem-storage-area

1.0.3 • Public • Published

mem-storage-area

Build Status dependencies Status JavaScript Style Guide

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

See MDN storage API docs

Contribute

Feel free to dive in! Open an issue or submit PRs.

License

MIT © Alan Shaw

Package Sidebar

Install

npm i mem-storage-area

Weekly Downloads

5,416

Version

1.0.3

License

MIT

Last publish

Collaborators

  • alanshaw