UseReadModuleFile
katanakit-js / useReadModuleFile
Function: useReadModuleFile()
Section titled “Function: useReadModuleFile()”function useReadModuleFile( importMetaUrl, relativePath, encoding?): Promise<FilesystemResult<string>>;Defined in: infrastructure/filesystem/filesystem.service.ts:530
Reads a file resolved from the caller’s module directory — the
__dirname + relative path pattern, without __dirname.
Parameters
Section titled “Parameters”| Parameter | Type | Default value | Description |
|---|---|---|---|
importMetaUrl |
string |
undefined |
Your module’s import.meta.url. |
relativePath |
string |
undefined |
Path relative to that module (e.g. "../data/books.json"). |
encoding? |
| "utf-8" | "utf8" | "ascii" | "base64" | "base64url" | "hex" | "latin1" | "binary" | "ucs2" | "ucs-2" | "utf16le" | "utf-16le" |
"utf8" |
Text encoding (default: "utf8"). |
Returns
Section titled “Returns”Promise<FilesystemResult<string>>
Safe Result with the file contents as a string.
Example
Section titled “Example”const css = await useReadModuleFile(import.meta.url, "./theme.css");