MCPcopy Index your code
hub / github.com/NsLearning/LangHelper / writeJSON

Function writeJSON

ChatGPT/src/utils.ts:72–90  ·  view source on GitHub ↗
(
  path: string,
  data: Record<string, any>,
  opts: writeJSONOpts = {},
)

Source from the content-addressed store, hash-verified

70
71type writeJSONOpts = { dir?: string; isRoot?: boolean };
72export 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
92export const fmtDate = (date: any) => dayjs(date).format('YYYY-MM-DD HH:mm:ss');
93

Callers 4

modelSetFunction · 0.90
modelCacheSetFunction · 0.90
modelCacheCmdFunction · 0.90
updateJsonFunction · 0.90

Calls 2

chatRootFunction · 0.85
existsFunction · 0.85

Tested by

no test coverage detected