X-Git-Url: https://git.squeep.com/?p=squeep-logger-json-console;a=blobdiff_plain;f=lib%2Fjson-replacers.js;fp=lib%2Fjson-replacers.js;h=51eacb3cb5f2c8a259ce0bf55496ec64391fbb79;hp=2160ad8635af71f9aed3fbd169c02cd17df71849;hb=8f067f063e2410dd72bcd51aee69b273b1915c25;hpb=9d6fc078e27013cbb94836d7a9c3a39ba30d216b diff --git a/lib/json-replacers.js b/lib/json-replacers.js index 2160ad8..51eacb3 100644 --- a/lib/json-replacers.js +++ b/lib/json-replacers.js @@ -4,51 +4,21 @@ * Here are some replacers for rendering peculiar entities as JSON suitable for logging. */ -const http = require('http'); - -/** - * @typedef {Object} ReplacerResult - * @property {Boolean} replaced - * @property {*} value - */ - - -/** - * template for replacers - * @param {String} _key - * @param {*} value - * @returns {ReplacerResult} - */ -/* istanbul ignore next */ -function _replacer(_key, value) { - let replaced = false; - - if (undefined) { // eslint-disable-line no-constant-condition - replaced = true; - - const newValue = Object.assign({}, value); - - value = newValue; - } - return { replaced, value }; -} - +const http = require('node:http'); /** * Convert any Error to a plain Object. * @param {String} _key * @param {*} value - * @returns {ReplacerResult} + * @returns {Object} */ function replacerError(_key, value) { - let replaced = false; if (value instanceof Error) { - replaced = true; const newValue = {}; Object.getOwnPropertyNames(value).forEach((propertyName) => newValue[propertyName] = value[propertyName]); // eslint-disable-line security/detect-object-injection value = newValue; } - return { replaced, value }; + return value; } @@ -56,15 +26,13 @@ function replacerError(_key, value) { * Convert any BigInt type to a String. * @param {String} _key * @param {*} value - * @returns {ReplacerResult} + * @returns {String} */ function replacerBigInt(_key, value) { - let replaced = false; if (typeof value === 'bigint') { - replaced = true; value = value.toString(); } - return { replaced, value }; + return value; } @@ -75,12 +43,10 @@ function replacerBigInt(_key, value) { * this object. * @param {String} _key * @param {*} value - * @returns {ReplacerResult} + * @returns {Object} */ function replacerHttpIncomingMessage(_key, value) { - let replaced = false; if (value instanceof http.IncomingMessage) { - replaced = true; const newValue = {}; [ 'method', @@ -102,7 +68,7 @@ function replacerHttpIncomingMessage(_key, value) { } value = newValue; } - return { replaced, value }; + return value; } @@ -110,21 +76,19 @@ function replacerHttpIncomingMessage(_key, value) { * Convert any ServerResponse or OutgoingMessage to a subset Object. * @param {String} _key * @param {*} value - * @returns {ReplacerResult} + * @returns {Object} */ function replacerHttpServerResponse(_key, value) { - let replaced = false; if (value instanceof http.OutgoingMessage || value instanceof http.ServerResponse) { - replaced = true; const newValue = {}; [ 'statusCode', 'statusMessage', - ].forEach((property) => newValue[property] = value[property]); // eslint-disable-line security/detect-object-injection + ].forEach((property) => newValue[property] = value[property]); // eslint-disable-line security/detect-object-injection newValue.headers = value.getHeaders(); value = newValue; } - return { replaced, value }; + return value; }