Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | 1x 1x 1x 2x 2x 2x 2x 2x 2x 1x 6x 6x 6x | const jsonCommentDelimiter = "\n//EMBEDDED_JSON\n"
// Stringifies JSON for placing into an arbitrary doc, for later extraction without parsing the whole doc
export const serializeJSONForHTML = (
obj: any,
delimiter = jsonCommentDelimiter
): string =>
`${delimiter}${
obj === undefined ? "" : JSON.stringify(obj, null, 2)
}${delimiter}`
export const deserializeJSONFromHTML = (
html: string,
delimiter = jsonCommentDelimiter
): any => {
const json = html.split(delimiter)[1]
return json === undefined || json === "" ? undefined : JSON.parse(json)
}
|