From 88b6d0607a6ef35c8d49627b2208ea72b183782b Mon Sep 17 00:00:00 2001 From: Kir_Antipov Date: Wed, 25 Jan 2023 17:36:00 +0000 Subject: [PATCH] Made a few utility types for `readFile` options --- src/utils/io/read-file-options.ts | 32 +++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/utils/io/read-file-options.ts diff --git a/src/utils/io/read-file-options.ts b/src/utils/io/read-file-options.ts new file mode 100644 index 0000000..eb04f04 --- /dev/null +++ b/src/utils/io/read-file-options.ts @@ -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[1]; + +/** + * Options that can be used with `fs.readFileSync()` to read a file synchronously. + */ +export type SyncReadFileOptions = Parameters[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; + +/** + * Object-style options that can be used with `fs.readFileSync()` to read a file synchronously. + */ +export type SyncReadFileOptionsObject = Exclude; + +/** + * All possible object-style options that can be passed to `fs.readFile()` and `fs.readFileSync()`. + */ +export type ReadFileOptionsObject = AsyncReadFileOptionsObject | SyncReadFileOptionsObject;