Détail du package

write-json-safe

bconnorwhite18.6kMIT4.0.0

Write formatted JSON to a file

write, file, json, safe

readme

write-json-safe

NPM TypeScript Coverage Status


Write formatted JSON to a file.


If I should maintain this repo, please ⭐️ GitHub stars

DM me on Twitter if you have questions or suggestions. Twitter


Installation

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

Usage

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

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

function writeJSONSync(path: string, content?: OptionalJSONValue, 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 Dependencies

  • @types/mock-fs: TypeScript definitions for mock-fs
  • autorepo: Autorepo abstracts away your dev dependencies, providing a single command to run all of your scripts.
  • mock-fs: A configurable mock file system. You know, for testing.
  • read-file-safe: Read files without try catch


License license

MIT


Related Packages

changelog

4.0.0 (2023-01-24)

3.0.0 (2023-01-18)

2.1.0 (2021-04-13)

Features

2.0.2 (2021-04-06)

Bug Fixes

  • dependency bump - preserve order for concurrent writes (c6db987)

2.0.1 (2020-10-04)

2.0.0 (2020-10-04)

Features

BREAKING CHANGES

  • new options format

1.0.1 (2020-09-03)