Giter VIP home page Giter VIP logo

keyva's Introduction

Keyva Poster Image

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).

keyva's People

Contributors

paul-go avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

keyva's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.