write-json-safe
v4.0.0
Published
Write formatted JSON to a file
Downloads
5,678
Maintainers
Readme
If I should maintain this repo, please ⭐️
DM me on Twitter if you have questions or suggestions.
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;
};
- stringify-json-object: Stringify and format a JSON object
- write-file-safe: Write files atomically, and create parent directories if necessary
- @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
Related Packages
- types-json: Type checking for JSON values
- fs-safe: A simple fs wrapper that doesn't throw
- read-json-safe: Read JSON files without try catch
- write-file-safe: Write files, and create parent directories if necessary
- write-md-safe: Write markdown files from a Marked token list or string