Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

write-json5-file

zkochan5.9kMIT3.1.0TypeScript support: included

Stringify and write JSON to a file atomically

write, json5, stringify, file, fs, graceful, atomic, atomically

readme

write-json5-file

Stringify and write JSON to a file atomically

npm version

Installation

<npm|yarn|pnpm> add write-json5-file

Usage

const writeJson5File = require('write-json5-file')

writeJson5File('foo.json5', {foo: true}).then(() => {
    console.log('done')
})

API

writeJson5File(filepath, data, [options])

Returns a promise.

writeJson5File.sync(filepath, data, [options])

options

indent

Type: string, number Default: \t

Indentation as a string or number of spaces. Pass in null for no formatting.

sortKeys

Type: boolean, function Default: false

Sort the keys recursively. Optionally pass in a compare function.

replacer

Type: function

Passed into JSON.stringify.

mode

Type: number Default 438 (0666 in octal)

Mode used when writing the file.

License

MIT © Zoltan Kochan

changelog

write-json5-file

3.1.0

Minor Changes

  • bba9985: graceful-fs and mz removed from dependencies.

3.0.1

Patch Changes

  • 0a21c77: Update write-file-atomic to v3.

3.0.0

Major Changes

  • 674dc01: Use native fs.mkdir instead of make-dir.

    BREAKING CHANGE:

    Node.js 8 support is dropped.