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 🙏

© 2024 – Pkg Stats / Ryan Hefner

keyvajs

v1.0.5

Published

<p align="center"> <img src="readme-poster.png" alt="Keyva Poster Image"> </p>

Downloads

8

Readme

What is Keyva?

Keyva is a feather-weight zero-dependency TypeScript library that gives you key/value access to IndexedDB. It's as easy to use as localStorage, but still manages to expose a lot of the power of IndexedDB, such as complex object storage, binary data storage, indexes, and querying.

Why Keyva?

There are many existing IndexedDB abstractions. While these projects meet some definition of functional, a library design aficionado like myself finds them insufficiently elegant. This matters. Especially for a key/value access layer which is going to be used in literally every app one might build.

Some libraries have that it factor where a significant amount of thought was obviously given to the interface, rather than only the internals. These libraries place a very high value on ergonomics, simplicity, naming, cognitive load minimization, and achieving the best possible Intellisense experience. These libraries have staying power. They're the type you keep reaching for year after year.

I didn't find any key/value access layer that inspired this level of confidence. So I designed one that does.

Features

  • Simple like localStorage, but powerful like IndexedDB.
  • Feather-weight. Only 1.5KB zipped + minified.
  • Zero dependencies
  • Written in TypeScript. Code is commented and readable.

Installation

Installation via npm:

npm install keyvajs --save

Script tag installation:

<script src="https://cdn.jsdelivr.net/npm/keyvajs/keyva.min.js"></script>

Or just download the Keyva.ts file and add it directly to your project.

Usage

Start by creating a Keyva object, which creates a new IndexedDB database with a default name:

const kv = new Keyva();

The Keyva class only has 4 methods: .get(), .set(), .delete(), and .each(). These methods have a few overloads, but otherwise, this is essentially the entire library.

// Writing
await kv.set("some-key", "some-value");

// Reading
const value = await kv.get("some-key");

// Deleting
await kv.delete("some-key");

// Iteration
for (const [key, value] of await kv.each()
{
	// Do stuff
}

Advanced Usage

Get all keys and values from a Keyva:

const all = await kv.get();

Get multiple values at once:

const all = await kv.get(["key1", "key2"]);

Set multiple values at once:

await kv.set([["k0", "v0"], ["k1", "v1"], ["k2", "v2"]]);

For more complete usage examples, see the tests file

Shameless Plug

Do you need a world class player who can architect complex projects, design & implement beautiful UIs, write production-grade compilers, manage engineering teams, and speak the language of business? I'm available for hourly consulting work. (See my profile for contact info).