0.2.0 • Published 6 months ago

bun-storage v0.2.0

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

bun-storage

A ponyfill for the Storage API, utilizing SQLite

License Version Build

Installation

bun install bun-storage

Usage

API

createLocalStorage

Usage: createLocalStorage(dbFile: string)
Returns: [Storage, EventEmitter]

Creates an instance of the localStorage API and a corresponding EventEmitter.

Example:

import { createLocalStorage } from 'bun-storage';

const [ localStorage, emitter ] = createLocalStorage('./db.sqlite');

// Listen for storage changes
emitter.addListener('storage', console.log);

createSessionStorage

Usage: createSessionStorage()
Returns: [Storage, EventEmitter]

Creates an instance of the sessionStorage API and a corresponding EventEmitter.

Example:

import { createSessionStorage } from 'bun-storage';

const [ sessionStorage, emitter ] = createSessionStorage();

// Listen for storage changes
emitter.addListener('storage', console.log);

Storage

Usage: new Storage(filePath: string | ':memory:', options: StorageEventOptions)

This class is used internally by both of the above factory functions. However, instanting the class allows you more control over the EventEmitter, i.e. you pass an existing one from your application code.

Example:

import { Storage } from 'bun-storage';
import EventEmitter from 'events';

const myEmitter = new EventEmitter();

const localStorage = new Storage('./db.sqlite', {
	emitter: myEmitter
});

// Listen for storage changes
myEmitter.addListener('storage', console.log);

License

This work is licensed under The MIT License.

0.2.0

6 months ago

0.1.6

6 months ago

0.1.5

8 months ago

0.1.4

1 year ago

0.1.3

1 year ago

0.1.2

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago