UNPKG

sys-prettier-json

Version:
24 lines (21 loc) 1 kB
const $149c1bd638913645$var$colorOptions = { jsonNumber: "#0CBB52", jsonKey: "#EB2013", jsonValue: "#097BED", jsonBoolean: "blue", jsonNull: "magenta" }; const $149c1bd638913645$export$dc6b347ec945e6af = (json, options = $149c1bd638913645$var$colorOptions)=>{ json = json.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;"); return json.replace(/("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+-]?\d+)?)/g, function(match) { let color = options.jsonNumber; if (/^"/.test(match)) { if (/:$/.test(match)) color = options.jsonKey; else color = options.jsonValue; } else if (/true|false/.test(match)) color = options.jsonBoolean; else if (/null/.test(match)) color = options.jsonNull; return `<span style="color: ${color}">${match}</span>`; }); }; export {$149c1bd638913645$export$dc6b347ec945e6af as prettyJson}; //# sourceMappingURL=module.js.map