UNPKG

1.93 kBMarkdownView Raw
1# Installation
2> `npm install --save @types/write`
3
4# Summary
5This package contains type definitions for write (https://github.com/jonschlinkert/write).
6
7# Details
8Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/write.
9## [index.d.ts](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/write/index.d.ts)
10````ts
11/// <reference types="node" />
12import * as fs from "fs";
13
14type Data = string | Buffer | Uint8Array;
15
16interface CommonOptions {
17 newline?: boolean | undefined;
18 overwrite?: boolean | undefined;
19 increment?: boolean | undefined;
20}
21
22type Options =
23 & Omit<fs.WriteFileOptions, "encoding">
24 & Omit<fs.MakeDirectoryOptions, "recursive">
25 & CommonOptions;
26
27type CreateWriteStreamOptions = Extract<Parameters<typeof fs.createWriteStream>[1], Record<string, any>>;
28
29type StreamOptions =
30 & Omit<CreateWriteStreamOptions, "encoding">
31 & Omit<fs.MakeDirectoryOptions, "recursive">
32 & CommonOptions;
33
34interface Result<T extends Data> {
35 path: string;
36 data: T;
37}
38
39type Callback<T extends Data> = (err: Error | null, result?: Result<T>) => any;
40
41declare function write<T extends Data>(filepath: string, data: T, options: Options, callback: Callback<T>): void;
42declare function write<T extends Data>(filepath: string, data: T, callback: Callback<T>): void;
43declare function write<T extends Data>(filepath: string, data: T, options?: Options): Promise<Result<T>>;
44
45declare namespace write {
46 function sync<T extends Data>(filepath: string, data: T, options?: Options): Result<T>;
47
48 function stream(filepath: string, options?: StreamOptions): fs.WriteStream;
49}
50
51export = write;
52
53````
54
55### Additional Details
56 * Last updated: Tue, 07 Nov 2023 15:11:36 GMT
57 * Dependencies: [@types/node](https://npmjs.com/package/@types/node)
58
59# Credits
60These definitions were written by [Junxiao Shi](https://github.com/yoursunny).
61
\No newline at end of file