without any libs:
Code:
import { readFileSync } from "node:fs";
export function luaToJson(content: string): any {
content = content.substring(content.indexOf("\r\n") + 2);
content = content.replace(/\[\"?([\w\$]+)\"?\] = /g, '"$1": ');
content = content.replace(/,(\r\n\s*})/gm, "$1");
return JSON.parse(content);
}
export function readSavedVariablesFile(path: string): any {
return luaToJson(readFileSync(path, "utf8"));
}