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

darko.db

v1.1.0

Published

darko.db is a simple, file-based JSON database package for Node.js. It provides an easy-to-use interface for storing and retrieving data in a JSON format.

Downloads

35

Readme

darko.db

npm version

darko.db is a simple, file-based JSON database package for Node.js. It provides an easy-to-use interface for storing and retrieving data in a JSON format.

Installation

You can install darko.db using npm:

npm install darko.db

Usage

const { Database } = require("darko.db");
const db = new Database(); // Creates or uses "database.json" as the file name or use [ const db = new Database("json db file name"); ] for specific db file

//Example Usage

// Set a key-value pair
db.set("name", "NotDarko");

// Retrieve the value associated with a key
const name = db.get("name");
console.log(name); // Output: "NotDarko"

// Alias for `get`
const aliasname = db.fetch("name");
console.log(aliasname); // Output: "NotDarko"

// Check if a key exists
const keyexists = db.has("name");
console.log(keyexists); // Output: true

// Retrieve all data in the database
const alldb = db.fetchAll();
console.log(alldb);

// Delete a key and its associated value
db.delete("name");

// Reset the entire database
db.reset();

// Set key-value pairs
db.set("key1", "value1");
db.set("key2", "value2");
db.set("key3", "value3");

// Retrieve all key-value pairs
const allentries = db.all();
console.log(allentries);

// Slice a portion of key-value pairs
const sliceddata = db.slice(1, 3);
console.log(sliceddata);

// Find index of an element based on a condition
const index = db.findIndex(value => value === "value2");
console.log(index);

// Filter elements based on a condition
const filtereddb = db.filter(value => value.startsWith("value"));
console.log(filtereddb);

// Sort key-value pairs based on a compare function
const sorteddb = db.sort((a, b) => a.localeCompare(b));
console.log(sorteddb);

// Push a value to an array associated with a key
db.push("numbers", 5);
db.push("numbers", 10);
const numbers = db.get("numbers");
console.log(numbers);

// Perform arithmetic operations on a numeric key's value
db.set("count", 10);
db.math("count", "+", 5);
const count = db.get("count");
console.log(count);

// Remove a specific item from an array associated with a key
db.push("fruits", "apple");
db.push("fruits", "banana");
db.push("fruits", "cherry");
db.pull("fruits", "banana");
const fruits = db.get("fruits");
console.log(fruits);

// Get database statistics
const stats = db.getStats();
console.log(stats);

// Rename a key
db.renameKey('oldKey', 'newKey');

// Export data to a file
db.exportData();

// Import data from a file
db.importData('backup_database.json');

API Documentation

set(key, value) = Sets a key-value pair in the database.

get(key) = Retrieves the value associated with a key.

fetch(key) = Alias for get.

has(key) = Checks if a key exists in the database.

fetchAll() = Retrieves all data in the database.

delete(key) = Deletes a key and its associated value from the database.

reset(key) = Deletes all data if no key is provided. Deletes keys starting with the specified key if provided.

all() = Retrieves all key-value pairs in the database.

subtract(key, value) = Subtracts a value from a numeric key's value.

slice(start, end) = Creates a new object containing a portion of the key-value pairs, starting from index start up to but not including index end.

findIndex(callback) = Finds the index of the first element in the database that satisfies the provided testing function.

filter(callback) = Creates a new array with all elements that pass the test implemented by the provided function.

sort(comparefunction) = Sorts the key-value pairs based on the provided compare function.

add(key, value) = Adds a value to a numeric key's value.

push(key, value) = Pushes a value to an array associated with the key.

pull(key, value) = Removes a specific item from an array associated with a key.

math(key, limit, value) = Performs basic arithmetic operations on a numeric key's value.

renameKey(oldKey, newKey) = Renames a specific key to a new specific key.

getStats() = Retrieves statistics about the database, returns with an object with the number of keys and total data size.

exportData() = Exports the current data from the database.

importData(data file name) =  Imports data into the database.

Contributing

If you'd like to contribute, please fork the repository and make changes as you'd like. Pull requests are warmly welcome.

License

This project is licensed under the MIT License.