Skip to content

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

License

Notifications You must be signed in to change notification settings

akpi816218/jsoning

 
 

Repository files navigation

jsoning

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


CodeCov Build Status Latest Stable Version NPM Downloads node-current FOSSA Status


View Demo · Report Bug · Request Feature

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


🚨 Since v0.10.19, JSON files are generated in the current working directory, rather than within the node_modules which resulted in loss of the JSON files whenever packages were re-installed!

Features ✨

  • Uses JSON files to modify and write key-value elements.
    • This allows for the usage of pre-existing JSON files by specifying the path when creating a new instance of Jsoning.
  • Easy to use, beginner-friendly and lightweight.
  • Writes atomically to prevent file corruption.

Install 💾

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

npm i jsoning
yarn add jsoning
pnpm i jsoning

View the full documentation here.

Basic Usage 📑

import { Jsoning, MathOps } from 'jsoning';
const db = new Jsoning('database.json');

// 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');

// Get the value of a key
console.log(await db.get('transformers')); // [ 'optimus prime', 'bumblebee', 'iron hide' ]

// Get all the values
console.log(await db.all()); // { Record<string, JSONValue> 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
await db.math('money', MathOps.Add, 200);

// Just wanna make sure how much money I got
console.log(await db.get<number>('money')); // 300

// RIP iron hide, he died
await db.remove('transformers', 'iron hide');

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

Contributing

Please see CONTRIBUTING.md for more details on contributing!

Contributors

All Contributors

Thanks goes to these wonderful people (emoji key):

Khaleel Gibran
Khaleel Gibran

💻 📖 🎨 🚇 ⚠️
David
David

📖
Jonyk56
Jonyk56

💻
ayntee
ayntee

💻
undefine
undefine

💻 🐛 🛡️
Aditya Gupta
Aditya Gupta

💻
Manuel Maly
Manuel Maly

💻 🐛
wh0
wh0

💻
akpi816218
akpi816218

💻 📖 💡 🚧 ⚠️ 🔧

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

About

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

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 82.6%
  • JavaScript 17.4%