Jsoning - A simple key-value JSON-based persistent lightweight database.✨

jsoning

:sparkles: A simple key-value JSON-based persistent lightweight database. :sparkles:


CodeCov
Build Status
Build Status
Build Status
License
Latest Stable Version

All Contributors

NPM Downloads
NPM Downloads
Pkgreview.dev Reviews
npm bundle size
GitHub repo size
node-current
Website
FOSSA Status


View Demo · Report Bug · Request Feature

Loved the project? Please consider donating to help it improve!

Like us a lot? Help others know why you like us! Review this package on pkgreview.dev :arrow_right: Review us on pkgreview.dev

Features

  • Uses JSON files to modify and write key-value elements as JSON-objects.
  • Easy to use and lightweight.
  • Prevents JSON corruption with atomic file writing.
  • Uses a single dependency (write-file-atomic)

Install :floppy_disk:

Node.js v12.x or greater is required for this package to work.

npm install jsoning

View the full documentation here.

Basic Usage :bookmark_tabs:

let jsoning = require("jsoning");
let db = new jsoning("database.json");


(async() => {

    // set some values with a key
    await db.set("birthday", "07-aug");
    await db.set("age", "13");

    // push stuff to an array for a particular key
    await db.push("transformers", "optimus prime");
    await db.push("transformers", "bumblebee");
    await db.push("transformers", "iron hide");

    // simply log what get is (i forgot what the transformers were)
    console.log(await db.get("transformers")); // [ 'optimus prime', 'bumblebee', 'iron hide' ]

    // just want to see what all is there
    console.log(await db.all()); // { object of the whole database contents }

    // does such a value exist
    console.log(await db.has("value2")); // false

    // my age keeps changing, so I'm deleting it
    console.log(await db.delete("age")); // true

    // i got 100$ for my birthday
    await db.set("money", 100);

    // and someone gave me 200 more dollars xD
    await db.math("money", "add", 200);

    // just wanna make sure how much money I got
    console.log(await db.get("money")); // 300

    // i'm getting bored, so i'm clearing the whole database
    await db.clear(); 

})();

Links :link:

Contributing

Please see CONTRIBUTING.md for more details on contributing!

Contributors

Thanks goes to these wonderful people (emoji key):


Khaleel Gibran

💻 📖 🎨 🚇 ⚠️

David

📖

Jonyk56

💻

ayntee

💻

undefine

💻 🐛 🛡️

This project follows the all-contributors specification.
Contributions of any kind are welcome!

License

This package is open sourced under the MIT License.

FOSSA Status

6 Likes

This is epic. I think im gonna use it for a project

Thanks for the valuable feedback, @lilnelly-oss!

Can you add an option to reopen the file from disk without creating a new object.

Yes @javaarchive, thanks for the idea, will implement it soon !

1 Like

You’re welcome. I’m using jsoning as a system where a user can switch languages during os boot.

It’s nice to hear that! :smiley:

1 Like

v0.5.13

Set almost any data type as value for an element when using Jsoning#set.

database.set("num1", 5);
database.set("obj", { "hi": "hello" });
database.set("arr", ["blue", "red", "yellow"]);
2 Likes

v0.6.14

Jsoning#has

See if a particular element exists by using its key.

Parameters

key (string) The key of the element to see if the element exists.

Returns

Boolean : True if the element exists or false if the element doesn’t exist.

Example

database.set("some value", "hi");

let has = database.has("some value");
console.log(has); // returns true 

let has2 = database.has("value");
console.log(has2); // returns false

Documentation: https://khalby786.github.io/jsoning/
Guide (WIP): https://jsoning.js.org/

1 Like

I’d also recommend having a look at

2 Likes

UPDATE! Jsoning hit 18,000 monthly downloads (with a total of 29,000 downloads) on npm! Thanks for all the support!

7 Likes