1.0.1 • Published 2 months ago

jsoning v1.0.1

Weekly downloads
68
License
MIT
Repository
github
Last release
2 months ago

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

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

View Demo · Report Bug · Request Feature


Jsoning is a simplified wrapper for Node.js that lets you write and read data to and from JSON files. It's designed to be beginner-friendly and easy to use, with a simple API that makes it easy to get started with. It's perfect for small projects, prototyping, and learning how to work with databases.

Features

  • Use existing JSON files to read and write key-value pairs
  • EventEmitters to listen to changes in the database
  • Atomic file writing to prevent data corruption
  • Easier to use than a toaster
  • TypeScript support for all the fixed-type addicts out there

Install

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

npm i jsoning

# pnpm if you're feeling fast
pnpm i jsoning

# yarn if you're feeling fancy
yarn add 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):

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

1.0.1

2 months ago

1.0.0

2 months ago

0.13.23

2 years ago

0.12.22

3 years ago

0.11.22

3 years ago

0.11.21

3 years ago

0.10.21

3 years ago

0.9.18

3 years ago

0.10.18

3 years ago

0.10.19

3 years ago

0.10.20

3 years ago

0.8.18

3 years ago

0.8.15

4 years ago

0.8.14

4 years ago

0.7.14

4 years ago

0.6.14

4 years ago

0.6.13

4 years ago

0.5.13

4 years ago

0.5.12

4 years ago

0.5.11

4 years ago

0.4.11

4 years ago

0.3.11

4 years ago

0.3.9

4 years ago

0.2.7

4 years ago

0.2.6

4 years ago

0.2.9

4 years ago

0.2.8

4 years ago

0.2.5

4 years ago

0.0.3

4 years ago

0.0.5

4 years ago

0.0.1

4 years ago