0.9.0 • Published 1 year ago

@haxtra/live-object v0.9.0

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

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 reserved
  • JSON.stringify rules apply, see docs

License

MIT