Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

bkv

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bkv

Browser key/value storage with simple interface

  • 1.0.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

bkv - simple KV storage for browsers

CI NPM version

bkv is browser persistent key/value storage with simple interface. It supports actual IndexedDB / localStorage. With silent fallback to memory store for error-less work (optional).

Install

npm install bkv --save

Examples

const bkv = new window.BKV()

await bkv.set('dolorem', { lorem: 'ipsum' })

const data = await bkv.get('dolorem')
console.log(`Loaded: ${data}`)

await bkv.remove('dolorem'));

API

Note, all methods with optional callbacks will return promises if callback is not set.

new BKV([options])

Options:

  • prefix - Data namespace. Default - bkv. Used to separate data for multiple instances, if required.
  • stores - Array of storage names to use, ordered by preference. Default ['indexeddb', 'localstorage', 'zero']. Set to ['indexeddb', 'localstorage'] if no fallback to memory required.

* zero is simple memory store for silent fallback when no persistent storages available.

.get(key [, default]) => Promise

Load data by key name. If not exists - returns default (if passed) or undefined.

.getAll() => Promise

Load all data from storage as [ { key, value }, { key, value }, ... ].

.set(key, data [, ttl]) => Promise

Put data into storage under key name.

  • key - String to address data.
  • data - serializable JS object to store.
  • ttl - Expiration time in seconds. Default = 0 (don't expire).

.remove(key | [keys]) => Promise

Remove key data from store. If Array passed - remove all listed keys.

.clear([expiredOnly]) => Promise

Clear all storage data (in your namespace), or just expired objects when called with true param.

.init() => Promise

Auto-executed on first call of any method. Usually not needed. But may be used, if you need exact info about availability of persistent storage, prior to start.

.create(options)

Alias of new BKV(options)

.shared(options)

Similar to .create() but returns the same (cached) instance for the same options. Useful if you need BKV in multiple modules, and don't wish to initialize it every time.

FAQs

Package last updated on 16 Feb 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc