import JSON5 from "json5"; import yaml from "js-yaml"; export const SupportedLanguages = [ { name: "json", readable: "JSON" }, { name: "json5", readable: "JSON5" }, { name: "yaml", readable: "YAML" }, ]; export const LanguagePrismBlockMap: Record = { json: "json", json5: "json5", yaml: "yaml", }; export function toPrismCode(syntax: string): string { return LanguagePrismBlockMap[syntax]; } export function parseData(data: string, syntax = "json"): Record { if (syntax == "json") { return JSON.parse(data) as Record; } else if (syntax == "json5") { return JSON5.parse(data); } else if (syntax == "yaml") { return yaml.load(data) as Record; } } export function dumpData(data: Record, space = 4, syntax = "json"): string { if (syntax == "json") { return JSON.stringify(data, null, space); } else if (syntax == "json5") { return JSON5.stringify(data, null, space); } else if (syntax == "yaml") { return yaml.dump(data, { indent: space, quotingType: "\"", forceQuotes: true }); } }