-
Notifications
You must be signed in to change notification settings - Fork 21
Helpers.store()
Javi Jiménez edited this page Jun 26, 2016
·
2 revisions
A method for save json
objects on disk file:
import { store } from 'ava-ia/lib/helpers';
const db = store('classifier.json');
const key = 'your_attribute_key';
db.get(key);
db.set(key, {hello: 'world'});
// -- More info: https://github.com/typicode/lowdb
'use strict';
import lowdb from 'lowdb';
import path from 'path';
import fs from 'fs';
// -- Internal
const folder = path.resolve('.', 'store');
if (!fs.existsSync(folder)) fs.mkdirSync(folder);
export default (file, defaults = {}) => {
const store = lowdb(`${folder}/${file}`, { storage: require('lowdb/lib/file-async') });
if (defaults) store.defaults(defaults).value();
return store;
}
Feel free to offer new features, improvements or anything you can think of. This project makes sense with your participation and experience using Ava.