(
path: string,
data: Record<string, any>,
opts: writeJSONOpts = {},
)
| 70 | |
| 71 | type writeJSONOpts = { dir?: string; isRoot?: boolean }; |
| 72 | export const writeJSON = async ( |
| 73 | path: string, |
| 74 | data: Record<string, any>, |
| 75 | opts: writeJSONOpts = {}, |
| 76 | ) => { |
| 77 | const { isRoot = false } = opts; |
| 78 | const root = await chatRoot(); |
| 79 | let file = path; |
| 80 | |
| 81 | if (!isRoot) { |
| 82 | file = await join(root, path); |
| 83 | } |
| 84 | |
| 85 | if (isRoot && !(await exists(await dirname(file)))) { |
| 86 | await createDir(await dirname(file), { recursive: true }); |
| 87 | } |
| 88 | |
| 89 | await writeTextFile(file, JSON.stringify(data, null, 2)); |
| 90 | }; |
| 91 | |
| 92 | export const fmtDate = (date: any) => dayjs(date).format('YYYY-MM-DD HH:mm:ss'); |
| 93 |
no test coverage detected