From e784b0ef8099d714852c172d73d3e29184ad6e76 Mon Sep 17 00:00:00 2001 From: chagris <> Date: Wed, 12 Dec 2018 02:29:39 +0100 Subject: [PATCH 1/8] start implementing output formatting https://github.com/visionmedia/debug/issues/582 --- src/common.js | 6 +++ src/node.js | 107 ++++++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 100 insertions(+), 13 deletions(-) diff --git a/src/common.js b/src/common.js index 0b6d0b64..b39fc261 100644 --- a/src/common.js +++ b/src/common.js @@ -36,6 +36,11 @@ function setup(env) { */ createDebug.formatters = {}; + /** + * Map of formatting handling functions, for output formatting. + */ + createDebug.outputFormatters = {}; + /** * Selects a color for a debug namespace * @param {String} namespace The namespace string for the for the debug instance to be colored @@ -117,6 +122,7 @@ function setup(env) { debug.namespace = namespace; debug.enabled = createDebug.enabled(namespace); debug.useColors = createDebug.useColors(); + debug.format = createDebug.getFormat() || '%{H:M-Z} %n %m %+'; debug.color = selectColor(namespace); debug.destroy = destroy; debug.extend = extend; diff --git a/src/node.js b/src/node.js index 5e1f1541..70d53333 100644 --- a/src/node.js +++ b/src/node.js @@ -15,6 +15,7 @@ exports.formatArgs = formatArgs; exports.save = save; exports.load = load; exports.useColors = useColors; +exports.getFormat = getFormat; /** * Colors. @@ -137,7 +138,10 @@ exports.inspectOpts = Object.keys(process.env).filter(key => { } else if (val === 'null') { val = null; } else { - val = Number(val); + let asNumber = Number(val); + if (!isNaN(asNumber)) { + val = asNumber; + } } obj[prop] = val; @@ -154,6 +158,14 @@ function useColors() { tty.isatty(process.stderr.fd); } +/** + * Returns DEBUG_FORMAT if specified, or false otherwise + */ + +function getFormat() { + return 'format' in exports.inspectOpts && exports.inspectOpts.format; +} + /** * Adds ANSI color escape codes if enabled. * @@ -161,18 +173,35 @@ function useColors() { */ function formatArgs(args) { - const {namespace: name, useColors} = this; - - if (useColors) { - const c = this.color; - const colorCode = '\u001B[3' + (c < 8 ? c : '8;5;' + c); - const prefix = ` ${colorCode};1m${name} \u001B[0m`; - - args[0] = prefix + args[0].split('\n').join('\n' + prefix); - args.push(colorCode + 'm+' + module.exports.humanize(this.diff) + '\u001B[0m'); - } else { - args[0] = getDate() + name + ' ' + args[0]; - } + var formatted = this.format; + + // Apply any `outputFormatters` transformations + formatted = formatted.replace(/%(J?[a-zA-Z+]|J?\{.+\})/g, (match, format) => { + //%J* are passed to JSON.stringify + let stringify = false; + if (format.startsWith('J')) { + format = format.replace(/^J/, ''); + stringify = true; + } + + let formatter; + //not really sure how to handle time at this point + if (format.startsWith('{')) { + formatter = outputFormatters._time; + } else { + formatter = outputFormatters[format]; + } + if (typeof formatter === 'function') { + match = formatter.call(this, format, args); + if (stringify) { + match = JSON.stringify(match) + } + } + + return match; + }); + + args[0] = formatted; } function getDate() { @@ -255,3 +284,55 @@ formatters.O = function (v) { this.inspectOpts.colors = this.useColors; return util.inspect(v, this.inspectOpts); }; + +const { outputFormatters } = module.exports; + +/** + * Map %m to outputting message + */ + +outputFormatters.m = function(format, args) { + return args; +} + +/** + * Map %m to outputting diff + */ + +outputFormatters['+'] = function(format, args) { + const diff = 'm+' + module.exports.humanize(this.diff); + + if (this.useColors) { + const c = this.color; + const colorCode = '\u001B[3' + (c < 8 ? c : '8;5;' + c); + + return colorCode + diff + '\u001B[0m'; + } else { + return diff; + } +} + +/** + * Map %n to outputting namespace prefix + */ + +outputFormatters.n = function(format, args) { + if (this.useColors) { + const c = this.color; + const colorCode = '\u001B[3' + (c < 8 ? c : '8;5;' + c); + + return ` ${colorCode};1m${this.name} \u001B[0m`;; + } else { + return this.name; + } +} + + +/** + * Map %_time to handling time...? + */ + +outputFormatters._time = function(format, args) { + return getDate(); +} + From a612347ad2ff04bbd491dc7c17b5bd3fcb6f7e09 Mon Sep 17 00:00:00 2001 From: chagris <> Date: Wed, 12 Dec 2018 23:28:58 +0100 Subject: [PATCH 2/8] move formatting mostly into common.js --- src/common.js | 90 ++++++++++++++++++++++++++++++++++++++++++++--- src/node.js | 97 ++++----------------------------------------------- 2 files changed, 93 insertions(+), 94 deletions(-) diff --git a/src/common.js b/src/common.js index b39fc261..c57f5378 100644 --- a/src/common.js +++ b/src/common.js @@ -38,9 +38,53 @@ function setup(env) { /** * Map of formatting handling functions, for output formatting. + * m and _time are special hardcoded keys. */ createDebug.outputFormatters = {}; + /** + * Map %m to outputting diff + */ + + createDebug.outputFormatters.m = function(format, args) { + return args; + } + + /** + * Map %+ to outputting diff + */ + + createDebug.outputFormatters['+'] = function(format, args) { + const diff = '+' + createDebug.humanize(this.diff); + if (this.useColors) { + return this.applyColor(diff); + } else { + return diff; + } + } + + /** + * Map %n to outputting namespace prefix + */ + + createDebug.outputFormatters.n = function(format, args) { + if (this.useColors) { + return this.applyColor(this.name, true); + } else { + return this.name; + } + } + + /** + * Map %_time to handling time...? + */ + + createDebug.outputFormatters._time = function(format, args) { + //doesn't respect `exports.inspectOpts.hideDate` + //browser doesn't have date + return new Date().toISOString(); + } + /** * Selects a color for a debug namespace * @param {String} namespace The namespace string for the for the debug instance to be colored @@ -112,18 +156,56 @@ function setup(env) { return match; }); - // Apply env-specific formatting (colors, etc.) - createDebug.formatArgs.call(self, args); + // Apply relevant `outputFormatters` to `format` + let reg = /%(J?[a-zA-Z+]|J?\{.+\})/, formattedArgs = [], res; + let outputFormat = self.format; //make a copy of the format + while (res = outputFormat.match(reg)) { + let [matched, formatToken] = res, stringify = false, formatter, formatted; + //split out the part before the matched format token + let split = outputFormat.slice(0, res.index); + outputFormat = outputFormat.slice(res.index + matched.length); + + //and add it to the arguments + if (split.length > 0) { + formattedArgs.push(split); + } + + //%J* are passed to JSON.stringify + if (formatToken.startsWith('J')) { + formatToken = formatToken.replace(/^J/, ''); + stringify = true; + } + + //not really sure how to handle time at this point + if (formatToken.startsWith('{')) { + formatter = createDebug.outputFormatters._time; + } else { + formatter = createDebug.outputFormatters[formatToken]; + } + if (typeof formatter === 'function') { + formatted = formatter.call(self, formatToken, args); + if (stringify) { + formatted = JSON.stringify(formatted) + } + + if (Array.isArray(formatted)) { //intended to concatenate %m's args in the middle of the format + formattedArgs = formattedArgs.concat(formatted); + } else { + formattedArgs.push(formatted); + } + } + } const logFn = self.log || createDebug.log; - logFn.apply(self, args); + logFn.apply(self, formattedArgs); } debug.namespace = namespace; debug.enabled = createDebug.enabled(namespace); debug.useColors = createDebug.useColors(); - debug.format = createDebug.getFormat() || '%{H:M-Z} %n %m %+'; + debug.format = createDebug.getFormat() || '%{H:M-Z}%n%m%+'; //' %n%m%+' debug.color = selectColor(namespace); + debug.applyColor = createDebug.applyColor.bind(debug); debug.destroy = destroy; debug.extend = extend; // Debug.formatArgs = formatArgs; diff --git a/src/node.js b/src/node.js index 70d53333..5c23486b 100644 --- a/src/node.js +++ b/src/node.js @@ -11,7 +11,7 @@ const util = require('util'); exports.init = init; exports.log = log; -exports.formatArgs = formatArgs; +exports.applyColor = applyColor; exports.save = save; exports.load = load; exports.useColors = useColors; @@ -172,43 +172,12 @@ function getFormat() { * @api public */ -function formatArgs(args) { - var formatted = this.format; +function applyColor(str, bold = false) { + //I think doing this each time is a waste, colorCode could be stored in some variable? + const c = this.color; + const colorCode = '\u001B[3' + (c < 8 ? c : '8;5;' + c); - // Apply any `outputFormatters` transformations - formatted = formatted.replace(/%(J?[a-zA-Z+]|J?\{.+\})/g, (match, format) => { - //%J* are passed to JSON.stringify - let stringify = false; - if (format.startsWith('J')) { - format = format.replace(/^J/, ''); - stringify = true; - } - - let formatter; - //not really sure how to handle time at this point - if (format.startsWith('{')) { - formatter = outputFormatters._time; - } else { - formatter = outputFormatters[format]; - } - if (typeof formatter === 'function') { - match = formatter.call(this, format, args); - if (stringify) { - match = JSON.stringify(match) - } - } - - return match; - }); - - args[0] = formatted; -} - -function getDate() { - if (exports.inspectOpts.hideDate) { - return ''; - } - return new Date().toISOString() + ' '; + return colorCode + (bold ? ';1' : '') + 'm' + str + '\u001B[0m'; } /** @@ -283,56 +252,4 @@ formatters.o = function (v) { formatters.O = function (v) { this.inspectOpts.colors = this.useColors; return util.inspect(v, this.inspectOpts); -}; - -const { outputFormatters } = module.exports; - -/** - * Map %m to outputting message - */ - -outputFormatters.m = function(format, args) { - return args; -} - -/** - * Map %m to outputting diff - */ - -outputFormatters['+'] = function(format, args) { - const diff = 'm+' + module.exports.humanize(this.diff); - - if (this.useColors) { - const c = this.color; - const colorCode = '\u001B[3' + (c < 8 ? c : '8;5;' + c); - - return colorCode + diff + '\u001B[0m'; - } else { - return diff; - } -} - -/** - * Map %n to outputting namespace prefix - */ - -outputFormatters.n = function(format, args) { - if (this.useColors) { - const c = this.color; - const colorCode = '\u001B[3' + (c < 8 ? c : '8;5;' + c); - - return ` ${colorCode};1m${this.name} \u001B[0m`;; - } else { - return this.name; - } -} - - -/** - * Map %_time to handling time...? - */ - -outputFormatters._time = function(format, args) { - return getDate(); -} - +}; \ No newline at end of file From 2b51112dc318dff3d27c625f413472863171354c Mon Sep 17 00:00:00 2001 From: chagris <> Date: Fri, 14 Dec 2018 00:10:46 +0100 Subject: [PATCH 3/8] fix %n to correctly show namespace --- src/common.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/common.js b/src/common.js index c57f5378..8b4ae9f9 100644 --- a/src/common.js +++ b/src/common.js @@ -69,9 +69,9 @@ function setup(env) { createDebug.outputFormatters.n = function(format, args) { if (this.useColors) { - return this.applyColor(this.name, true); + return this.applyColor(this.namespace, true); } else { - return this.name; + return this.namespace; } } From 73ad1ed963758d9b73799589935cb76a709f2c2c Mon Sep 17 00:00:00 2001 From: chagris <> Date: Fri, 14 Dec 2018 00:18:46 +0100 Subject: [PATCH 4/8] properly match current version's formatting --- src/node.js | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/node.js b/src/node.js index 5c23486b..3a877ffd 100644 --- a/src/node.js +++ b/src/node.js @@ -159,11 +159,26 @@ function useColors() { } /** - * Returns DEBUG_FORMAT if specified, or false otherwise + * If DEBUG_FORMAT if specified, returns it. + * Otherwise, returns a format matching previous version's based on DEBUG_COLORS and DEBUG_HIDE_DATE */ function getFormat() { - return 'format' in exports.inspectOpts && exports.inspectOpts.format; + const useColors = 'colors' in exports.inspectOpts ? + Boolean(exports.inspectOpts.colors) : + tty.isatty(process.stderr.fd); + + if ('format' in exports.inspectOpts) { + return exports.inspectOpts.format; + } else { + if (useColors) { + return ' %n%m%+'; //' %n %m %+' + } else if (exports.inspectOpts.hideDate) { + return '%n%m'; //'%n %m' + } else { + return '%{%FT%T.%LZ%M-Z}%n%m'; //'%{%FT%T.%LZ%M-Z} %n %m' + } + } } /** From 1e18a8e9c11ccf716c24f3be8ac3070f7498091e Mon Sep 17 00:00:00 2001 From: chagris <> Date: Fri, 14 Dec 2018 14:24:39 +0100 Subject: [PATCH 5/8] move args handling to outputFormatters.m() --- src/common.js | 59 ++++++++++++++++++++++++++++----------------------- 1 file changed, 32 insertions(+), 27 deletions(-) diff --git a/src/common.js b/src/common.js index 8b4ae9f9..973ac4eb 100644 --- a/src/common.js +++ b/src/common.js @@ -47,6 +47,38 @@ function setup(env) { */ createDebug.outputFormatters.m = function(format, args) { + args[0] = createDebug.coerce(args[0]); + + if (typeof args[0] !== 'string') { + // Anything else let's inspect with %O + /** + * Note: This only inspects the first argument, + * so if debug({foo: "bar"}, {foo: "bar"}) is passed + * only the first object will be colored by node's formatters.O + */ + args.unshift('%O'); + } + + // Apply any `formatters` transformations + let index = 0; + args[0] = args[0].replace(/%([a-zA-Z%])/g, (match, format) => { + // If we encounter an escaped % then don't increase the array index + if (match === '%%') { + return match; + } + index++; + const formatter = createDebug.formatters[format]; + if (typeof formatter === 'function') { + const val = args[index]; + match = formatter.call(this, val); + + // Now we need to remove `args[index]` since it's inlined in the `format` + args.splice(index, 1); + index--; + } + return match; + }); + return args; } @@ -129,33 +161,6 @@ function setup(env) { self.curr = curr; prevTime = curr; - args[0] = createDebug.coerce(args[0]); - - if (typeof args[0] !== 'string') { - // Anything else let's inspect with %O - args.unshift('%O'); - } - - // Apply any `formatters` transformations - let index = 0; - args[0] = args[0].replace(/%([a-zA-Z%])/g, (match, format) => { - // If we encounter an escaped % then don't increase the array index - if (match === '%%') { - return match; - } - index++; - const formatter = createDebug.formatters[format]; - if (typeof formatter === 'function') { - const val = args[index]; - match = formatter.call(self, val); - - // Now we need to remove `args[index]` since it's inlined in the `format` - args.splice(index, 1); - index--; - } - return match; - }); - // Apply relevant `outputFormatters` to `format` let reg = /%(J?[a-zA-Z+]|J?\{.+\})/, formattedArgs = [], res; let outputFormat = self.format; //make a copy of the format From 5313c69f83bfc9e8607aa9adf5a52249369eccd0 Mon Sep 17 00:00:00 2001 From: chagris <> Date: Fri, 14 Dec 2018 15:13:21 +0100 Subject: [PATCH 6/8] implement metaformatters (color, JSON.stringify) --- src/common.js | 76 +++++++++++++++++++++++++++++++++++++-------------- src/node.js | 2 +- 2 files changed, 56 insertions(+), 22 deletions(-) diff --git a/src/common.js b/src/common.js index 973ac4eb..ba08e79e 100644 --- a/src/common.js +++ b/src/common.js @@ -87,12 +87,7 @@ function setup(env) { */ createDebug.outputFormatters['+'] = function(format, args) { - const diff = '+' + createDebug.humanize(this.diff); - if (this.useColors) { - return this.applyColor(diff); - } else { - return diff; - } + return '+' + createDebug.humanize(this.diff); } /** @@ -100,11 +95,7 @@ function setup(env) { */ createDebug.outputFormatters.n = function(format, args) { - if (this.useColors) { - return this.applyColor(this.namespace, true); - } else { - return this.namespace; - } + return this.namespace; } /** @@ -112,11 +103,48 @@ function setup(env) { */ createDebug.outputFormatters._time = function(format, args) { - //doesn't respect `exports.inspectOpts.hideDate` //browser doesn't have date return new Date().toISOString(); } + + /** + * Map of meta-formatters which are applied to outputFormatters + */ + createDebug.metaFormatters = {}; + + /** + * Map %J* to `JSON.stringify()` + */ + + createDebug.outputFormatters.J = function(v) { + return JSON.stringify(v); + } + + /** + * Map %c* to to `applyColor()` + */ + + createDebug.outputFormatters.c = function(v) { + if (this.useColors) { + return this.applyColor(v); + } else { + return v; + } + } + + /** + * Map %C* to to `applyColor(arg, bold = true)` (node) + */ + + createDebug.outputFormatters.C = function(v) { + if (this.useColors) { + return this.applyColor(v, true); + } else { + return v; + } + } + /** * Selects a color for a debug namespace * @param {String} namespace The namespace string for the for the debug instance to be colored @@ -162,10 +190,10 @@ function setup(env) { prevTime = curr; // Apply relevant `outputFormatters` to `format` - let reg = /%(J?[a-zA-Z+]|J?\{.+\})/, formattedArgs = [], res; + let reg = /%([a-zA-Z+]+|[a-zA-Z]*?\{.+\})/, formattedArgs = [], res; let outputFormat = self.format; //make a copy of the format while (res = outputFormat.match(reg)) { - let [matched, formatToken] = res, stringify = false, formatter, formatted; + let [matched, formatToken] = res, formatter, formatted; //split out the part before the matched format token let split = outputFormat.slice(0, res.index); outputFormat = outputFormat.slice(res.index + matched.length); @@ -175,10 +203,12 @@ function setup(env) { formattedArgs.push(split); } - //%J* are passed to JSON.stringify - if (formatToken.startsWith('J')) { - formatToken = formatToken.replace(/^J/, ''); - stringify = true; + let metaFormatters = []; + // Extract metaformatters + while (formatToken.length > 1 && !formatToken.startsWith('{')) { + const metaFormatterToken = formatToken.slice(0, 1); + formatToken = formatToken.slice(1); + metaFormatters.push(createDebug.outputFormatters[metaFormatterToken]); } //not really sure how to handle time at this point @@ -189,9 +219,13 @@ function setup(env) { } if (typeof formatter === 'function') { formatted = formatter.call(self, formatToken, args); - if (stringify) { - formatted = JSON.stringify(formatted) - } + + // Apply metaFormatters + metaFormatters.forEach(metaFormatter => { + if (typeof metaFormatter === "function") { + formatted = metaFormatter.call(self, formatted); + } + }); if (Array.isArray(formatted)) { //intended to concatenate %m's args in the middle of the format formattedArgs = formattedArgs.concat(formatted); diff --git a/src/node.js b/src/node.js index 3a877ffd..51cbf75e 100644 --- a/src/node.js +++ b/src/node.js @@ -172,7 +172,7 @@ function getFormat() { return exports.inspectOpts.format; } else { if (useColors) { - return ' %n%m%+'; //' %n %m %+' + return ' %Cn%m%c+'; //' %n %m %+' } else if (exports.inspectOpts.hideDate) { return '%n%m'; //'%n %m' } else { From 69b5a48ce4fcbaab2fa400e122785c86017ac29e Mon Sep 17 00:00:00 2001 From: chagris <> Date: Fri, 14 Dec 2018 16:07:07 +0100 Subject: [PATCH 7/8] add `%d` `outputFormatter` to show exact ms diff https://github.com/visionmedia/debug/issues/626 --- src/common.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/common.js b/src/common.js index ba08e79e..7038fa78 100644 --- a/src/common.js +++ b/src/common.js @@ -83,13 +83,21 @@ function setup(env) { } /** - * Map %+ to outputting diff + * Map %+ to humanize()'s defaults (1000ms diff => "1s") */ createDebug.outputFormatters['+'] = function(format, args) { return '+' + createDebug.humanize(this.diff); } + /** + * Map %d to returning milliseconds + */ + + createDebug.outputFormatters.d = function(format, args) { + return '+' + this.diff + "ms"; + } + /** * Map %n to outputting namespace prefix */ From 8fa6444b043089a08080197f272013bcdd2ad508 Mon Sep 17 00:00:00 2001 From: chagris <> Date: Fri, 14 Dec 2018 16:25:35 +0100 Subject: [PATCH 8/8] fix most issues from the linter --- src/common.js | 66 +++++++++++++++++++++++++++------------------------ src/node.js | 12 +++++----- 2 files changed, 41 insertions(+), 37 deletions(-) diff --git a/src/common.js b/src/common.js index 7038fa78..2c66873a 100644 --- a/src/common.js +++ b/src/common.js @@ -43,10 +43,10 @@ function setup(env) { createDebug.outputFormatters = {}; /** - * Map %m to outputting diff + * Map %m to applying formatters to arguments */ - createDebug.outputFormatters.m = function(format, args) { + createDebug.outputFormatters.m = function (_, args) { args[0] = createDebug.coerce(args[0]); if (typeof args[0] !== 'string') { @@ -80,41 +80,40 @@ function setup(env) { }); return args; - } + }; /** * Map %+ to humanize()'s defaults (1000ms diff => "1s") */ - createDebug.outputFormatters['+'] = function(format, args) { + createDebug.outputFormatters['+'] = function () { return '+' + createDebug.humanize(this.diff); - } + }; /** * Map %d to returning milliseconds */ - createDebug.outputFormatters.d = function(format, args) { - return '+' + this.diff + "ms"; - } + createDebug.outputFormatters.d = function () { + return '+' + this.diff + 'ms'; + }; /** * Map %n to outputting namespace prefix */ - createDebug.outputFormatters.n = function(format, args) { + createDebug.outputFormatters.n = function () { return this.namespace; - } + }; /** * Map %_time to handling time...? */ - createDebug.outputFormatters._time = function(format, args) { - //browser doesn't have date + createDebug.outputFormatters._time = function (format) { + // Browser doesn't have date return new Date().toISOString(); - } - + }; /** * Map of meta-formatters which are applied to outputFormatters @@ -125,33 +124,33 @@ function setup(env) { * Map %J* to `JSON.stringify()` */ - createDebug.outputFormatters.J = function(v) { + createDebug.outputFormatters.J = function (v) { return JSON.stringify(v); - } + }; /** * Map %c* to to `applyColor()` */ - createDebug.outputFormatters.c = function(v) { + createDebug.outputFormatters.c = function (v) { if (this.useColors) { return this.applyColor(v); } else { return v; } - } + }; /** * Map %C* to to `applyColor(arg, bold = true)` (node) */ - createDebug.outputFormatters.C = function(v) { + createDebug.outputFormatters.C = function (v) { if (this.useColors) { return this.applyColor(v, true); } else { return v; } - } + }; /** * Selects a color for a debug namespace @@ -198,20 +197,25 @@ function setup(env) { prevTime = curr; // Apply relevant `outputFormatters` to `format` - let reg = /%([a-zA-Z+]+|[a-zA-Z]*?\{.+\})/, formattedArgs = [], res; - let outputFormat = self.format; //make a copy of the format + const reg = /%([a-zA-Z+]+|[a-zA-Z]*?\{.+\})/; + let formattedArgs = []; + let res; + let outputFormat = self.format; // Make a copy of the format while (res = outputFormat.match(reg)) { - let [matched, formatToken] = res, formatter, formatted; - //split out the part before the matched format token - let split = outputFormat.slice(0, res.index); + let [matched, formatToken] = res; + let formatter; + let formatted; + + // Split out the part before the matched format token + const split = outputFormat.slice(0, res.index); outputFormat = outputFormat.slice(res.index + matched.length); - //and add it to the arguments + // And add it to the arguments if (split.length > 0) { formattedArgs.push(split); } - let metaFormatters = []; + const metaFormatters = []; // Extract metaformatters while (formatToken.length > 1 && !formatToken.startsWith('{')) { const metaFormatterToken = formatToken.slice(0, 1); @@ -219,7 +223,7 @@ function setup(env) { metaFormatters.push(createDebug.outputFormatters[metaFormatterToken]); } - //not really sure how to handle time at this point + // Not really sure how to handle time at this point if (formatToken.startsWith('{')) { formatter = createDebug.outputFormatters._time; } else { @@ -230,12 +234,12 @@ function setup(env) { // Apply metaFormatters metaFormatters.forEach(metaFormatter => { - if (typeof metaFormatter === "function") { + if (typeof metaFormatter === 'function') { formatted = metaFormatter.call(self, formatted); } }); - if (Array.isArray(formatted)) { //intended to concatenate %m's args in the middle of the format + if (Array.isArray(formatted)) { // Intended to concatenate %m's args in the middle of the format formattedArgs = formattedArgs.concat(formatted); } else { formattedArgs.push(formatted); @@ -250,7 +254,7 @@ function setup(env) { debug.namespace = namespace; debug.enabled = createDebug.enabled(namespace); debug.useColors = createDebug.useColors(); - debug.format = createDebug.getFormat() || '%{H:M-Z}%n%m%+'; //' %n%m%+' + debug.format = createDebug.getFormat() || '%{H:M-Z}%n%m%+'; // ' %n%m%+' debug.color = selectColor(namespace); debug.applyColor = createDebug.applyColor.bind(debug); debug.destroy = destroy; diff --git a/src/node.js b/src/node.js index 51cbf75e..9075c07c 100644 --- a/src/node.js +++ b/src/node.js @@ -138,7 +138,7 @@ exports.inspectOpts = Object.keys(process.env).filter(key => { } else if (val === 'null') { val = null; } else { - let asNumber = Number(val); + const asNumber = Number(val); if (!isNaN(asNumber)) { val = asNumber; } @@ -172,11 +172,11 @@ function getFormat() { return exports.inspectOpts.format; } else { if (useColors) { - return ' %Cn%m%c+'; //' %n %m %+' + return ' %Cn%m%c+'; // ' %n %m %+' } else if (exports.inspectOpts.hideDate) { - return '%n%m'; //'%n %m' + return '%n%m'; // '%n %m' } else { - return '%{%FT%T.%LZ%M-Z}%n%m'; //'%{%FT%T.%LZ%M-Z} %n %m' + return '%{%FT%T.%LZ%M-Z}%n%m'; // '%{%FT%T.%LZ%M-Z} %n %m' } } } @@ -188,7 +188,7 @@ function getFormat() { */ function applyColor(str, bold = false) { - //I think doing this each time is a waste, colorCode could be stored in some variable? + // I think doing this each time is a waste, colorCode could be stored in some variable? const c = this.color; const colorCode = '\u001B[3' + (c < 8 ? c : '8;5;' + c); @@ -267,4 +267,4 @@ formatters.o = function (v) { formatters.O = function (v) { this.inspectOpts.colors = this.useColors; return util.inspect(v, this.inspectOpts); -}; \ No newline at end of file +};