From eb0f17bd9a7d3e8ddfe0c12c3dd6f52c895f3127 Mon Sep 17 00:00:00 2001 From: fofolee Date: Fri, 29 Apr 2022 23:17:31 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8E=BB=E6=8E=89=20beaufiLog?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugin/lib/beautifyLog.js | 45 --------------------------------------- 1 file changed, 45 deletions(-) delete mode 100644 plugin/lib/beautifyLog.js diff --git a/plugin/lib/beautifyLog.js b/plugin/lib/beautifyLog.js deleted file mode 100644 index 4115c05..0000000 --- a/plugin/lib/beautifyLog.js +++ /dev/null @@ -1,45 +0,0 @@ -let itemPropCaches = []; - -let parseEveryItem = item => { - if (typeof item === "undefined") return "undefined" - if (typeof item === "number") return item - if (typeof item !== "object") return item.toString() - if (Buffer.isBuffer(item)) { - var bufferString = `[Buffer ${item.slice(0, 50).toString('hex').match(/\w{1,2}/g).join(" ")}`; - if (item.length > 50) bufferString += `...${(item.length / 1000).toFixed(2)} kb `; - return bufferString + ']' - } - if (item instanceof ArrayBuffer) return `ArrayBuffer(${item.byteLength})`; - if (item instanceof Blob) return `BlobĀ { size: ${item.size}, type: "${item.type}" }`; - try { - var result = item.constructor(); - for (const key in item) { - if (typeof item[key] === 'function') result[key] = liteFuntcion(item[key]) - else if (typeof item[key] === 'object') { - if (itemPropCaches.includes(item[key])) result[key] = `[Circular]` - else { - itemPropCaches.push(item[key]); - result[key] = parseEveryItem(item[key]) - } - } else { - result[key] = item[key] || 'undefined' - } - } - itemPropCaches = [] - return result - } catch (error) { - console.log(error); - return item.toString() - } -} - -let liteFuntcion = fn => { - return `[Function: ${fn.name ? fn.name : '(anonymous)'}]` -} - -let beautifyLog = item => { - let result = parseEveryItem(item) - return typeof result === 'object' ? JSON.stringify(result, null, 2) : result -} - -module.exports = beautifyLog;