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

meowdb

v2.2.3

Published

Database in JSON

Downloads

109

Readme

MeowDB.js

MeowDB

Downloads Minified Size Vulnerabilities License Last Commit GitHub Repo stars

NPM

"Database" in JSON (Node.JS Library).

Released v2.2.3. See CHANGELOG.

Installation

  • npm install meowdb --save.

Also available in Ruby! MeowDB.rb

I recommend not using versions lower than 2.1.9 or being aware of updates to the library.

Usage

JavaScript - CommonJS require

const MeowDB = require("meowdb");

const myDatabase = new MeowDB({
    dir: __dirname,
    name: "database",
    raw: false // Defines if MeowDBObjects will be returned (optional, default: false)
});

TypeScript - ES6 import

With TypeScript you should've the esModuleInterop flag.

import MeowDB from "meowdb";
// The generic type is optional, by default it's "full" but when using the raw option, use "raw" instead of "full"
const myDatabase = new MeowDB<'full'>({
    dir: __dirname,
    name: "database",
    raw: false // Defines if MeowDBObjects will be returned (optional, default: false)
});

Example of all functions

// Creating object (it'll search property by property and if it doesn't exist, it'll create it otherwise it'll not modify the current information~)
// * where the first parameter is the ID, they're like properties of an object (same thing in most functions)
const newObject = myDatabase.create("0001", {
    name: "David",
    country: "CO",
    info: "Nothing to show"
});
console.log(newObject);

// Obtaining an object
const object = myDatabase.get("0001");
console.log(object);

// Modifying an object and saving it
object.name = "Deivid";
object.save();
console.log(object.name);

// Setting directly the value of an element
const newName = myDatabase.set("0001.info", "Just a person");
console.log(newName);

// Listing all objects
let temp = "";
Object.entries(myDatabase.all()).forEach((user) => {
    temp += `   - ${user[1].name} (ID: ${user[0]})\n`;
});
console.log(temp.trimRight());

// Finding an object
const anObject = myDatabase.find((user) => user.name === "Deivid");
console.log(anObject);

// Filtering objects
const someObjects = myDatabase.filter((user) => user.country === "CO");
console.log(someObjects);

// Deleting an object
const deletedObject = myDatabase.delete("0001");
console.log(deletedObject);

Important note while using TypeScript

You can use TypeScript Generics to create/get/update/set/find/filter the data, it doesn't matter what type you use.

const nonObjectValue = myDatabase.get<string>('0002.name');
console.log(nonObjectValue); // TS will interpret it as string

const numberValue = myDatabase.get<number>('some id here');
console.log(numberValue); // TS will interpret it as a number

const booleanValue = myDatabase.get<boolean>('some id here');
console.log(booleanValue); // TS will interpret it as a boolean

// With Objects/also works with interfaces
type Person = {
    name: string;
    country: string;
    info: string;
};

const objectValue = myDatabase.get<Person>('0002'); // This will return a MeowDBObject with the properties that you specified in the generic type
console.log(objectValue.name); // While typing '.name', you'll get *autocomplete*
// It also works when you save an MeowDBObject
objectValue.info = 'Hi!';

/// Important: Read the note in the Usage/TypeScript section.
objectValue.save(); // This will return a plain 'Person' object.

"Documentation"

new MeowDB(options)

Creates or gets a database

  • Parameters:
    • options - An object with the options
      • options.dir - A string indicating the directory that will have the database (must be an absolute path - the folder should be created)
      • options.name - A string with the name of the database
  • Throws: MeowDBError - If any option is invalid

Methods

all()

Returns all data stored in the database

  • Returns: MeowDBObject - All data

create(id, initialValue)

Creates an element in the database with the specified ID and sets it's value

  • Parameters:
    • id - A string representing the ID of the element to create
    • initialValue - The initial value of the element
  • Returns: Object - The created element
  • Throws: MeowDBError - If the ID or initialValue is invalid

delete(id)

Deletes an element from the database

  • Parameters:
    • id - A string representing the ID of the element to delete
  • Returns: Object - The deleted element
  • Throws: MeowDBError - If the ID is invalid

exists(id)

Checks if an element exists in the database

  • Parameters:
    • id - A string representing the ID of the element to check
  • Returns: Boolean - If it exists
  • Throws: MeowDBError - If the ID is invalid

get(id)

Gets an element of the database

  • Parameters:
    • id - A string representing the ID of the element to get
  • Returns: * - The element
  • Throws: MeowDBError - If the ID is invalid

set(id, value)

Sets the value of an element in the database

  • Parameters:
    • id - A string representing the ID of the element to update
    • value - The new value of the element
  • Returns: * - The value setted
  • Throws: MeowDBError - If the ID or value is invalid

find(callback, id?)

Finds an element in the database. You should only use this function if you're finding for objects

  • Parameters:
  • callback - A function that handles all the elements and decides which one will be returned
    • id? - A string representing the ID of the root element to find another elements (optional)
  • Returns: * - The element
  • Throws: MeowDBError - If the ID or callback is invalid

filter(callback, id?)

Filters elements in the database. You should only use this function if you're filtering for objects

  • Parameters:
    • callback - A function that handles all the elements and decides which ones will be returned
    • id? - A string representing the ID of the root element to find another elements (optional)
  • Returns: * - The elements (MeowDBObject[] if they're objects, array with ID and value if not)
  • Throws: MeowDBError - If the ID or callback is invalid

MeowDBError

Extends Error, only used for error reference.