fs-json-writer
Generate JSON file content readable by a human
The native solution fs.writeFile combined with JSON.stringify generate a minified content because JSON.stringify is designed for data transfer.
This package full rewrite a JavaScript Object Notation with resolve tabulation depth and resolve nested object/array.
installation
in depending your need you can install at dev-dependencies
> npm install --save fs-json-writer
or with yarn
> yarn add fs-json-writer
usage
json file
const jsonWriter = ;const path = ; const myHumanJson = version: "1.0.0" details: "this is a stable version with goodly peoples ^.^"; ;
output (filename.json)
This encoding use is always UTF-8 for write a JSON content
and path
argument should be a absolute path
js file
const jsonWriter = ;const path = ; const myHumanJson = version: "1.0.0" details: "this is a stable version with goodly peoples ^.^"; ;
extension of filename determined if content should be JS or JSON file.
output (filename.js)
version: "1.0.0" details: "this is a stable version with goodly peoples ^.^"
async
Can asynchrone generate content with Promise API or inehrit from natively fs module callback system.
Promise
const jsonWriter = ;const path = ; const myHumanJson = version: "1.0.0" details: "this is a stable version with goodly peoples ^.^"; jsonWriter;
Callback
const jsonWriter = ;const path = ; const myHumanJson = version: "1.0.0" details: "this is a stable version with goodly peoples ^.^"; jsonWriter;
optionals
From a syn/async call can define optionals attributes: onReplace: () => any | string[] | number[]
, space: string | number
this attributes is passed to arg2 and arg3 of JSON.stringify
Please if you detect any bugs/undetermined comportement open new issue