write-json-safe

Write formatted JSON to a file

Usage no npm install needed!

<script type="module">
  import writeJsonSafe from 'https://cdn.skypack.dev/write-json-safe';
</script>

README

write-json-safe

NPM TypeScript Coverage Status GitHub Stars Twitter Follow

Write formatted JSON to a file.

Installation

yarn add write-json-safe
npm install write-json-safe

API

import { writeJSON, writeJSONSync, Options, JSONObject } from "write-json-safe";

function writeJSON(path: string, content?: JSONObject, options?: Options): Promise<boolean>;

function writeJSONSync(path: string, content?: JSONObject, options?: Options): boolean;

type Options = {
  /**
   * Output formatted JSON. Default: `true`
   */
  pretty?: boolean;
  /**
   * Recursively create parent directories if needed. Default: `true`
   */
  recursive?: boolean;
  /**
   * Ensure file ends with a newline. Default: `true`
   */
  appendNewline?: boolean;
  /**
   * Write even if file already exists. Default: `true`
   */
  overwrite?: boolean;
}

Dependenciesdependencies


Dev DependenciesDavid


License license

MIT


Related Packages