Skip to content

haxtra/live-object

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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('@haxtra/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

About

Standard javascript object with built-in JSON serialization to file

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published