0.0.1 • Published 1 year ago
json-master v0.0.1
json-master module
Introduction
This is a simple module for storing and managing data in JSON format. Great for small projects, making coding easier and faster!
Installation
Installation from npm
npm i json-master
Installation from yarn
in the future
Setup
Importing
import Storage from 'json-master';
To use ES6, add to package.json
:
"type": "module"
Creating storage
// Specify the path to the storage
const path = Storage.path('storages', 'example.json');
// Indicate the stored data, its types and default values
const structure = {
key: {
type: 'string',
},
};
// Create a class for further work with the repository
const storage = new Storage(path, structure);
Example
This is a small example with which you can easily start using json-master
.
import { resolve } from 'path';
import { Storage } from 'json-master';
const path = resolve('storages', 'users.json');
const structure = {
name: {
type: 'string',
},
age: {
type: 'number',
},
is_verified: {
type: 'boolean',
default: false,
},
};
const options = {
spaces: 2,
save: {
onExit: true,
},
};
const storage = new Storage(path, structure, options);
const userID = 12345;
storage.set(userID, {
name: 'Kio Gia',
age: 21,
});
const user = storage.get(userID);
console.log(user);
You can find more examples here.