Spaces:
Running
Running
File size: 470 Bytes
3d4392e 3b780fb 3d4392e |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
import YAML from "yaml"
export function parseRawStringToYAML<T>(input: any, defaultValue: T) {
try {
let rawString = `${input || ""}`.trim()
rawString = rawString
.replaceAll("```yaml\n", "")
.replaceAll("```yaml", "")
// we remove everything after the last ``` (or ``)
rawString = rawString.split(/```?/)[0].trim()
const something: any = YAML.parse(rawString)
return something as T
} catch (err) {
return defaultValue
}
} |