MCPcopy Index your code
hub / github.com/mhart/react-server-example / safeStringify

Function safeStringify

server.js:120–126  ·  view source on GitHub ↗
(obj)

Source from the content-addressed store, hash-verified

118
119// A utility function to safely escape JSON for embedding in a <script> tag
120function safeStringify(obj) {
121 return JSON.stringify(obj)
122 .replace(/<\/(script)/ig, '<\\/$1')
123 .replace(/<!--/g, '<\\!--')
124 .replace(/\u2028/g, '\\u2028') // Only necessary if interpreting as JS, which we do
125 .replace(/\u2029/g, '\\u2029') // Ditto
126}

Callers 1

server.jsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected