MCPcopy
hub / github.com/webpack/webpack / stringifySafe

Function stringifySafe

lib/json/JsonGenerator.js:35–44  ·  view source on GitHub ↗
(data)

Source from the content-addressed store, hash-verified

33 * @returns {undefined | string} stringified data
34 */
35const stringifySafe = (data) => {
36 const stringified = JSON.stringify(data);
37 if (!stringified) {
38 return; // Invalid JSON
39 }
40
41 return stringified.replace(/\u2028|\u2029/g, (str) =>
42 str === "\u2029" ? "\\u2029" : "\\u2028"
43 ); // invalid in JavaScript but valid JSON
44};
45
46/**
47 * Creates an object for exports info.

Callers 2

getSizeMethod · 0.85
generateMethod · 0.85

Calls 1

replaceMethod · 0.45

Tested by

no test coverage detected