@studio/log
Advanced tools
+10
-0
| # Changes | ||
| ## 1.0.5 | ||
| Fixes and improvements for the fancy format transform. | ||
| - 🐛 Escape all non-printable characters. Print escape sequences, if available, | ||
| and fall back to hex values. Do not escape emoji‼️ | ||
| - 🐛 Escape newlines and tabs in strings (Fixes #3) | ||
| - 🐛 Format empty objects as `{}` without blanks (Fixes #1) | ||
| - 🐛 Format primitive data values (Fixes #4) | ||
| ## 1.0.4 | ||
@@ -4,0 +14,0 @@ |
+12
-8
@@ -53,11 +53,15 @@ /* | ||
| if (data && entry.data) { | ||
| for (const key in entry.data) { | ||
| if (entry.data.hasOwnProperty(key)) { | ||
| const value = entry.data[key]; | ||
| const kvu = value_format(key, value, JSON.stringify); | ||
| const k = kvu[0]; | ||
| const v = kvu[1]; | ||
| const unit = kvu[2]; | ||
| parts.push(k ? `${k}=${v}${unit}` : `${v}${unit}`); | ||
| if (typeof entry.data === 'object') { | ||
| for (const key in entry.data) { | ||
| if (entry.data.hasOwnProperty(key)) { | ||
| const value = entry.data[key]; | ||
| const kvu = value_format(key, value, JSON.stringify); | ||
| const k = kvu[0]; | ||
| const v = kvu[1]; | ||
| const unit = kvu[2]; | ||
| parts.push(k ? `${k}=${v}${unit}` : `${v}${unit}`); | ||
| } | ||
| } | ||
| } else { | ||
| parts.push(JSON.stringify(entry.data)); | ||
| } | ||
@@ -64,0 +68,0 @@ } |
+49
-11
@@ -13,2 +13,29 @@ /* | ||
| const non_printable_ecapes = { | ||
| 0: '\\0', | ||
| 7: '\\a', | ||
| 8: '\\b', | ||
| 9: '\\t', | ||
| 10: '\\n', | ||
| 11: '\\v', | ||
| 12: '\\f', | ||
| 13: '\\r', | ||
| 27: '\\e' | ||
| }; | ||
| function escapeNonPrintable(m) { | ||
| const code = m.charCodeAt(0); | ||
| if (code > 128) { | ||
| return m; | ||
| } | ||
| const escape = non_printable_ecapes[code]; | ||
| if (escape) { | ||
| return escape; | ||
| } | ||
| const hex = code.toString(16); | ||
| return hex.length === 1 | ||
| ? `\\x0${hex}` | ||
| : `\\x${hex}`; | ||
| } | ||
| function stringify(value) { | ||
@@ -20,3 +47,7 @@ if (value === null || value === undefined) { | ||
| if (type === 'string') { | ||
| return chalk.green(`'${value.replace(/'/g, '\\\'')}'`); | ||
| // https://en.wikipedia.org/wiki/ASCII#ASCII_printable_characters | ||
| const escaped = value | ||
| .replace(/'/g, '\\\'') | ||
| .replace(/[^\x20-\x7e]/g, escapeNonPrintable); | ||
| return chalk.green(`'${escaped}'`); | ||
| } | ||
@@ -37,3 +68,6 @@ if (type === 'number' || type === 'boolean') { | ||
| }).join(chalk.magenta(', ')); | ||
| return `${chalk.magenta('{')} ${values} ${chalk.magenta('}')}`; | ||
| if (values) { | ||
| return `${chalk.magenta('{')} ${values} ${chalk.magenta('}')}`; | ||
| } | ||
| return chalk.magenta('{}'); | ||
| } | ||
@@ -86,12 +120,16 @@ | ||
| if (data && entry.data) { | ||
| for (const key in entry.data) { | ||
| if (entry.data.hasOwnProperty(key)) { | ||
| const value = entry.data[key]; | ||
| const kvu = value_format(key, value, stringify); | ||
| const k = kvu[0]; | ||
| const v = kvu[1]; | ||
| const unit = kvu[2]; | ||
| const highlighted = unit ? `${chalk.yellow(v)}${unit}` : v; | ||
| parts.push(k ? `${chalk.bold(k)}=${highlighted}` : highlighted); | ||
| if (typeof entry.data === 'object') { | ||
| for (const key in entry.data) { | ||
| if (entry.data.hasOwnProperty(key)) { | ||
| const value = entry.data[key]; | ||
| const kvu = value_format(key, value, stringify); | ||
| const k = kvu[0]; | ||
| const v = kvu[1]; | ||
| const unit = kvu[2]; | ||
| const highlighted = unit ? `${chalk.yellow(v)}${unit}` : v; | ||
| parts.push(k ? `${chalk.bold(k)}=${highlighted}` : highlighted); | ||
| } | ||
| } | ||
| } else { | ||
| parts.push(stringify(entry.data)); | ||
| } | ||
@@ -98,0 +136,0 @@ } |
+2
-2
| { | ||
| "name": "@studio/log", | ||
| "version": "1.0.4", | ||
| "version": "1.0.5", | ||
| "description": "A tiny JSON logger with emoji support", | ||
@@ -37,3 +37,3 @@ "bin": { | ||
| "mocha": "^3.2.0", | ||
| "sinon": "^1.17.7" | ||
| "sinon": "^2.1.0" | ||
| }, | ||
@@ -40,0 +40,0 @@ "repository": { |
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
19286
7.2%447
9.83%