UNPKG

@toolpad/utils

Version:

Shared utilities used by Toolpad packages.

19 lines 1.25 kB
import * as fs from 'fs/promises'; import { Dirent } from 'fs'; export type Reviver = NonNullable<Parameters<typeof JSON.parse>[1]>; /** * Like `fs.readFile`, but for JSON files specifically. Will throw on malformed JSON. */ export declare function readJsonFile(filePath: string, reviver?: Reviver): Promise<unknown>; export declare function readMaybeFile(filePath: string): Promise<string | null>; export declare function readMaybeDir(dirPath: string): Promise<Dirent[]>; export type WriteFileOptions = Parameters<typeof fs.writeFile>[2]; export declare function writeFileRecursive(filePath: string, content: string | Buffer, options?: WriteFileOptions): Promise<void>; export interface UpdateYamlOptions { schemaUrl?: string; } export declare function updateYamlFile(filePath: string, content: object, options?: UpdateYamlOptions): Promise<void>; export declare function fileExists(filepath: string): Promise<boolean>; export declare function folderExists(folderpath: string): Promise<boolean>; export declare function fileReplace(filePath: string, searchValue: string | RegExp, replaceValue: string): Promise<void>; export declare function fileReplaceAll(filePath: string, searchValue: string | RegExp, replaceValue: string): Promise<void>;