Skip to content

fundamentool


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

ParameterTypeDescription
pathstringFile path to check.

Returns

Promise<unknown>

Promise resolved with true if readable, false otherwise.

Example

ts
const readable = await access('./data.json'); // => true or false

makeDir()

ts
function makeDir(path): Promise<void>;

Defined in: src/node/file/base.ts:53

Creates a directory recursively (like mkdir -p).

Parameters

ParameterTypeDescription
pathstringDirectory 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

ParameterTypeDefault valueDescription
pathstringundefinedFile 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

ParameterTypeDescription
pathstringDirectory 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

ParameterTypeDescription
pathstringDestination file path.
datastring | ArrayBufferView<ArrayBufferLike>Data to write.
optionsWriteFileOptionsOptional fs.writeFile options.

Returns

Promise<void>

Promise resolved when the write is complete.

Example

ts
await write('./output/result.json', JSON.stringify(data));

MIT License