1.1.6 • Published 3 years ago

enmap-json-sync v1.1.6

Weekly downloads
9
License
MIT
Repository
-
Last release
3 years ago

Enmap-JSON-Sync

npm npm NPM npm bundle size

This package allows you to use most of the normal JS Map functions but in the background automatically persists your data to a JSON file. I created this project because I just wanted a simple way to create key pair values and have them automatically save to a file without needing to download and setup a bunch of third party applications such an SQL db. This is perfect for small projects or projects that don't need to persist a lot of data.

npm i enmap-json-sync

Examples & Usages

Create an instance

const EnJS = require('enmap-json-sync');
const Scores = new EnJS('./settings.json');
// Path to a JSON file

(async function () {
  await Scores.loadFromJSON();
})();

Creating

const EnJS = require('enmap-json-sync');
const Scores = new EnJS('./settings.json');
// Path to a JSON file

(async function () {
  await Scores.loadFromJSON();
  // Random ID of a user
  Scores.set('2342342343234234', { name: 'Brandon', score: 10 });
})();

Deleting

const EnJS = require('enmap-json-sync');
const Scores = new EnJS('./settings.json');
// Path to a JSON file

(async function () {
  await Scores.loadFromJSON();
  Scores.delete('2342342343234234');
})();

Updating

const EnJS = require('enmap-json-sync');
const Scores = new EnJS('./settings.json');
// Path to a JSON file

(async function () {
  await Scores.loadFromJSON();
  const currentScore = await Scores.get('2342342343234234').score;
  data.update('2342342343234234', 'score', currentScore++);
})();

Fetch All Keys

const EnJS = require('enmap-json-sync');
const Scores = new EnJS('./settings.json');
// Path to a JSON file

(async function () {
  await Scores.loadFromJSON();
  const scoreKeys = await Scores.keys();
})();
1.1.6

3 years ago

1.1.5

3 years ago

1.1.4

3 years ago

1.1.3

3 years ago

1.1.2

3 years ago

1.1.1

3 years ago

1.1.0

3 years ago

1.0.0

3 years ago