@haxtra/live-object
v0.9.0
Published
Standard javascript object with built-in JSON serialization to file
Downloads
2
Maintainers
Readme
live-object
Standard javascript object with built-in JSON serialization to file. Dreams do come true sometimes.
Install
npm i @haxtra/live-object
Usage
const liveObject = require('live-object')
const obj = liveObject('/path/to/file')
obj.foo = 'bar'
obj.save()
$ cat /path/to/file
> {"foo":"bar"}
API
obj = liveObject(filePath, default?, opts?)
// filePath - (str) json file path, to load and save (required)
// default - (obj) used when file at path is not found
// opts.reset - (bool) ignore file even if it exists, force default
obj.save(filePath?, pretty?)
// filePath - (str) alternative file to save to, used for this save only
// does not change/update path given at creation time
// pretty - (bool) save formatted json, with proper indentation
Rules
- read/write uses sync api
save
key is reservedJSON.stringify
rules apply, see docs
License
MIT