Skip to content

Browser-level KV store, utilizing both IndexedDB and local storage.

License

Notifications You must be signed in to change notification settings

rayriffy/datastore

Repository files navigation

datastore

Browser-level KV store, utilizing both IndexedDB and local storage.

This library will provide benefits of almost unlimited storage size of IndexedDB, with ease of use when interacting with interface like LocalStorage.

If browser does not have IndexedDB, this library will performs a fallback to LocalStorage by itself

Install

pnpm add @rayriffy/datastore

Usage

// initialize (initialize once, use everywhere)
const instance = createInstance('indexedDb-database-name')

// set (lib will JSON.stringify() for you in localStorage)
await instance.setItem('key1', {
  message: 'amogus',
})

// get (default to null) (lib will JSON.parse() for you in localStorage)
const val = await instance.getItem('key1')

// delete
await instance.removeItem('key1')

// clear
await instance.clear()

Publishing

This repository has been configured to automatically publish NPM packages by Changesets. Run pnpm changeset command to publishing your changes before commit.

About

Browser-level KV store, utilizing both IndexedDB and local storage.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published