app/lib/json-ld.mjs
23 lines and 1 functions in DrDustinEdwards/dustinedwards-info, at commit 1590ba4 on 2026-10-24. This file on GitHub.
Functions
| Function | Lines | Complexity | Covered | CRAP | Mutation |
|---|---|---|---|---|---|
| jsonLd | 16 to 25 | 1 | 100% | OkCRAP 1 | Ok100% |
Imports
It imports no other module of this repo. Imported by app/components/taxonomy-listing.tsx, app/lib/speculation.mjs, app/routes/about.tsx, app/routes/blog.$slug.tsx, app/routes/blog._index.tsx, app/routes/content-page.tsx, app/routes/cv.tsx, app/routes/home.tsx, app/routes/kb-library.tsx, app/routes/lab.kind.tsx, app/routes/lab.tsx, app/routes/phages.tsx, app/routes/procedure.tsx, app/routes/procedure.version.tsx, app/routes/protocols.tsx, app/routes/publications.$slug.tsx, app/routes/publications.tsx, app/routes/systems.tsx.
Source
/**
* `<script>` contents are raw text ended only by a literal `</script`, so a
* value containing it would close the element early. U+2028/9 are escaped
* because they are line terminators if this is ever read as JavaScript.
* The escapes parse back to identical data, so they are safe on every emitter.
*/
// Built from strings: a literal U+2028 is invisible and does not survive a copy.
const LINE_SEPARATOR = new RegExp("\\u2028", "g");
const PARAGRAPH_SEPARATOR = new RegExp("\\u2029", "g");
/**
* @param {unknown} value
* @returns {string}
*/
export function jsonLd(value) {
return (
JSON.stringify(value)
.replace(/</g, "\\u003c")
.replace(/>/g, "\\u003e")
.replace(/&/g, "\\u0026")
.replace(LINE_SEPARATOR, "\\u2028")
.replace(PARAGRAPH_SEPARATOR, "\\u2029")
);
}