Comparing version 2.1.0 to 2.2.0
/** | ||
* logdown - Debug utility with markdown support that runs on browser and server | ||
* | ||
* @version v2.1.0 | ||
* @version v2.2.0 | ||
* @link https://github.com/caiogondim/logdown | ||
@@ -76,2 +76,3 @@ * @author Caio Gondim <me@caiogondim.com> (http://caiogondim.com) | ||
alignPrefixes(Logdown._instances) | ||
updateEnabledDisabled() | ||
@@ -206,2 +207,47 @@ return this | ||
function updateEnabledDisabled () { | ||
if (isNode()) { | ||
// Parsing `NODE_DEBUG` and `DEBUG` env var. | ||
var envVar = null | ||
if ( | ||
typeof process !== 'undefined' && | ||
process.env !== undefined | ||
) { | ||
// `NODE_DEBUG` has precedence over `DEBUG` | ||
if ( | ||
process.env.NODE_DEBUG !== undefined && | ||
process.env.NODE_DEBUG !== '' | ||
) { | ||
envVar = 'NODE_DEBUG' | ||
} else if ( | ||
process.env.DEBUG !== undefined && | ||
process.env.DEBUG !== '' | ||
) { | ||
envVar = 'DEBUG' | ||
} | ||
if (envVar) { | ||
Logdown.disable('*') | ||
process.env[envVar] | ||
.split(',') | ||
.forEach(function (regExp) { | ||
Logdown.enable(regExp) | ||
}) | ||
} | ||
} | ||
} else if (isBrowser()) { | ||
if ( | ||
window.localStorage && | ||
typeof window.localStorage.getItem('debug') === 'string' | ||
) { | ||
Logdown.disable('*') | ||
window.localStorage.debug | ||
.split(',') | ||
.forEach(function (regExp) { | ||
Logdown.enable(regExp) | ||
}) | ||
} | ||
} | ||
} | ||
function parseMarkdown (text) { | ||
@@ -405,35 +451,13 @@ var styles = [] | ||
function isDisabled (instance) { | ||
// Parsing `NODE_DEBUG` and `DEBUG` env var. | ||
// We verify `NODE_DEBUG` and `DEBUG` env vars on runtime so it is | ||
// easier to test. | ||
var envVar = null | ||
if (typeof process !== 'undefined' && | ||
process.env !== undefined && | ||
filterRegExps.length === 0) { | ||
// `NODE_DEBUG` has precedence over `DEBUG` | ||
if (process.env.NODE_DEBUG !== undefined && | ||
process.env.NODE_DEBUG !== '') { | ||
envVar = 'NODE_DEBUG' | ||
} else if (process.env.DEBUG !== undefined && | ||
process.env.DEBUG !== '') { | ||
envVar = 'DEBUG' | ||
} | ||
if (envVar) { | ||
Logdown.disable('*') | ||
process.env[envVar] | ||
.split(',') | ||
.forEach(function (regExp) { | ||
Logdown.enable(regExp) | ||
}) | ||
} | ||
} | ||
// Now checks if instance is disabled | ||
var isDisabled_ = false | ||
filterRegExps.forEach(function (filter) { | ||
if (filter.type === 'enable' && filter.regExp.test(instance.opts.prefix)) { | ||
if ( | ||
filter.type === 'enable' && | ||
filter.regExp.test(instance.opts.prefix) | ||
) { | ||
isDisabled_ = false | ||
} else if (filter.type === 'disable' && | ||
filter.regExp.test(instance.opts.prefix)) { | ||
} else if ( | ||
filter.type === 'disable' && | ||
filter.regExp.test(instance.opts.prefix) | ||
) { | ||
isDisabled_ = true | ||
@@ -440,0 +464,0 @@ } |
/** | ||
* logdown - Debug utility with markdown support that runs on browser and server | ||
* | ||
* @version v2.1.0 | ||
* @version v2.2.0 | ||
* @link https://github.com/caiogondim/logdown | ||
@@ -9,3 +9,3 @@ * @author Caio Gondim <me@caiogondim.com> (http://caiogondim.com) | ||
*/ | ||
!function(){"use strict";function e(n,t){return this instanceof e?(this.opts=r(n,t),l(this.opts.prefix,e._instances)?u(this.opts.prefix,e._instances):(e._instances.push(this),o(e._instances),this)):new e(n,t)}function r(e,r){"object"==typeof e&&(r=e),r=r||{},"string"!=typeof e&&(e=r.prefix||""),e=a(e);var o,n=Boolean(r.alignOutput),t=void 0===r.markdown||Boolean(r.markdown);return g()?(o=h[x%h.length],x+=1):d()&&(o=v()),{prefix:e,alignOutput:n,markdown:t,prefixColor:o}}function o(e){var r=e.sort(function(e,r){return r.opts.prefix.length-e.opts.prefix.length})[0];e.forEach(function(e){if(e.opts.alignOutput){var o=new Array(Math.max(r.opts.prefix.length-e.opts.prefix.length+1,0)).join(" ");e.opts.prefix=e.opts.prefix+o}})}function n(e){for(var r=[],o=t(e);o;)e=e.replace(o.rule.regexp,o.rule.replacer),g()&&(r.push(o.rule.style),r.push("")),o=t(e);return{text:e,styles:r}}function t(e){var r=[],o=[];return g()?o=[{regexp:/\*([^\*]+)\*/,replacer:function(e,r){return"%c"+r+"%c"},style:"font-weight:bold;"},{regexp:/_([^_]+)_/,replacer:function(e,r){return"%c"+r+"%c"},style:"font-style:italic;"},{regexp:/`([^`]+)`/,replacer:function(e,r){return"%c"+r+"%c"},style:"background:#FDF6E3; color:#586E75; padding:1px 5px; border-radius:4px;"}]:d()&&(o=[{regexp:/\*([^\*]+)\*/,replacer:function(e,r){return"["+m.modifiers.bold[0]+"m"+r+"["+m.modifiers.bold[1]+"m"}},{regexp:/_([^_]+)_/,replacer:function(e,r){return"["+m.modifiers.italic[0]+"m"+r+"["+m.modifiers.italic[1]+"m"}},{regexp:/`([^`]+)`/,replacer:function(e,r){return"["+m.bgColors.bgYellow[0]+"m["+m.colors.black[0]+"m "+r+" ["+m.colors.black[1]+"m["+m.bgColors.bgYellow[1]+"m"}}]),o.forEach(function(o){var n=e.match(o.regexp);n&&r.push({rule:o,match:n})}),0===r.length?null:(r.sort(function(e,r){return e.match.index-r.match.index}),r[0])}function i(e,r){var o,t=[];return r.opts.prefix?f()?(t.push("%c"+r.opts.prefix+"%c "),t.push("color:"+r.opts.prefixColor+"; font-weight:bold;","")):t.push("["+r.prefix+"] "):t.push(""),"string"==typeof e[0]?r.opts.markdown&&f()?(o=n(e[0]),t[0]=t[0]+o.text,t=t.concat(o.styles)):t[0]=t[0]+e[0]:t[0]=e[0],e.length>1&&(t=t.concat(e.splice(1))),t}function s(e,r,o){var t=[];return o.opts.prefix&&(f()?t[0]="["+o.opts.prefixColor[0]+"m["+m.modifiers.bold[0]+"m"+o.opts.prefix+"["+m.modifiers.bold[1]+"m["+o.opts.prefixColor[1]+"m":t[0]="["+o.opts.prefix+"]"),"warn"===r?t[0]="["+m.colors.yellow[0]+"m⚠["+m.colors.yellow[1]+"m "+(t[0]||""):"error"===r?t[0]="["+m.colors.red[0]+"m✖["+m.colors.red[1]+"m "+(t[0]||""):"info"===r?t[0]="["+m.colors.blue[0]+"mℹ["+m.colors.blue[1]+"m "+(t[0]||""):"debug"===r&&(t[0]="["+m.colors.gray[0]+"m🐛["+m.colors.gray[1]+"m "+(t[0]||"")),e.forEach(function(e){"string"==typeof e&&o.opts.markdown?t.push(n(e).text):t.push(e)}),t}function c(r){var o=null;"undefined"!=typeof process&&void 0!==process.env&&0===b.length&&(void 0!==process.env.NODE_DEBUG&&""!==process.env.NODE_DEBUG?o="NODE_DEBUG":void 0!==process.env.DEBUG&&""!==process.env.DEBUG&&(o="DEBUG"),o&&(e.disable("*"),process.env[o].split(",").forEach(function(r){e.enable(r)})));var n=!1;return b.forEach(function(e){"enable"===e.type&&e.regExp.test(r.opts.prefix)?n=!1:"disable"===e.type&&e.regExp.test(r.opts.prefix)&&(n=!0)}),n}function p(e){return new RegExp("^"+e.replace(/\*/g,".*?")+"$")}function l(e,r){var o=!1;return r.forEach(function(r){if(r.opts.prefix===e)return void(o=!0)}),o}function u(e,r){var o;return r.forEach(function(r){if(r.opts.prefix===e)return void(o=r)}),o}function a(e){return"string"==typeof e?e.replace(/%c/g,""):e}function f(){if(g()){var e="WebkitAppearance"in document.documentElement.style,r=window.console&&(console.firebug||console.exception&&console.table),o=navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)&&parseInt(RegExp.$1,10)>=31;return e||r||o}if(d())return!(process.stdout&&!process.stdout.isTTY)&&("win32"===process.platform||("COLORTERM"in process.env||"dumb"!==process.env.TERM&&!!/^screen|^xterm|^vt100|color|ansi|cygwin|linux/i.test(process.env.TERM)))}function d(){return"undefined"!=typeof module&&"undefined"!=typeof module.exports}function g(){return"undefined"!=typeof window}var x=0,h=["#B58900","#CB4B16","#DC322F","#D33682","#6C71C4","#268BD2","#2AA198","#859900"],m={modifiers:{reset:[0,0],bold:[1,22],dim:[2,22],italic:[3,23],underline:[4,24],inverse:[7,27],hidden:[8,28],strikethrough:[9,29]},colors:{black:[30,39],red:[31,39],green:[32,39],yellow:[33,39],blue:[34,39],magenta:[35,39],cyan:[36,39],white:[37,39],gray:[90,39]},bgColors:{bgBlack:[40,49],bgRed:[41,49],bgGreen:[42,49],bgYellow:[43,49],bgBlue:[44,49],bgMagenta:[45,49],bgCyan:[46,49],bgWhite:[47,49]}},b=[];e._instances=[],e.enable=function(){Array.prototype.forEach.call(arguments,function(r){"-"===r[0]&&e.disable(r.substr(1));var o=p(r);"*"===r?b=[]:b.push({type:"enable",regExp:o})})},e.disable=function(){Array.prototype.forEach.call(arguments,function(r){"-"===r[0]&&e.enable(r.substr(1));var o=p(r);"*"===r?b=[{type:"disable",regExp:o}]:b.push({type:"disable",regExp:o})})};var y=["debug","log","info","warn","error"];y.forEach(function(r){e.prototype[r]=function(){if(!c(this)){var e,o=Array.prototype.slice.call(arguments,0);g()?(e=i(o,this),Function.prototype.apply.call(console[r]||console.log,console,e)):d()&&(e=s(o,r,this),(console[r]||console.log).apply(console,e))}}});var v=function(){var e=0,r=[[31,39],[32,39],[33,39],[34,39],[35,39],[36,39]];return function(){return e+=1,r[e%r.length]}}();d()?module.exports=e:g()&&(window.Logdown=e)}(); | ||
!function(){"use strict";function e(t,i){return this instanceof e?(this.opts=o(t,i),a(this.opts.prefix,e._instances)?u(this.opts.prefix,e._instances):(e._instances.push(this),r(e._instances),n(),this)):new e(t,i)}function o(e,o){"object"==typeof e&&(o=e),o=o||{},"string"!=typeof e&&(e=o.prefix||""),e=f(e);var r,n=Boolean(o.alignOutput),t=void 0===o.markdown||Boolean(o.markdown);return x()?(r=b[h%b.length],h+=1):g()&&(r=w()),{prefix:e,alignOutput:n,markdown:t,prefixColor:r}}function r(e){var o=e.sort(function(e,o){return o.opts.prefix.length-e.opts.prefix.length})[0];e.forEach(function(e){if(e.opts.alignOutput){var r=new Array(Math.max(o.opts.prefix.length-e.opts.prefix.length+1,0)).join(" ");e.opts.prefix=e.opts.prefix+r}})}function n(){if(g()){var o=null;"undefined"!=typeof process&&void 0!==process.env&&(void 0!==process.env.NODE_DEBUG&&""!==process.env.NODE_DEBUG?o="NODE_DEBUG":void 0!==process.env.DEBUG&&""!==process.env.DEBUG&&(o="DEBUG"),o&&(e.disable("*"),process.env[o].split(",").forEach(function(o){e.enable(o)})))}else x()&&window.localStorage&&"string"==typeof window.localStorage.getItem("debug")&&(e.disable("*"),window.localStorage.debug.split(",").forEach(function(o){e.enable(o)}))}function t(e){for(var o=[],r=i(e);r;)e=e.replace(r.rule.regexp,r.rule.replacer),x()&&(o.push(r.rule.style),o.push("")),r=i(e);return{text:e,styles:o}}function i(e){var o=[],r=[];return x()?r=[{regexp:/\*([^\*]+)\*/,replacer:function(e,o){return"%c"+o+"%c"},style:"font-weight:bold;"},{regexp:/_([^_]+)_/,replacer:function(e,o){return"%c"+o+"%c"},style:"font-style:italic;"},{regexp:/`([^`]+)`/,replacer:function(e,o){return"%c"+o+"%c"},style:"background:#FDF6E3; color:#586E75; padding:1px 5px; border-radius:4px;"}]:g()&&(r=[{regexp:/\*([^\*]+)\*/,replacer:function(e,o){return"["+m.modifiers.bold[0]+"m"+o+"["+m.modifiers.bold[1]+"m"}},{regexp:/_([^_]+)_/,replacer:function(e,o){return"["+m.modifiers.italic[0]+"m"+o+"["+m.modifiers.italic[1]+"m"}},{regexp:/`([^`]+)`/,replacer:function(e,o){return"["+m.bgColors.bgYellow[0]+"m["+m.colors.black[0]+"m "+o+" ["+m.colors.black[1]+"m["+m.bgColors.bgYellow[1]+"m"}}]),r.forEach(function(r){var n=e.match(r.regexp);n&&o.push({rule:r,match:n})}),0===o.length?null:(o.sort(function(e,o){return e.match.index-o.match.index}),o[0])}function s(e,o){var r,n=[];return o.opts.prefix?d()?(n.push("%c"+o.opts.prefix+"%c "),n.push("color:"+o.opts.prefixColor+"; font-weight:bold;","")):n.push("["+o.prefix+"] "):n.push(""),"string"==typeof e[0]?o.opts.markdown&&d()?(r=t(e[0]),n[0]=n[0]+r.text,n=n.concat(r.styles)):n[0]=n[0]+e[0]:n[0]=e[0],e.length>1&&(n=n.concat(e.splice(1))),n}function c(e,o,r){var n=[];return r.opts.prefix&&(d()?n[0]="["+r.opts.prefixColor[0]+"m["+m.modifiers.bold[0]+"m"+r.opts.prefix+"["+m.modifiers.bold[1]+"m["+r.opts.prefixColor[1]+"m":n[0]="["+r.opts.prefix+"]"),"warn"===o?n[0]="["+m.colors.yellow[0]+"m⚠["+m.colors.yellow[1]+"m "+(n[0]||""):"error"===o?n[0]="["+m.colors.red[0]+"m✖["+m.colors.red[1]+"m "+(n[0]||""):"info"===o?n[0]="["+m.colors.blue[0]+"mℹ["+m.colors.blue[1]+"m "+(n[0]||""):"debug"===o&&(n[0]="["+m.colors.gray[0]+"m🐛["+m.colors.gray[1]+"m "+(n[0]||"")),e.forEach(function(e){"string"==typeof e&&r.opts.markdown?n.push(t(e).text):n.push(e)}),n}function l(e){var o=!1;return y.forEach(function(r){"enable"===r.type&&r.regExp.test(e.opts.prefix)?o=!1:"disable"===r.type&&r.regExp.test(e.opts.prefix)&&(o=!0)}),o}function p(e){return new RegExp("^"+e.replace(/\*/g,".*?")+"$")}function a(e,o){var r=!1;return o.forEach(function(o){if(o.opts.prefix===e)return void(r=!0)}),r}function u(e,o){var r;return o.forEach(function(o){if(o.opts.prefix===e)return void(r=o)}),r}function f(e){return"string"==typeof e?e.replace(/%c/g,""):e}function d(){if(x()){var e="WebkitAppearance"in document.documentElement.style,o=window.console&&(console.firebug||console.exception&&console.table),r=navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)&&parseInt(RegExp.$1,10)>=31;return e||o||r}if(g())return!(process.stdout&&!process.stdout.isTTY)&&("win32"===process.platform||("COLORTERM"in process.env||"dumb"!==process.env.TERM&&!!/^screen|^xterm|^vt100|color|ansi|cygwin|linux/i.test(process.env.TERM)))}function g(){return"undefined"!=typeof module&&"undefined"!=typeof module.exports}function x(){return"undefined"!=typeof window}var h=0,b=["#B58900","#CB4B16","#DC322F","#D33682","#6C71C4","#268BD2","#2AA198","#859900"],m={modifiers:{reset:[0,0],bold:[1,22],dim:[2,22],italic:[3,23],underline:[4,24],inverse:[7,27],hidden:[8,28],strikethrough:[9,29]},colors:{black:[30,39],red:[31,39],green:[32,39],yellow:[33,39],blue:[34,39],magenta:[35,39],cyan:[36,39],white:[37,39],gray:[90,39]},bgColors:{bgBlack:[40,49],bgRed:[41,49],bgGreen:[42,49],bgYellow:[43,49],bgBlue:[44,49],bgMagenta:[45,49],bgCyan:[46,49],bgWhite:[47,49]}},y=[];e._instances=[],e.enable=function(){Array.prototype.forEach.call(arguments,function(o){"-"===o[0]&&e.disable(o.substr(1));var r=p(o);"*"===o?y=[]:y.push({type:"enable",regExp:r})})},e.disable=function(){Array.prototype.forEach.call(arguments,function(o){"-"===o[0]&&e.enable(o.substr(1));var r=p(o);"*"===o?y=[{type:"disable",regExp:r}]:y.push({type:"disable",regExp:r})})};var v=["debug","log","info","warn","error"];v.forEach(function(o){e.prototype[o]=function(){if(!l(this)){var e,r=Array.prototype.slice.call(arguments,0);x()?(e=s(r,this),Function.prototype.apply.call(console[o]||console.log,console,e)):g()&&(e=c(r,o,this),(console[o]||console.log).apply(console,e))}}});var w=function(){var e=0,o=[[31,39],[32,39],[33,39],[34,39],[35,39],[36,39]];return function(){return e+=1,o[e%o.length]}}();g()?module.exports=e:x()&&(window.Logdown=e)}(); | ||
//# sourceMappingURL=logdown.min.js.map |
/** | ||
* logdown - Debug utility with markdown support that runs on browser and server | ||
* | ||
* @version v2.1.0 | ||
* @version v2.2.0 | ||
* @link https://github.com/caiogondim/logdown | ||
@@ -9,2 +9,2 @@ * @author Caio Gondim <me@caiogondim.com> (http://caiogondim.com) | ||
*/ | ||
!function(){"use strict";function e(n,t){return this instanceof e?(this.opts=r(n,t),l(this.opts.prefix,e._instances)?u(this.opts.prefix,e._instances):(e._instances.push(this),o(e._instances),this)):new e(n,t)}function r(e,r){"object"==typeof e&&(r=e),r=r||{},"string"!=typeof e&&(e=r.prefix||""),e=a(e);var o,n=Boolean(r.alignOutput),t=void 0===r.markdown||Boolean(r.markdown);return g()?(o=h[x%h.length],x+=1):d()&&(o=v()),{prefix:e,alignOutput:n,markdown:t,prefixColor:o}}function o(e){var r=e.sort(function(e,r){return r.opts.prefix.length-e.opts.prefix.length})[0];e.forEach(function(e){if(e.opts.alignOutput){var o=new Array(Math.max(r.opts.prefix.length-e.opts.prefix.length+1,0)).join(" ");e.opts.prefix=e.opts.prefix+o}})}function n(e){for(var r=[],o=t(e);o;)e=e.replace(o.rule.regexp,o.rule.replacer),g()&&(r.push(o.rule.style),r.push("")),o=t(e);return{text:e,styles:r}}function t(e){var r=[],o=[];return g()?o=[{regexp:/\*([^\*]+)\*/,replacer:function(e,r){return"%c"+r+"%c"},style:"font-weight:bold;"},{regexp:/_([^_]+)_/,replacer:function(e,r){return"%c"+r+"%c"},style:"font-style:italic;"},{regexp:/`([^`]+)`/,replacer:function(e,r){return"%c"+r+"%c"},style:"background:#FDF6E3; color:#586E75; padding:1px 5px; border-radius:4px;"}]:d()&&(o=[{regexp:/\*([^\*]+)\*/,replacer:function(e,r){return"["+m.modifiers.bold[0]+"m"+r+"["+m.modifiers.bold[1]+"m"}},{regexp:/_([^_]+)_/,replacer:function(e,r){return"["+m.modifiers.italic[0]+"m"+r+"["+m.modifiers.italic[1]+"m"}},{regexp:/`([^`]+)`/,replacer:function(e,r){return"["+m.bgColors.bgYellow[0]+"m["+m.colors.black[0]+"m "+r+" ["+m.colors.black[1]+"m["+m.bgColors.bgYellow[1]+"m"}}]),o.forEach(function(o){var n=e.match(o.regexp);n&&r.push({rule:o,match:n})}),0===r.length?null:(r.sort(function(e,r){return e.match.index-r.match.index}),r[0])}function i(e,r){var o,t=[];return r.opts.prefix?f()?(t.push("%c"+r.opts.prefix+"%c "),t.push("color:"+r.opts.prefixColor+"; font-weight:bold;","")):t.push("["+r.prefix+"] "):t.push(""),"string"==typeof e[0]?r.opts.markdown&&f()?(o=n(e[0]),t[0]=t[0]+o.text,t=t.concat(o.styles)):t[0]=t[0]+e[0]:t[0]=e[0],e.length>1&&(t=t.concat(e.splice(1))),t}function s(e,r,o){var t=[];return o.opts.prefix&&(f()?t[0]="["+o.opts.prefixColor[0]+"m["+m.modifiers.bold[0]+"m"+o.opts.prefix+"["+m.modifiers.bold[1]+"m["+o.opts.prefixColor[1]+"m":t[0]="["+o.opts.prefix+"]"),"warn"===r?t[0]="["+m.colors.yellow[0]+"m⚠["+m.colors.yellow[1]+"m "+(t[0]||""):"error"===r?t[0]="["+m.colors.red[0]+"m✖["+m.colors.red[1]+"m "+(t[0]||""):"info"===r?t[0]="["+m.colors.blue[0]+"mℹ["+m.colors.blue[1]+"m "+(t[0]||""):"debug"===r&&(t[0]="["+m.colors.gray[0]+"m🐛["+m.colors.gray[1]+"m "+(t[0]||"")),e.forEach(function(e){"string"==typeof e&&o.opts.markdown?t.push(n(e).text):t.push(e)}),t}function c(r){var o=null;"undefined"!=typeof process&&void 0!==process.env&&0===b.length&&(void 0!==process.env.NODE_DEBUG&&""!==process.env.NODE_DEBUG?o="NODE_DEBUG":void 0!==process.env.DEBUG&&""!==process.env.DEBUG&&(o="DEBUG"),o&&(e.disable("*"),process.env[o].split(",").forEach(function(r){e.enable(r)})));var n=!1;return b.forEach(function(e){"enable"===e.type&&e.regExp.test(r.opts.prefix)?n=!1:"disable"===e.type&&e.regExp.test(r.opts.prefix)&&(n=!0)}),n}function p(e){return new RegExp("^"+e.replace(/\*/g,".*?")+"$")}function l(e,r){var o=!1;return r.forEach(function(r){if(r.opts.prefix===e)return void(o=!0)}),o}function u(e,r){var o;return r.forEach(function(r){if(r.opts.prefix===e)return void(o=r)}),o}function a(e){return"string"==typeof e?e.replace(/%c/g,""):e}function f(){if(g()){var e="WebkitAppearance"in document.documentElement.style,r=window.console&&(console.firebug||console.exception&&console.table),o=navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)&&parseInt(RegExp.$1,10)>=31;return e||r||o}if(d())return!(process.stdout&&!process.stdout.isTTY)&&("win32"===process.platform||("COLORTERM"in process.env||"dumb"!==process.env.TERM&&!!/^screen|^xterm|^vt100|color|ansi|cygwin|linux/i.test(process.env.TERM)))}function d(){return"undefined"!=typeof module&&"undefined"!=typeof module.exports}function g(){return"undefined"!=typeof window}var x=0,h=["#B58900","#CB4B16","#DC322F","#D33682","#6C71C4","#268BD2","#2AA198","#859900"],m={modifiers:{reset:[0,0],bold:[1,22],dim:[2,22],italic:[3,23],underline:[4,24],inverse:[7,27],hidden:[8,28],strikethrough:[9,29]},colors:{black:[30,39],red:[31,39],green:[32,39],yellow:[33,39],blue:[34,39],magenta:[35,39],cyan:[36,39],white:[37,39],gray:[90,39]},bgColors:{bgBlack:[40,49],bgRed:[41,49],bgGreen:[42,49],bgYellow:[43,49],bgBlue:[44,49],bgMagenta:[45,49],bgCyan:[46,49],bgWhite:[47,49]}},b=[];e._instances=[],e.enable=function(){Array.prototype.forEach.call(arguments,function(r){"-"===r[0]&&e.disable(r.substr(1));var o=p(r);"*"===r?b=[]:b.push({type:"enable",regExp:o})})},e.disable=function(){Array.prototype.forEach.call(arguments,function(r){"-"===r[0]&&e.enable(r.substr(1));var o=p(r);"*"===r?b=[{type:"disable",regExp:o}]:b.push({type:"disable",regExp:o})})};var y=["debug","log","info","warn","error"];y.forEach(function(r){e.prototype[r]=function(){if(!c(this)){var e,o=Array.prototype.slice.call(arguments,0);g()?(e=i(o,this),Function.prototype.apply.call(console[r]||console.log,console,e)):d()&&(e=s(o,r,this),(console[r]||console.log).apply(console,e))}}});var v=function(){var e=0,r=[[31,39],[32,39],[33,39],[34,39],[35,39],[36,39]];return function(){return e+=1,r[e%r.length]}}();d()?module.exports=e:g()&&(window.Logdown=e)}(); | ||
!function(){"use strict";function e(t,i){return this instanceof e?(this.opts=o(t,i),a(this.opts.prefix,e._instances)?u(this.opts.prefix,e._instances):(e._instances.push(this),r(e._instances),n(),this)):new e(t,i)}function o(e,o){"object"==typeof e&&(o=e),o=o||{},"string"!=typeof e&&(e=o.prefix||""),e=f(e);var r,n=Boolean(o.alignOutput),t=void 0===o.markdown||Boolean(o.markdown);return x()?(r=b[h%b.length],h+=1):g()&&(r=w()),{prefix:e,alignOutput:n,markdown:t,prefixColor:r}}function r(e){var o=e.sort(function(e,o){return o.opts.prefix.length-e.opts.prefix.length})[0];e.forEach(function(e){if(e.opts.alignOutput){var r=new Array(Math.max(o.opts.prefix.length-e.opts.prefix.length+1,0)).join(" ");e.opts.prefix=e.opts.prefix+r}})}function n(){if(g()){var o=null;"undefined"!=typeof process&&void 0!==process.env&&(void 0!==process.env.NODE_DEBUG&&""!==process.env.NODE_DEBUG?o="NODE_DEBUG":void 0!==process.env.DEBUG&&""!==process.env.DEBUG&&(o="DEBUG"),o&&(e.disable("*"),process.env[o].split(",").forEach(function(o){e.enable(o)})))}else x()&&window.localStorage&&"string"==typeof window.localStorage.getItem("debug")&&(e.disable("*"),window.localStorage.debug.split(",").forEach(function(o){e.enable(o)}))}function t(e){for(var o=[],r=i(e);r;)e=e.replace(r.rule.regexp,r.rule.replacer),x()&&(o.push(r.rule.style),o.push("")),r=i(e);return{text:e,styles:o}}function i(e){var o=[],r=[];return x()?r=[{regexp:/\*([^\*]+)\*/,replacer:function(e,o){return"%c"+o+"%c"},style:"font-weight:bold;"},{regexp:/_([^_]+)_/,replacer:function(e,o){return"%c"+o+"%c"},style:"font-style:italic;"},{regexp:/`([^`]+)`/,replacer:function(e,o){return"%c"+o+"%c"},style:"background:#FDF6E3; color:#586E75; padding:1px 5px; border-radius:4px;"}]:g()&&(r=[{regexp:/\*([^\*]+)\*/,replacer:function(e,o){return"["+m.modifiers.bold[0]+"m"+o+"["+m.modifiers.bold[1]+"m"}},{regexp:/_([^_]+)_/,replacer:function(e,o){return"["+m.modifiers.italic[0]+"m"+o+"["+m.modifiers.italic[1]+"m"}},{regexp:/`([^`]+)`/,replacer:function(e,o){return"["+m.bgColors.bgYellow[0]+"m["+m.colors.black[0]+"m "+o+" ["+m.colors.black[1]+"m["+m.bgColors.bgYellow[1]+"m"}}]),r.forEach(function(r){var n=e.match(r.regexp);n&&o.push({rule:r,match:n})}),0===o.length?null:(o.sort(function(e,o){return e.match.index-o.match.index}),o[0])}function s(e,o){var r,n=[];return o.opts.prefix?d()?(n.push("%c"+o.opts.prefix+"%c "),n.push("color:"+o.opts.prefixColor+"; font-weight:bold;","")):n.push("["+o.prefix+"] "):n.push(""),"string"==typeof e[0]?o.opts.markdown&&d()?(r=t(e[0]),n[0]=n[0]+r.text,n=n.concat(r.styles)):n[0]=n[0]+e[0]:n[0]=e[0],e.length>1&&(n=n.concat(e.splice(1))),n}function c(e,o,r){var n=[];return r.opts.prefix&&(d()?n[0]="["+r.opts.prefixColor[0]+"m["+m.modifiers.bold[0]+"m"+r.opts.prefix+"["+m.modifiers.bold[1]+"m["+r.opts.prefixColor[1]+"m":n[0]="["+r.opts.prefix+"]"),"warn"===o?n[0]="["+m.colors.yellow[0]+"m⚠["+m.colors.yellow[1]+"m "+(n[0]||""):"error"===o?n[0]="["+m.colors.red[0]+"m✖["+m.colors.red[1]+"m "+(n[0]||""):"info"===o?n[0]="["+m.colors.blue[0]+"mℹ["+m.colors.blue[1]+"m "+(n[0]||""):"debug"===o&&(n[0]="["+m.colors.gray[0]+"m🐛["+m.colors.gray[1]+"m "+(n[0]||"")),e.forEach(function(e){"string"==typeof e&&r.opts.markdown?n.push(t(e).text):n.push(e)}),n}function l(e){var o=!1;return y.forEach(function(r){"enable"===r.type&&r.regExp.test(e.opts.prefix)?o=!1:"disable"===r.type&&r.regExp.test(e.opts.prefix)&&(o=!0)}),o}function p(e){return new RegExp("^"+e.replace(/\*/g,".*?")+"$")}function a(e,o){var r=!1;return o.forEach(function(o){if(o.opts.prefix===e)return void(r=!0)}),r}function u(e,o){var r;return o.forEach(function(o){if(o.opts.prefix===e)return void(r=o)}),r}function f(e){return"string"==typeof e?e.replace(/%c/g,""):e}function d(){if(x()){var e="WebkitAppearance"in document.documentElement.style,o=window.console&&(console.firebug||console.exception&&console.table),r=navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)&&parseInt(RegExp.$1,10)>=31;return e||o||r}if(g())return!(process.stdout&&!process.stdout.isTTY)&&("win32"===process.platform||("COLORTERM"in process.env||"dumb"!==process.env.TERM&&!!/^screen|^xterm|^vt100|color|ansi|cygwin|linux/i.test(process.env.TERM)))}function g(){return"undefined"!=typeof module&&"undefined"!=typeof module.exports}function x(){return"undefined"!=typeof window}var h=0,b=["#B58900","#CB4B16","#DC322F","#D33682","#6C71C4","#268BD2","#2AA198","#859900"],m={modifiers:{reset:[0,0],bold:[1,22],dim:[2,22],italic:[3,23],underline:[4,24],inverse:[7,27],hidden:[8,28],strikethrough:[9,29]},colors:{black:[30,39],red:[31,39],green:[32,39],yellow:[33,39],blue:[34,39],magenta:[35,39],cyan:[36,39],white:[37,39],gray:[90,39]},bgColors:{bgBlack:[40,49],bgRed:[41,49],bgGreen:[42,49],bgYellow:[43,49],bgBlue:[44,49],bgMagenta:[45,49],bgCyan:[46,49],bgWhite:[47,49]}},y=[];e._instances=[],e.enable=function(){Array.prototype.forEach.call(arguments,function(o){"-"===o[0]&&e.disable(o.substr(1));var r=p(o);"*"===o?y=[]:y.push({type:"enable",regExp:r})})},e.disable=function(){Array.prototype.forEach.call(arguments,function(o){"-"===o[0]&&e.enable(o.substr(1));var r=p(o);"*"===o?y=[{type:"disable",regExp:r}]:y.push({type:"disable",regExp:r})})};var v=["debug","log","info","warn","error"];v.forEach(function(o){e.prototype[o]=function(){if(!l(this)){var e,r=Array.prototype.slice.call(arguments,0);x()?(e=s(r,this),Function.prototype.apply.call(console[o]||console.log,console,e)):g()&&(e=c(r,o,this),(console[o]||console.log).apply(console,e))}}});var w=function(){var e=0,o=[[31,39],[32,39],[33,39],[34,39],[35,39],[36,39]];return function(){return e+=1,o[e%o.length]}}();g()?module.exports=e:x()&&(window.Logdown=e)}(); |
@@ -41,3 +41,3 @@ 'use strict' | ||
gulp.task('test', ['karma']) | ||
gulp.task('test', ['mocha', 'karma']) | ||
gulp.task('test:travisci', ['karma-travisci']) | ||
@@ -44,0 +44,0 @@ |
{ | ||
"name": "logdown", | ||
"version": "2.1.0", | ||
"version": "2.2.0", | ||
"description": "Debug utility with markdown support that runs on browser and server", | ||
@@ -11,5 +11,5 @@ "main": "dist/logdown.js", | ||
"scripts": { | ||
"test": "npm run build && npm run test:lint && gulp test", | ||
"test": "npm run build && gulp test && npm run test:lint", | ||
"test:server": "gulp mocha", | ||
"test:client": "gulp karma", | ||
"test:client": "npm run build && gulp karma", | ||
"test:lint": "standard './src/**/*.js' './test/**/*.js'", | ||
@@ -16,0 +16,0 @@ "test:lint:fix": "standard './src/**/*.js' './test/**/*.js' --fix", |
@@ -68,2 +68,3 @@ /* global console, module, window, document, navigator, process */ | ||
alignPrefixes(Logdown._instances) | ||
updateEnabledDisabled() | ||
@@ -198,2 +199,47 @@ return this | ||
function updateEnabledDisabled () { | ||
if (isNode()) { | ||
// Parsing `NODE_DEBUG` and `DEBUG` env var. | ||
var envVar = null | ||
if ( | ||
typeof process !== 'undefined' && | ||
process.env !== undefined | ||
) { | ||
// `NODE_DEBUG` has precedence over `DEBUG` | ||
if ( | ||
process.env.NODE_DEBUG !== undefined && | ||
process.env.NODE_DEBUG !== '' | ||
) { | ||
envVar = 'NODE_DEBUG' | ||
} else if ( | ||
process.env.DEBUG !== undefined && | ||
process.env.DEBUG !== '' | ||
) { | ||
envVar = 'DEBUG' | ||
} | ||
if (envVar) { | ||
Logdown.disable('*') | ||
process.env[envVar] | ||
.split(',') | ||
.forEach(function (regExp) { | ||
Logdown.enable(regExp) | ||
}) | ||
} | ||
} | ||
} else if (isBrowser()) { | ||
if ( | ||
window.localStorage && | ||
typeof window.localStorage.getItem('debug') === 'string' | ||
) { | ||
Logdown.disable('*') | ||
window.localStorage.debug | ||
.split(',') | ||
.forEach(function (regExp) { | ||
Logdown.enable(regExp) | ||
}) | ||
} | ||
} | ||
} | ||
function parseMarkdown (text) { | ||
@@ -397,35 +443,13 @@ var styles = [] | ||
function isDisabled (instance) { | ||
// Parsing `NODE_DEBUG` and `DEBUG` env var. | ||
// We verify `NODE_DEBUG` and `DEBUG` env vars on runtime so it is | ||
// easier to test. | ||
var envVar = null | ||
if (typeof process !== 'undefined' && | ||
process.env !== undefined && | ||
filterRegExps.length === 0) { | ||
// `NODE_DEBUG` has precedence over `DEBUG` | ||
if (process.env.NODE_DEBUG !== undefined && | ||
process.env.NODE_DEBUG !== '') { | ||
envVar = 'NODE_DEBUG' | ||
} else if (process.env.DEBUG !== undefined && | ||
process.env.DEBUG !== '') { | ||
envVar = 'DEBUG' | ||
} | ||
if (envVar) { | ||
Logdown.disable('*') | ||
process.env[envVar] | ||
.split(',') | ||
.forEach(function (regExp) { | ||
Logdown.enable(regExp) | ||
}) | ||
} | ||
} | ||
// Now checks if instance is disabled | ||
var isDisabled_ = false | ||
filterRegExps.forEach(function (filter) { | ||
if (filter.type === 'enable' && filter.regExp.test(instance.opts.prefix)) { | ||
if ( | ||
filter.type === 'enable' && | ||
filter.regExp.test(instance.opts.prefix) | ||
) { | ||
isDisabled_ = false | ||
} else if (filter.type === 'disable' && | ||
filter.regExp.test(instance.opts.prefix)) { | ||
} else if ( | ||
filter.type === 'disable' && | ||
filter.regExp.test(instance.opts.prefix) | ||
) { | ||
isDisabled_ = true | ||
@@ -432,0 +456,0 @@ } |
@@ -20,2 +20,3 @@ /* global describe, afterEach, beforeEach, console, it, require, window, | ||
Logdown.enable('*') | ||
Logdown._instances = [] | ||
}) | ||
@@ -29,3 +30,2 @@ | ||
try { | ||
Logdown._instances = [] | ||
var foo = Logdown({markdown: true}) | ||
@@ -80,3 +80,2 @@ | ||
try { | ||
Logdown._instances = [] | ||
var foo = Logdown({markdown: false}) | ||
@@ -141,18 +140,42 @@ | ||
assert.equal(abc.opts.prefix.length, 3, 'Skipping \'alignOutput\' will not add whitespace characters') | ||
assert.equal( | ||
abc.opts.prefix.length, | ||
3, | ||
'Skipping \'alignOutput\' will not add whitespace characters' | ||
) | ||
assert.equal(abc.opts.alignOutput, false) | ||
assert.equal(text.opts.prefix.length, 10, 'Inputs will be converted into Boolean values') | ||
assert.equal( | ||
text.opts.prefix.length, | ||
10, | ||
'Inputs will be converted into Boolean values' | ||
) | ||
assert.equal(text.opts.alignOutput, true) | ||
assert.equal(demo.opts.prefix.length, 10, 'Padding will be added to make short names as long as the longest') | ||
assert.equal( | ||
demo.opts.prefix.length, | ||
10, | ||
'Padding will be added to make short names as long as the longest' | ||
) | ||
assert.equal(demo.opts.alignOutput, true) | ||
assert.equal(longDemo.opts.prefix.length, 10, 'Padding will be added to make long names as long as the longest') | ||
assert.equal( | ||
longDemo.opts.prefix.length, | ||
10, | ||
'Padding will be added to make long names as long as the longest' | ||
) | ||
assert.equal(longDemo.opts.alignOutput, true) | ||
assert.equal(demoFalse.opts.prefix.length, 9, 'Padding will be skipped if set to \'false\'') | ||
assert.equal( | ||
demoFalse.opts.prefix.length, | ||
9, | ||
'Padding will be skipped if set to \'false\'' | ||
) | ||
assert.equal(demoFalse.opts.alignOutput, false) | ||
assert.equal(longerDemo.opts.prefix.length, 10, 'The longest name will set the width for every other logger name') | ||
assert.equal( | ||
longerDemo.opts.prefix.length, | ||
10, | ||
'The longest name will set the width for every other logger name' | ||
) | ||
assert.equal(longerDemo.opts.alignOutput, true) | ||
@@ -159,0 +182,0 @@ } catch (error) { |
@@ -27,2 +27,3 @@ /* global describe, it, beforeEach, afterEach, xit */ | ||
Logdown.enable('*') | ||
Logdown._instances = [] | ||
}) | ||
@@ -35,33 +36,33 @@ | ||
envVars.forEach(function (envVar) { | ||
it('`' + envVar + '=foo` should enable only instances with “foo” prefix', | ||
function () { | ||
try { | ||
var foo = new Logdown({prefix: 'foo'}) | ||
var bar = new Logdown({prefix: 'bar'}) | ||
var quz = new Logdown({prefix: 'quz'}) | ||
var baz = new Logdown({prefix: 'baz'}) | ||
it('`' + envVar + '=foo` should enable only instances with “foo” prefix', function () { | ||
try { | ||
process.env[envVar] = 'foo' | ||
process.env[envVar] = 'foo' | ||
var foo = new Logdown({prefix: 'foo'}) | ||
var bar = new Logdown({prefix: 'bar'}) | ||
var quz = new Logdown({prefix: 'quz'}) | ||
var baz = new Logdown({prefix: 'baz'}) | ||
bar.log('lorem') | ||
assert.notCalled(console.log) | ||
quz.log('lorem') | ||
assert.notCalled(console.log) | ||
baz.log('lorem') | ||
assert.notCalled(console.log) | ||
foo.log('lorem') | ||
assert.called(console.log) | ||
bar.log('lorem') | ||
assert.notCalled(console.log) | ||
quz.log('lorem') | ||
assert.notCalled(console.log) | ||
baz.log('lorem') | ||
assert.notCalled(console.log) | ||
foo.log('lorem') | ||
assert.called(console.log) | ||
sandbox.restore() | ||
} catch (error) { | ||
sandbox.restore() | ||
throw error | ||
} | ||
sandbox.restore() | ||
} catch (error) { | ||
sandbox.restore() | ||
throw error | ||
} | ||
sandbox.restore() | ||
}) | ||
sandbox.restore() | ||
}) | ||
xit('`' + envVar + '=*foo` should enable only instances with names ' + | ||
'ending with “foo”', function () { | ||
xit('`' + envVar + '=*foo` should enable only instances with names ending with “foo”', function () { | ||
try { | ||
process.env[envVar] = '*foo' | ||
var foo = new Logdown({prefix: 'foo'}) | ||
@@ -72,4 +73,2 @@ var bar = new Logdown({prefix: 'bar'}) | ||
process.env[envVar] = '*foo' | ||
bar.log('lorem') | ||
@@ -91,5 +90,6 @@ foobar.log('lorem') | ||
xit('`' + envVar + '=foo*` should enable only instances with names ' + | ||
'beginning with “foo”', function () { | ||
xit('`' + envVar + '=foo*` should enable only instances with names beginning with “foo”', function () { | ||
try { | ||
process.env[envVar] = 'foo*' | ||
var foo = new Logdown({prefix: 'foo'}) | ||
@@ -100,4 +100,2 @@ var bar = new Logdown({prefix: 'bar'}) | ||
process.env[envVar] = 'foo*' | ||
bar.log('lorem') | ||
@@ -121,2 +119,4 @@ barfoo.log('lorem') | ||
try { | ||
process.env[envVar] = '-*' | ||
var foo = new Logdown({prefix: 'foo'}) | ||
@@ -127,4 +127,2 @@ var bar = new Logdown({prefix: 'bar'}) | ||
process.env[envVar] = '-*' | ||
foobar.log('lorem') | ||
@@ -143,5 +141,6 @@ foo.log('lorem') | ||
it('`' + envVar + '=*,-foo` should enable all but only instances ' + | ||
'with “foo” prefix', function () { | ||
it('`' + envVar + '=*,-foo` should enable all but only instances with “foo” prefix', function () { | ||
try { | ||
process.env[envVar] = '*,-foo' | ||
var foo = new Logdown({prefix: 'foo'}) | ||
@@ -152,4 +151,2 @@ var bar = new Logdown({prefix: 'bar'}) | ||
process.env[envVar] = '*,-foo' | ||
foo.log('lorem') | ||
@@ -169,5 +166,6 @@ assert.notCalled(console.log) | ||
it('`' + envVar + '=*,-*foo` should enable all but instances with names ' + | ||
'ending with “foo”', function () { | ||
it('`' + envVar + '=*,-*foo` should enable all but instances with names ending with “foo”', function () { | ||
try { | ||
process.env[envVar] = '*,-*foo' | ||
var foo = new Logdown({prefix: 'foo'}) | ||
@@ -178,4 +176,2 @@ var bar = new Logdown({prefix: 'bar'}) | ||
process.env[envVar] = '*,-*foo' | ||
foo.log('lorem') | ||
@@ -195,5 +191,6 @@ barfoo.log('lorem') | ||
it('`' + envVar + '=*,-foo*` should enable all but instances with names ' + | ||
'beginning with “foo”', function () { | ||
it('`' + envVar + '=*,-foo*` should enable all but instances with names beginning with “foo”', function () { | ||
try { | ||
process.env[envVar] = '*,-foo*' | ||
var foo = new Logdown({prefix: 'foo'}) | ||
@@ -204,4 +201,2 @@ var bar = new Logdown({prefix: 'bar'}) | ||
process.env[envVar] = '*,-foo*' | ||
foobar.log('lorem') | ||
@@ -223,2 +218,5 @@ foo.log('lorem') | ||
try { | ||
Logdown.enable('*') | ||
process.env[envVar] = 'foo,barfoo' | ||
var foo = new Logdown({prefix: 'foo'}) | ||
@@ -229,5 +227,2 @@ var bar = new Logdown({prefix: 'bar'}) | ||
Logdown.enable('*') | ||
process.env[envVar] = 'foo,barfoo' | ||
bar.log('lorem') | ||
@@ -252,2 +247,5 @@ foobar.log('lorem') | ||
try { | ||
process.env.NODE_DEBUG = 'foo,barfoo' | ||
process.env.DEBUG = 'bar,foobar' | ||
var foo = new Logdown({prefix: 'foo'}) | ||
@@ -258,5 +256,2 @@ var bar = new Logdown({prefix: 'bar'}) | ||
process.env.NODE_DEBUG = 'foo,barfoo' | ||
process.env.DEBUG = 'bar,foobar' | ||
bar.log('lorem') | ||
@@ -263,0 +258,0 @@ foobar.log('lorem') |
Sorry, the diff of this file is not supported yet
146744
3239
29