Made a few utility types for readFile options

This commit is contained in:
Kir_Antipov 2023-01-25 17:36:00 +00:00
parent 49ccf5b5a2
commit 88b6d0607a

View file

@ -0,0 +1,32 @@
import { readFileSync } from "node:fs";
import { readFile } from "node:fs/promises";
/**
* Options that can be used with `fs.readFile()` to read a file asynchronously.
*/
export type AsyncReadFileOptions = Parameters<typeof readFile>[1];
/**
* Options that can be used with `fs.readFileSync()` to read a file synchronously.
*/
export type SyncReadFileOptions = Parameters<typeof readFileSync>[1];
/**
* All possible options that can be passed to `fs.readFile()` and `fs.readFileSync()`.
*/
export type ReadFileOptions = AsyncReadFileOptions | SyncReadFileOptions;
/**
* Object-style options that can be used with `fs.readFile()` to read a file asynchronously.
*/
export type AsyncReadFileOptionsObject = Exclude<AsyncReadFileOptions, string>;
/**
* Object-style options that can be used with `fs.readFileSync()` to read a file synchronously.
*/
export type SyncReadFileOptionsObject = Exclude<SyncReadFileOptions, string>;
/**
* All possible object-style options that can be passed to `fs.readFile()` and `fs.readFileSync()`.
*/
export type ReadFileOptionsObject = AsyncReadFileOptionsObject | SyncReadFileOptionsObject;