Skip to content

marmotte / utils/fs

utils/fs

Type Aliases

PathFilter

PathFilter = RegExp | ((path) => boolean)

Defined in: src/utils/fs.ts:5

Functions

dirExists()

dirExists(path): boolean

Defined in: src/utils/fs.ts:45

Returns true if path exists and is a directory.

Parameters

path

string

Returns

boolean


fileExists()

fileExists(path): boolean

Defined in: src/utils/fs.ts:50

Returns true if path exists and is a regular file.

Parameters

path

string

Returns

boolean


moduleExists()

moduleExists(path): boolean

Defined in: src/utils/fs.ts:67

Returns true if path resolves to a TypeScript module — either:

  • a directory containing an index.ts, or
  • a <path>.ts file.

Parameters

path

string

Returns

boolean


resolveEntries()

resolveEntries(sourceDir, filter): Promise<Record<string, string>>

Defined in: src/utils/fs.ts:35

Walks sourceDir recursively and returns a Rollup-compatible entry map ({ [name]: absolutePath }) for every file matched by filter. The entry name is the file path relative to sourceDir, without its extension.

Parameters

sourceDir

string

filter

PathFilter

Returns

Promise<Record<string, string>>

Example

ts
// { "index": "/abs/src/index.ts", "utils/foo": "/abs/src/utils/foo.ts" }
await resolveEntries("/abs/src", /\.ts$/)

safeWrite()

safeWrite(path, content): Promise<void>

Defined in: src/utils/fs.ts:57

Writes content to path, creating parent directories as needed.

Parameters

path

string

content

string

Returns

Promise<void>


walk()

walk(dir, filter?): AsyncGenerator<string>

Defined in: src/utils/fs.ts:17

Recursively iterates over a directory (and its subdirectories) files

Parameters

dir

string

filter?

PathFilter

Returns

AsyncGenerator<string>