mirror of
https://github.com/valitydev/wazuh-kibana-app.git
synced 2024-11-08 02:38:51 +00:00
21 lines
735 B
JavaScript
21 lines
735 B
JavaScript
const replacer = (match, pIndent, pKey, pVal, pEnd) => {
|
|
let key = '<span class=json-key>';
|
|
let val = '<span class=json-value>';
|
|
let str = '<span class=json-string>';
|
|
let r = pIndent || '';
|
|
if (pKey) r = r + key + pKey.replace(/[": ]/g, '') + '</span>: ';
|
|
if (pVal) r = r + (pVal[0] == '"' ? str : val) + pVal + '</span>';
|
|
return r + (pEnd || '');
|
|
};
|
|
const prettyPrint = obj => {
|
|
let jsonLine = /^( *)("[\w]+": )?("[^"]*"|[\w.+-]*)?([,[{])?$/gm;
|
|
return JSON.stringify(obj, null, 3)
|
|
.replace(/&/g, '&')
|
|
.replace(/\\"/g, '"')
|
|
.replace(/</g, '<')
|
|
.replace(/>/g, '>')
|
|
.replace(jsonLine, replacer);
|
|
};
|
|
|
|
module.exports = { replacer, prettyPrint };
|