npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

browser-keyval-stores

v1.0.1

Published

The browser-keyval-stores package offers a clean and unified API to interact with browser storage mechanisms (localStorage, sessionStorage, and indexedDB) from your applications. It streamlines development and eliminates the need for browser-specific code

Readme

Browser KeyVal Stores

The browser-keyval-stores package offers a clean and unified API to interact with browser storage mechanisms (localStorage, sessionStorage, and indexedDB) from your applications. It streamlines development and eliminates the need for browser-specific code when working with client-side data storage.

Getting Started

Install the package:

npm i -S browser-keyval-stores

Usage

localStorage Store

import { LocalStorageStore } from 'browser-keyval-stores';

type IUserPreferences = {
  language: string,
  theme: string
};

const store = new LocalStorageStore<IUserPreferences>('userPreferences');

const uid = '2d22df80-fc4b-498a-a4a7-734daa71c8dd';

store.get(uid);
// undefined

store.set(uid, { language: 'en', theme: 'dark' });
store.get(uid);
// { language: 'en', theme: 'dark' }

store.set(uid, { language: 'es', theme: 'light' });
store.get(uid);
// { language: 'es', theme: 'light' }

store.del(uid);
store.get(uid);
// undefined

sessionStorage Store

import { SessionStorageStore } from 'browser-keyval-stores';

type IApplicationFormData = {
  fullName: string,
  passportNum: string,
};

const store = new SessionStorageStore<IApplicationFormData>('applicationForm');

store.get();
// undefined

store.set(undefined, { fullName: 'Jess Grateol', passportNum: 'P4366918' });
store.get();
// { fullName: 'Jess Grateol', passportNum: 'P4366918' }

store.set(undefined, { fullName: 'Jesus Graterol', passportNum: 'LA080402' });
store.get();
// { fullName: 'Jesus Graterol', passportNum: 'LA080402' }

store.del();
store.get();
// undefined

indexedDB Store

import { IndexedDBStore } from 'browser-keyval-stores';

type IBlogPost = {
  id: number,
  title: string,
  content: string,
};

const store = new IndexedDBStore<IBlogPost>('blogPosts');

await store.set(1, { id: 1, title: 'Test title', content: 'This is the ...'});
await store.get(1);
// { id: 1, title: 'Test title', content: 'This is the ...'}

await store.del(1);
await store.get(1);
// undefined

Types

The supported browser storage mechanisms.

type IStoreMechanism = 'tempMemory' | 'localStorage' | 'sessionStorage' | 'indexedDB';

The identifier used to manage records. The store behaves differently based on the type:

  • undefined: the data will be stored at the root of the store
  • string | number: the value will be coerced into a string and can be used to locate the data
type IRecordID = undefined | string | number;

Object in charge of interacting with the Browser's Storage API. This API is used by Window.localStorage & Window.sessionStorage.

interface IWebStorageStore<T> {
  // properties
  id: string;

  // methods
  isCompatible: () => boolean;
  get: (id?: IRecordID) => T | undefined;
  set: (id: IRecordID, data: T) => void;
  del: (id?: IRecordID) => void;
}

interface ILocalStorageStore<T> extends IWebStorageStore<T> {
  // ...
}

interface ISessionStorageStore<T> extends IWebStorageStore<T> {
  // ...
}

Object in charge of charge of interacting with the Browser's IndexedDB implementation.

interface IIndexedDBStore<T> {
  // properties
  id: string;

  // methods
  isCompatible(): Promise<boolean>;
  get: (id?: IRecordID) => Promise<T | undefined>;
  set: (id: IRecordID, data: T) => Promise<void>;
  del: (id?: IRecordID) => Promise<void>;
}

Built With

  • TypeScript

Running the Tests

# integration tests
npm run test:integration

# unit tests
npm run test:unit

License

MIT