@afoot/write-json
v0.1.3
Published
Parse and write json to the filesystem.
Downloads
20
Maintainers
Readme
write-json
A JSON file-writing package designed for NPM initializers and places where Node needs to write static files.
installation
install: npm i --D @afoot/write-json
import: import writeJson from '@afoot/write-json'
documentation
write-json takes the following params:
- filename |
string
name and extension of the file to be written - json |
Object
any valid JSON statement. Ideally object literals or arrays - config |
Object
configuration object (see below)
config object breakdown
{
errorCallback: null, // Calls if file write fails
willFormat: true, // Option to disable tab formatting
root: `(current working directory)`, // File path to write
writeOptions: {flag:'w'} // Node options object for `writeFile`
}
example
const obj = { name: 'test', version: '0.0.1' };
const filename = 'package.json';
writeJson(filename, obj);