1.2.0 • Published 7 years ago

awesome-json v1.2.0

Weekly downloads
2
License
MIT
Repository
github
Last release
7 years ago

awesome-json

Build Status dependencies Status optionalDependencies Status

About

awesome-json is a simple system for reading JSON (plus BSON, YAML, ETF, and MsgPack) files, and automatically writing to the JSON (or BSON/YAML/ETF/MsgPack) file whenever the object is updated. awesome-json supports gzip compression as well.

Installation

npm install --save awesome-json

API

read(filename, options, callback)

Returns: Promise

options

  • fs: any fs module backwards compatible with fs
  • space: (JSON only) space argument accepted by JSON.stringify
  • encoder: a custom encoder to use while parsing and writing to the file
  • encoding: encoding to use while reading the file
  • writeFrequency (default: 5000): the length of the interval to write changes in milliseconds, writes immediately if 0

Reads a JSON file, and watches for changes. Automatically appends .json if the file isn't found.

const json = require('awesome-json');

json.read('test', (err, contents) => {
  if (err) throw err;
  contents.baz = 1; // This change is automatically written to the file.
});

readSync(filename, options)

Returns: Object

options

  • fs: any fs module backwards compatible with fs
  • space: (JSON only) space argument accepted by JSON.stringify
  • encoder: a custom encoder to use while parsing and writing to the file
  • encoding: encoding to use while reading the file
  • writeFrequency (default: 5000): the length of the interval to write changes in milliseconds, writes immediately if 0

Reads a JSON file, and watches for changes. Automatically appends .json if the file isn't found.

const json = require('awesome-json');

const contents = json.readSync('test');

contents.baz = 1; // This change is automatically written to the file.