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

@heliomarpm/kvs

v1.3.0

Published

A simple and robust KeyValues Storage's library

Readme

DeepScan grade CodeFactor Test Coverage

NPM version Downloads

PayPal Ko-fi Liberapay GitHub Sponsors

📚 Summary

KeyValues Storage is a lightweight, file-based utility for managing key-value pairs using JSON. It offers intuitive methods for reading, writing, checking, and deleting values — all with support for both synchronous and asynchronous operations.

❓When Should You Use This Library?

You should consider using KeyValues Storage when you need:

  1. ✅ A simple and lightweight key-value store without the overhead of a full database.
  2. 🗂️ To persist configuration or state in local .json files.
  3. 🚀 Quick read/write operations for small or medium-sized data.
  4. 🧩 Nested object support with dot notation access ('user.profile.name').
  5. 🧪 Built-in support for both synchronous and asynchronous APIs.
  6. 🛡️ Safe and atomic writes to prevent file corruption.
  7. 📦 Minimal dependencies (just lodash and write-file-atomic).

💡 It's a great fit for:

  • Desktop apps (Electron, Tauri, etc.)
  • Low-traffic web servers or services
  • Caching user preferences
  • Storing app metadata
  • Configuration files
  • Testing and development tools
  • CLI Tools

🚀 Main Features

  • Manage key-value pairs in a persistent JSON file
  • Support for nested key paths
  • Multiple instances with different file names
  • Sync and async methods
  • Atomic writes and optional formatting

🔧 Usage

⚠Install the library:

npm install @heliomarpm/kvs
# or 
yarn add @heliomarpm/kvs

✏️ Example Code

// Default options
{
  atomicSave: true,
  fileName: 'keyvalues.json',
  prettify: false,
  numSpaces: 2
}
import { KeyValues } from '@heliomarpm/kvs';

// Create a new instance of KeyValues with or without custom options
const kvs = new KeyValues()
//or 
const kvs = new KeyValues({ fileName: 'config.json',  prettify: true });

const color =
{
  "name": "cerulean",
  "code": {
    "hex": "#003BE6",
    "rgb": [0, 179, 230]
  }
}

// Set a key-value
kvs.setSync(['settings', 'language'], "pt-Br");
kvs.getSync(['settings', 'language'])	
// => 'pt-Br'

// Set/Add a key settings
kvs.setSync("settings.default", "en");
kvs.getSync("settings")
// => { "language": "pt-Br", "default": "en" }

kvs.getSync();	
// => { "settings": { "language": "pt-Br", "default": "en" } }

// replace key settings
kvs.setSync("settings", { theme: "dark"});
kvs.getSync("settings")
// => { "theme": "dark" }

// Added a new key-value
kvs.setSync("color", color);
kvs.getSync();
// => { "theme": "dark", "color": { "name": "cerulean", "code": { "rgb": [0, 179, 230], "hex": "#003BE6" } } }

// Replace all key-values
kvs.setSync(color);
kvs.getSync();
// => { "name": "cerulean", "code": { "rgb": [0, 179, 230], "hex": "#003BE6" } }

// Unset a key-value
kvs.unsetSync();
kvs.getSync();
// => {}

// Set a new key-values
kvs.setSync("color", color);
kvs.getSync();	
// => { "color": { "name": "cerulean", "code": { "rgb": [0, 179, 230], "hex": "#003BE6" } } }

kvs.getSync("color.name")
// => "cerulean"

kvs.getSync("color.code.hex")
// => "#003BE6"

kvs.getSync(["color", "code"])
// or
kvs.getSync("color.code")
// => { "hex": "#003BE6", "rgb": [0, 179, 230] }

kvs.getSync(["color", "hue"])
// => undefined

// Set a key-value pair
await kvs.set("color.name", "sapphire");

// Get the value at a specific key path
const value = await kvs.get("color.name");
// => "sapphire"

// Check if a key path exists
const exists = await kvs.has("color.name");
// => true

// Remove a key-value pair
await kvs.unset("color.name");
await kvs.get(); 
// => { "code": { "rgb": [0, 179, 230], "hex": "#003BE6" } }

const exists = kvs.hasSync("color.name");
// => false

kvs.unset().then(() => {
  console.log("All key-value pairs have been removed.");
});

📚 API Reference

See the API documentation for a complete list of available functions and their signatures.

🧪 Methods

| Method | Description | |--------|-----------| constructor(options?) | Initializes a new instance of the KeyValues class with optional custom options. file(): string | Returns the path to the JSON file. resetOptions(): void | Resets the configuration of the KeyValues instance to default options. has(keyPath): Promise<boolean> | Checks if a key path exists asynchronously. hasSync(keyPath): boolean | Checks if a key path exists synchronously. get<T>(keyPath?): Promise<T> | Gets the value at a specific key path asynchronously. getSync<T>(keyPath?): T | Gets the value at a specific key path synchronously. set<T>(...args): Promise<void> | Sets a value at a specific key path asynchronously. setSync<T>(...args): void | Sets a value at a specific key path synchronously. unset(keyPath?): Promise<void> | Removes a key-value pair at a specific key path asynchronously. unsetSync(keyPath?): void |Removes a key-value pair at a specific key path synchronously.

📦 Project Scripts

  • npm run check — runs formatter, linter and import sorting to the requested files
  • npm run format — run the formatter on a set of files
  • npm run lint — run various checks on a set of files
  • npm run test — run unit tests
  • npm run test:c — run unit tests with coverage
  • npm run commit - run conventional commits check
  • npm run release:test — dry run semantic release
  • npm run build — build library

📦 Dependencies

  • lodash Utility functions for working with objects and arrays.
  • write-file-atomic Ensures file writes are safe and atomic.

🤝 Contributing

We welcome contributions! Please read:

Thank you to everyone who has already contributed to the project!

Made with contrib.rocks.

❤️ Support this project

If this project helped you in any way, there are several ways to contribute.
Help us maintain and improve this template:

⭐ Starring the repository
🐞 Reporting bugs
💡 Suggest features
🧾 Improving the documentation
📢 Share with others

💵 Supporting via GitHub Sponsors, Ko-fi, Paypal or Liberapay, you decide. 😉

PayPal Ko-fi Liberapay GitHub Sponsors

📝 License

MIT © Heliomar P. Marques 🔝