Appearance
file
Namespaces
Functions
access()
ts
function access(path): Promise<unknown>;Defined in: src/node/file/base.ts:37
Checks whether a file is readable (exists and has read permission).
Parameters
| Parameter | Type | Description |
|---|---|---|
path | string | File path to check. |
Returns
Promise<unknown>
Promise resolved with true if readable, false otherwise.
Example
ts
const readable = await access('./data.json'); // => true or falsemakeDir()
ts
function makeDir(path): Promise<void>;Defined in: src/node/file/base.ts:53
Creates a directory recursively (like mkdir -p).
Parameters
| Parameter | Type | Description |
|---|---|---|
path | string | Directory path to create. |
Returns
Promise<void>
Promise resolved when the directory is created.
Example
ts
await makeDir('./output/reports');read()
ts
function read(path, options?): Promise<any>;Defined in: src/node/file/base.ts:99
Reads a file and resolves with its content.
Parameters
| Parameter | Type | Default value | Description |
|---|---|---|---|
path | string | undefined | File path to read. |
options | | BufferEncoding | { encoding?: null; flag?: string; signal?: AbortSignal; } | "utf8" | Encoding or fs.readFile options (default: 'utf8'). |
Returns
Promise<any>
Promise resolved with the file content.
Example
ts
const content = await read('./data.json'); // => '{"a":1}'readDir()
ts
function readDir(path): Promise<unknown>;Defined in: src/node/file/base.ts:122
Lists files in a directory.
Parameters
| Parameter | Type | Description |
|---|---|---|
path | string | Directory path to list. |
Returns
Promise<unknown>
Promise resolved with an array of file names.
Example
ts
const files = await readDir('./src'); // => ['index.ts', 'utils.ts', ...]write()
ts
function write(
path,
data,
options?): Promise<void>;Defined in: src/node/file/base.ts:73
Writes data to a file, creating parent directories as needed.
Parameters
| Parameter | Type | Description |
|---|---|---|
path | string | Destination file path. |
data | string | ArrayBufferView<ArrayBufferLike> | Data to write. |
options | WriteFileOptions | Optional fs.writeFile options. |
Returns
Promise<void>
Promise resolved when the write is complete.
Example
ts
await write('./output/result.json', JSON.stringify(data));