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

objectkv

v0.4.0

Published

a lightweight in-memory key-value database

Downloads

2

Readme

ObjectKV

The ObjectKV is a simple and lightweight in-memory key-value database with subscription capabilities. It allows you to store and retrieve data while notifying subscribed functions whenever the store is updated.

Installation

ObjectKV can be installed using npm or yarn:

# Install with NPM
npm install objectkv

# Install with Yarn
yarn add objectkv

Usage

Import the createStore function from the module:

import { createStore } from "objectkv";

Creating a Store

To create a new store, invoke the createStore function:

const store = createStore();

Subscribing to Store Updates

To subscribe to the store and execute a callback function whenever the store is updated, use the subscribe method:

const callback = (updatedStore) => {
  // Do something with the updated store
};

store.subscribe(callback);

Setting Values in the Store

To set the value for a given key in the store, use the set method:

store.set("key", "value");

Retrieving Values from the Store

To retrieve the value associated with a given key from the store, use the get method:

const value = store.get("key");

The get method returns the value associated with the key or undefined if the key doesn't exist in the store.

Removing Items from the Store

To remove an item from the store based on the given key, use the del method:

const removed = store.del("key");

The del method returns true if the item was removed successfully, or false if the key doesn't exist in the store.

Clearing the Store

To remove all items from the store, use the clear method:

store.clear();

Example

Here's an example that demonstrates the basic usage of the ObjectKV:

import { createStore } from "objectkv";

const store = createStore();

const callback = (updatedStore) => {
  console.log("Store updated:", updatedStore);
};

store.subscribe(callback);

store.set("name", "John Doe");
store.set("age", 25);

const name = store.get("name");
console.log("Name:", name);

store.del("age");

store.clear();

Output:

Store updated: Map { 'name' => 'John Doe' }
Store updated: Map { 'name' => 'John Doe', 'age' => 25 }
Name: John Doe
Store updated: Map { 'name' => 'John Doe' }
Store updated: Map {}

Contributing

Contributions to ObjectKV are always welcome! If you find a bug or want to suggest an improvement, please open an issue or submit a pull request to the repository: https://github.com/itsag/objectkv

License

This project is licensed under the MIT License.