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

xcf-db

v0.0.4

Published

A lightweight, file-based key-value database library for local storage and management of data.

Downloads

7

Readme

xcf-db

Discord GitHub Action NPM Version NPM Downloads NPM Unpacked Size NPM License

Installation

You can install xcf-db using npm:

npm install xcf-db

Usage

To use xcf-db, import the database function and create an instance of the database.

JavaScript Example

Creating a Database Instance

const { database } = require("xcf-db")

const db = database()

If you want to use a custom path for your database, you can pass the path option:

const db = database({ path: "Your Custom Path" })

Setting Data

To set data in the database, use the set method:

db.set("cool", { data: "This is data" })
// Returns: { data: "This is data" }

Getting Data

To retrieve data from the database, use the get method:

db.get("cool")
// Returns: { data: "This is data" }

Removing Data

To remove data from the database, use the delete method:

db.delete("cool")
// Returns: true if data exists, otherwise returns false

Checking Data Existence

To check if a key exists in the database, use the has method:

db.has("cool")
// Returns: true if the key exists, otherwise false

Clearing the Database

To clear all data in the database, use the clear method:

db.clear()
// Clears all data in the database

TypeScript Example

Creating a Database Instance

import { database } from "xcf-db"

const db = database<{ data: string }>()

If you want to use a custom path for your database, you can pass the path option:

const db = database<{ data: string }>({ path: "Your Custom Path" })

Setting Data

To set data in the database, use the set method:

db.set("cool", { data: "This is data" })
// Returns: { data: "This is data" }

Getting Data

To retrieve data from the database, use the get method:

const data = db.get("cool")
// Returns: { data: "This is data" }

Removing Data

To remove data from the database, use the delete method:

const removed = db.delete("cool")
// Returns: true if data exists, otherwise returns false

Checking Data Existence

To check if a key exists in the database, use the has method:

const exists = db.has("cool")
// Returns: true if the key exists, otherwise false

Clearing the Database

To clear all data in the database, use the clear method:

db.clear()
// Clears all data in the database

API

database(options?)

Creates a new database instance.

  • options (optional): An object containing configuration options.
    • path (optional): A string specifying the custom path for the database.

db.set(key, value)

Sets the value for the specified key in the database.

  • key: A string representing the key.
  • value: The value to set.

db.get(key, exist?)

Gets the value for the specified key from the database.

  • key: A string representing the key.
  • exist (optional): A boolean indicating whether to throw an error if the key does not exist.

db.delete(key)

Removes the value for the specified key from the database.

  • key: A string representing the key.

db.has(key)

Checks if the specified key exists in the database.

  • key: A string representing the key.

db.clear()

Clears all data from the database.

db.entries()

Retrieves all entries in the database as an array of key-value pairs.

  • Returns: An array of key-value pairs.

db.keys()

Retrieves all keys in the database.

  • Returns: An array of keys.

db.values()

Retrieves all values in the database.

  • Returns: An array of values.

db.size()

Retrieves the number of entries in the database.

  • Returns: The number of entries.

db.map()

Retrieves all entries in the database as a Map.

  • Returns: A Map of key-value pairs.

db.forEach(callbackfn, thisArg?)

Executes a callback function for each entry in the database.

  • callbackfn: A function to execute for each entry.
  • thisArg (optional): Value to use as this when executing callbackfn.

Example

JavaScript Example

const { database } = require("xcf-db")

const db = database()

// Set data
db.set("cool", { data: "This is data" })
// Returns: { data: "This is data" }

// Get data
db.get("cool")
// Returns: { data: "This is data" }

// Check if data exists
db.has("cool")
// Returns: true

// Remove data
db.delete("cool")
// Returns: true if data exists, otherwise returns false

// Clear the database
db.clear()
// Clears all data

TypeScript Example

import { database } from "xcf-db"

const db = database<{ data: string }>()

// Set data
db.set("cool", { data: "This is data" })
// Returns: { data: "This is data" }

// Get data
const data = db.get("cool")
// Returns: { data: "This is data" }

// Check if data exists
const exists = db.has("cool")
// Returns: true

// Remove data
const removed = db.delete("cool")
// Returns: true if data exists, otherwise returns false

// Clear the database
db.clear()
// Clears all data

License

This project is licensed under the Apache-2.0 License.