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

@heliomarpm/kvs

v1.0.6

Published

A simple and robust KeyValues Storage's library

Downloads

117

Readme

DeepScan grade CodeFactor CodeQL NPM version Downloads

lodash write-file-atomic

Summary

The KeyValues Storage library is a utility for managing key-value pairs and storing them in a JSON file. It provides methods for setting, getting, checking existence, and removing key-value pairs. This document provides an overview of the library and its usage.

Installation

You can install the library using npm or yarn:

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

Example Usage

// Create a new instance of KeyValues with or or without custom options

/**
 * Default Options
 * 
 * {
 *   atomicSave: true,
 *   fileName: 'keyvalues.json',
 *   prettify: false,
 *   numSpaces: 2,
 * }
 */
const kvs = new KeyValues()
-- or --
const kvs = new KeyValues({
  fileName: 'config.json',
  prettify: true
});

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

// Set a key-values
kvs.setSync('color', color);

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

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

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');

// Remove a key-value pair
await kvs.unset('color.name');

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

Code Analysis

Main functionalities

  • Manage key-value pairs and store them in a JSON file
  • Create one or more instances for different JSON files
  • Set and get values at specific key paths
  • Check if a key path exists
  • Remove key-value pairs

Methods

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

Fields

  • options: Options: The configuration options for the KeyValues instance.
  • fnc: Functions: An instance of the Functions class used for file operations and data manipulation.

Dependencies

  • lodash: The Lodash library exported as Node.js modules.
  • write-file-atomic: Atomically and asynchronously writes data to a file, replacing the file if it already exists. data can be a string or a buffer

Contributing

Please make sure to read the Contributing Guide before making a pull request.

Thank you to all the people who already contributed to project!

Made with contrib.rocks.

That said, there's a bunch of ways you can contribute to this project, like by:

  • :beetle: Reporting a bug
  • :page_facing_up: Improving this documentation
  • :rotating_light: Sharing this project and recommending it to your friends
  • :dollar: Supporting this project on GitHub Sponsors or Ko-fi
  • :star2: Giving a star on this repository

Donate

If you appreciate that, please consider donating to the Developer.

License

MIT © Heliomar P. Marques 🔝