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

@salemkode/ranidb

v0.0.75

Published

> A simple "database" that use JSON file for Node.JS.

Downloads

3

Readme

Ranidb

A simple "database" that use JSON file for Node.JS.

Installation

Add ranidb to your existing Node.js project.

with npm :

npm i @salemkode/ranidb

or with yarn:

yarn add @salemkode/ranidb

Used with node

const ranidb = require("ranidb");

API

  • Ranidb()
  • db.save()
  • db.getAll()
  • db.push()
  • db.find()
  • db.filter()
  • db.findIndex()
  • db.clear()
  • db.updata()
  • Options

Ranidb(path_db)

The main entry point for creating a new Ranidb instance.

  • path_db it must be string for path to file json, for example : "./db/data.json"
let db = new ranidb("./db/data.json");

save(data)

This function will delete all data and then rewrite it again.

  • data it must be Array data.
let db = new ranidb("./db/data.json");
let arr = [
  { id: 1, name: "sami", age: 21 },
  { id: 2, name: "was", age: 19 },
  { id: 3, name: "ahmed", age: 17 },
];

db.save(arr);

getAll()

This function will return data in file json.

let db = new ranidb("./db/data.json");
db.getAll();

/* Output :
[
    // all data in DB (File json)
]
*/

push(data)

This function will push data in file json.

  • data it must be object data.
let db = new ranidb("./db/data.json");
let data = { name: "ahmed", age: 17 };

db.push(data);
/* Output :
{
   {"_id": "R_Ddwtu1A", name:"ahmed", age:17}
}
*/

filter(data)

This function will data to need find.

  • data it must be object data or function.
let db = new ranidb("./db/data.json");

db.filter((user) => user.age > 12);

/* Output :
[
  { _id: 'Wtl9v2x-Q', user: 'barney', age: 36, active: true },
  { _id: 'rqACSWx6kA', user: 'fred', age: 40, active: false }
]
*/

db.filter((user) => user.active == true);

/* Output :
[
  { _id: 'Wtl9v2x-Q', user: 'barney', age: 36, active: true },
  { _id: 'DniDQHMNpo', user: 'pebbles', age: 1, active: true },
  { _id: 'SflmjJaVN', user: 'barney', age: 36, active: true },
  { _id: 'mL7Np2hr_Z', user: 'pebbles', age: 1, active: true }
]
*/

find(data)

This function will data to need find.

  • data it must be object data.
let db = new ranidb("./db/data.json");

db.find({ _id: "rqACSWx6kA" });

/* Output :
    {"_id": "rqACSWx6kA","user": "fred","age": 40,"active": false}
*/

db.find({ _id: "rqACSWx6kA", age: 40 });

/* Output :
    {"_id": "rqACSWx6kA","user": "fred","age": 40,"active": false}
*/

all Sub-functions work in find like filter ()

findIndex(data)

This function will find index for this data.

  • data it must be object data.
let db = new ranidb("./db/data.json");

/*
[
    {
        "_id": "Wtl9v2x-Q",
        "user": "barney",
        "age": 36,
        "active": true
    },
    {
        "_id": "rqACSWx6kA",
        "user": "fred",
        "age": 40,
        "active": false
    },
    {
        "_id": "DniDQHMNpo",
        "user": "pebbles",
        "age": 1,
        "active": true
    }
]
*/

db.findIndex({ _id: "Wtl9v2x-Q" });

/* Output :
    0
*/

db.findIndex({ _id: "rqACSWx6kA", age: 40 });

/* Output :
    1
*/

// for not find
db.findIndex({ _id: "rqACSWx6kA", age: 42 });

/* Output :
    -1
*/

clear()

This function will clear all data in ranidb.

let db = new ranidb("./db/data.json");
/* in file json :
[
  { _id: 'Wtl9v2x-Q', user: 'barney', age: 36, active: true },
  { _id: 'DniDQHMNpo', user: 'pebbles', age: 1, active: true },
  { _id: 'SflmjJaVN', user: 'barney', age: 36, active: true },
  { _id: 'mL7Np2hr_Z', user: 'pebbles', age: 1, active: true }
]
*/
db.clear();
/* Output :
   []
*/

updata(find, data)

This function will data to need find.

  • find it must be opject.
  • data it must be object.
let db = new ranidb("./db/data.json");
/* in file json :
[
  { _id: 'Wtl9v2x-Q', user: 'barney', age: 36, active: true },
  { _id: 'DniDQHMNpo', user: 'pebbles', age: 1, active: true },
  { _id: 'SflmjJaVN', user: 'barney', age: 36, active: true },
  { _id: 'mL7Np2hr_Z', user: 'pebbles', age: 1, active: true }
]
*/

let data = {
  _id: "Wtl9v2x-Q",
  user: "barney",
  age: 42,
  active: true,
};

db.updata({ _id: "Wtl9v2x-Q" }, data);

/* Output :
   { _id: 'Wtl9v2x-Q', user: 'barney', age: 42, active: true }
*/

delete(find)

This function will data to need find.

  • find it must be opject.
let db = new ranidb("./db/data.json");
/* in file json :
[
  { _id: 'Wtl9v2x-Q', user: 'barney', age: 36, active: true },
  { _id: 'DniDQHMNpo', user: 'pebbles', age: 1, active: true },
  { _id: 'SflmjJaVN', user: 'barney', age: 36, active: true },
  { _id: 'mL7Np2hr_Z', user: 'pebbles', age: 1, active: true }
]
*/

let data = {
  _id: "Wtl9v2x-Q",
  user: "barney",
  age: 42,
  active: true,
};

db.delete({ _id: "Wtl9v2x-Q" });

/* Output : true */
/* in file json :
[
  { _id: 'DniDQHMNpo', user: 'pebbles', age: 1, active: true },
  { _id: 'SflmjJaVN', user: 'barney', age: 36, active: true },
  { _id: 'mL7Np2hr_Z', user: 'pebbles', age: 1, active: true }
]
*/

Options

now we're going to make changes to some of the virtual things

  • idType it must be string.

    • random (default)
    let db = new ranidb("./db/data.json", { idType: "random" });
    /*
    is like let db = new ranidb("./db/data.json")
    */
    /* Output :
       { _id: 'Wtl9v2x-Q', ... }
    */
    • empty
    let db = new ranidb("./db/data.json", { idType: "empty" });
    /* Output :
       { ... }
    */
    • gradual
    let db = new ranidb("./db/data.json", { idType: "gradual" });
    /* Output :
       { _id: '1', ... },
       { _id: '2', ... },
       { _id: '3', ... },
       { _id: '4', ... },
       { _id: '5', ... }
    */