write-json-safe
TypeScript icon, indicating that this package has built-in type declarations

4.0.0 • Public • Published

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

Package Sidebar

Install

npm i write-json-safe

Weekly Downloads

824

Version

4.0.0

License

MIT

Unpacked Size

8.21 kB

Total Files

8

Last publish

Collaborators

  • bconnorwhite