sys-prettier-json
Version:
Format JSON with beautiful color
28 lines (24 loc) • 1.16 kB
JavaScript
function $parcel$export(e, n, v, s) {
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
}
$parcel$export(module.exports, "prettyJson", () => $882b6d93070905b3$export$dc6b347ec945e6af);
const $882b6d93070905b3$var$colorOptions = {
jsonNumber: "#0CBB52",
jsonKey: "#EB2013",
jsonValue: "#097BED",
jsonBoolean: "blue",
jsonNull: "magenta"
};
const $882b6d93070905b3$export$dc6b347ec945e6af = (json, options = $882b6d93070905b3$var$colorOptions)=>{
json = json.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
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>`;
});
};
//# sourceMappingURL=main.js.map