Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/tableflip/mem-storage-area

A WebExtension like StorageArea in memory
https://github.com/tableflip/mem-storage-area

memory persistence storage webextension webextension-api

Last synced: about 8 hours ago
JSON representation

A WebExtension like StorageArea in memory

Awesome Lists containing this project

README

        

# mem-storage-area

[![Build Status](https://travis-ci.org/tableflip/mem-storage-area.svg?branch=master)](https://travis-ci.org/tableflip/mem-storage-area)
[![dependencies Status](https://david-dm.org/tableflip/mem-storage-area/status.svg)](https://david-dm.org/tableflip/mem-storage-area)
[![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)

> A WebExtension like StorageArea in memory

https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/storage

For testing and whatever.

## Install

```sh
npm install mem-storage-area
```

## Usage

```js
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:

```js
// 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](https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/storage)

## Contribute

Feel free to dive in! [Open an issue](https://github.com/tableflip/mem-storage-area/issues/new) or submit PRs.

## License

[MIT](LICENSE) © Alan Shaw