edjison v1.0.5
Edjison
A simple NodeJs package to modify json files
const edjison = require('edjison')
const file = edjison.import({
path: '../file.json',
encoding: 'utf8'
})
file.write({ test: 'ok' }, (err) => {
if(err) throw err
})
Installation
npm i edjison
API
edjison.import(options)
This function allows you to import a .json file
var file = edjison.import({
path: '/dir/file.json',
encoding: 'utf8',
sync: true
})
Options
Type : Object
path
Type : String
\
Default : ''
The path of your .json file
sync
Type : Boolean
\
Default : false
When this option is set to true, the file will be read and written synchronously
encoding
Type : String
\
Default : utf8
The encoding of the file
file.read(callback)
This function allows you to read the contents of the file
file.read((data, err) => {
if(err) throw err
console.log(data)
})
The callback
is given the two arguments, (data, err)
file.write(obj, callback)
This function allows you to write to the file
const data = {
username: 'user',
email: 'example@gmail.com'
}
file.write(data, (err) => {
if(err) throw err
})
obj
Type : Object
The data to be written to the file
callback
Type : function
The callback
is given the one argument, (err)
. The callback
is optional
file.add(obj, callback)
This function allows you to add data to existing data
file.add({ country: 'FR' }, (err) => {
if(err) throw err
})
obj
Type : Object
The data to be added to the file
callback
Type : function
The callback
is given the one argument, (err)
. The callback
is optional
file.remove(keys, callback)
This function allows you to delete data
file.remove(['country', 'email'], (err) => {
if(err) throw err
})
keys
Type : Array
The keys to be deleted
callback
Type : function
The callback
is given the one argument, (err)
. The callback
is optional
file.deleteAll(callback)
This function deletes all data from the file
file.deleteAll((err) => {
if(err) throw err
})
The callback
is given the one argument, (err)
. The callback
is optional
License
MIT © Rebst