Dado un YAML como este:
--- body: "something else" path: site:^example\.com?"something"..."something" title: "How to do this" al analizarlo usando yaml-ast-parser , da como resultado un YAML no válido debido al punto en la expresión regular y las comillas. Puedo extraer el valor de path y comillas dobles con strconv.Quote y eso da como resultado un YAML final como este:
--- body: "something else" path: "site:^example\\.com?\"something\"...\"something\"" title: "How to do this" Sin embargo, strconv.Quote es un método golang y este es un proyecto javascript. ¿Alguien sabe una forma en que puedo lograr strconv.Quote en un entorno de javascript?
Para obtener algo similar a strconv.Quote , use JSON.stringify :
// Example value you got from the YAML: const path = String.raw`site:^example\.com?"something"..."something"`; console.log("before"); console.log(path); console.log("after"); console.log(JSON.stringify(path));