summaryrefslogtreecommitdiffstats
path: root/src/renderer/editor/util.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/renderer/editor/util.ts')
-rw-r--r--src/renderer/editor/util.ts9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/renderer/editor/util.ts b/src/renderer/editor/util.ts
index b2331bb..f816de4 100644
--- a/src/renderer/editor/util.ts
+++ b/src/renderer/editor/util.ts
@@ -25,7 +25,12 @@ export function usePromise<T>(f: () => Promise<T>): T | null {
return value;
}
-export function useReadFile(path: string, encoding: BufferEncoding): string | null {
- const readFile = useCallback(() => fs.promises.readFile(path, encoding), [path, encoding]);
+export function useReadFile(path: string): Buffer | null {
+ const readFile = useCallback(() => fs.promises.readFile(path), [path]);
return usePromise(readFile);
}
+
+export async function readJSON(path: string): Promise<unknown> {
+ const content = await fs.promises.readFile(path, 'utf8');
+ return JSON.parse(content);
+}