-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
51 lines (41 loc) · 1.19 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
'use strict';
const Delver = require( 'delver' );
const extend = require( 'extend' );
const fs = require( 'fs' );
const util = require( 'util' );
const async_write_file = util.promisify( fs.writeFile );
const Boxcutter = {
read: function( json ) {
this.__obj = JSON.parse( json );
return this;
},
load: function( filename ) {
this.__obj = extend( true, {}, require( filename ) );
return this;
},
save: async function( filename, options ) {
const output = this.serialize( options );
await async_write_file( filename, output );
return this;
},
get: function( key ) {
this.__obj = this.__obj || {};
return Delver.get( this.__obj, key );
},
set: function( key, value ) {
this.__obj = this.__obj || {};
return Delver.set( this.__obj, key, value );
},
serialize: function( _options ) {
const options = extend( true, {
replacer: null,
index: 4
}, _options );
return JSON.stringify( this.__obj, options.replacer, options.indent );
}
};
module.exports = {
create: () => {
return Object.assign( {}, Boxcutter );
}
};