README
Write files atomically and create parent directories if necessary.
Installation
yarn add write-file-safe
npm install write-file-safe
API
import { writeFile, writeFileSync, Options } from "write-file-safe";
function writeFile(path: string, content?: string | Buffer): Promise<boolean>;
function writeFileSync(path: string, content?: string | Buffer): boolean;
type Options = {
/**
* Recursively create parent directories if needed. Default: `true`
*/
recursive?: boolean;
/**
* Ensure file ends with a newline. Default: `true`
*/
appendNewline?: boolean;
}
Dependencies
- file-exists-safe: Check if a file exists without try catch
- remove-file-safe: Remove files without try catch
- terminating-newline: Add or remove a terminating newline
- write-dir-safe: Create directories and their parents recursively
Dev Dependencies
- @bconnorwhite/bob: Bob is a toolkit for TypeScript projects
- @types/mock-fs: TypeScript definitions for mock-fs
- @types/node: TypeScript definitions for Node.js
- mock-fs: A configurable mock file system. You know, for testing.
License
Related Packages
- fs-safe: A simple fs wrapper that doesn't throw
- read-file-safe: Read files without try catch
- remove-file-safe: Remove files without try catch
- read-dir-safe: Read directories recursively or non-recursively
- remove-dir-safe: Remove directories recursively or non-recursively
- write-dir-safe: Create directories and their parents recursively