diff --git a/dist/logdown.js b/dist/logdown.js index cfad483..affdf73 100644 --- a/dist/logdown.js +++ b/dist/logdown.js @@ -1,7 +1,7 @@ /** * logdown - Debug utility with markdown support that runs on browser and server * - * @version v2.0.3 + * @version v2.1.0 * @link https://github.com/caiogondim/logdown * @author Caio Gondim (http://caiogondim.com) * @license MIT diff --git a/dist/logdown.min.js b/dist/logdown.min.js index 8a77bdd..9432ab4 100644 --- a/dist/logdown.min.js +++ b/dist/logdown.min.js @@ -1,7 +1,7 @@ /** * logdown - Debug utility with markdown support that runs on browser and server * - * @version v2.0.3 + * @version v2.1.0 * @link https://github.com/caiogondim/logdown * @author Caio Gondim (http://caiogondim.com) * @license MIT diff --git a/dist/logdown.min.js.map b/dist/logdown.min.js.map index 5898093..6307741 100644 --- a/dist/logdown.min.js.map +++ b/dist/logdown.min.js.map @@ -1 +1 @@ -{"version":3,"sources":["logdown.js"],"names":["Logdown","prefix","opts","this","normalizeOpts","isPrefixAlreadyInUse","_instances","getInstanceByPrefix","push","alignPrefixes","sanitizeStringToBrowser","prefixColor","alignOutput","Boolean","markdown","undefined","isBrowser","colors","lastUsedColorIndex","length","isNode","getNextPrefixColor","instances","longest","sort","a","b","forEach","instance","padding","Array","Math","max","join","parseMarkdown","text","styles","match","getNextMatch","replace","rule","regexp","replacer","style","matches","rules","submatch1","ansiColors","modifiers","bold","italic","bgColors","bgYellow","black","index","prepareOutputToBrowser","args","parsedMarkdown","preparedOutput","isColorSupported","concat","splice","prepareOutputToNode","method","yellow","red","blue","gray","arg","isDisabled","envVar","process","env","filterRegExps","NODE_DEBUG","DEBUG","disable","split","regExp","enable","isDisabled_","filter","type","test","prepareRegExpForPrefixSearch","str","RegExp","isPrefixAlreadyInUse_","instanceCur","isWebkit","document","documentElement","isFirebug","window","console","firebug","exception","table","isFirefox31Plus","navigator","userAgent","toLowerCase","parseInt","$1","stdout","isTTY","platform","TERM","module","exports","reset","dim","underline","inverse","hidden","strikethrough","green","magenta","cyan","white","bgBlack","bgRed","bgGreen","bgBlue","bgMagenta","bgCyan","bgWhite","prototype","call","arguments","substr","methods","slice","Function","apply","log","lastUsed","nodePrefixColors"],"mappings":";;;;;;;;CAEA,WACA,YAmDA,SAAAA,GAAAC,EAAAC,GACA,MAAAC,gBAAAH,IAIAG,KAAAD,KAAAE,EAAAH,EAAAC,GAEAG,EAAAF,KAAAD,KAAAD,OAAAD,EAAAM,YACAC,EAAAJ,KAAAD,KAAAD,OAAAD,EAAAM,aAGAN,EAAAM,WAAAE,KAAAL,MACAM,EAAAT,EAAAM,YAEAH,OAZA,GAAAH,GAAAC,EAAAC,GAqGA,QAAAE,GAAAH,EAAAC,GACA,gBAAAD,KAAAC,EAAAD,GACAC,EAAAA,MAEA,gBAAAD,KAAAA,EAAAC,EAAAD,QAAA,IACAA,EAAAS,EAAAT,EAEA,IAGAU,GAHAC,EAAAC,QAAAX,EAAAU,aACAE,EAAAC,SAAAb,EAAAY,UAAAD,QAAAX,EAAAY,SAUA,OAPAE,MACAL,EAAAM,EAAAC,EAAAD,EAAAE,QACAD,GAAA,GACAE,MACAT,EAAAU,MAIApB,OAAAA,EACAW,YAAAA,EACAE,SAAAA,EACAH,YAAAA,GAIA,QAAAF,GAAAa,GACA,GAAAC,GAAAD,EAAAE,KAAA,SAAAC,EAAAC,GACA,MAAAA,GAAAxB,KAAAD,OAAAkB,OAAAM,EAAAvB,KAAAD,OAAAkB,SACA,EAEAG,GAAAK,QAAA,SAAAC,GACA,GAAAA,EAAA1B,KAAAU,YAAA,CACA,GAAAiB,GAAA,GAAAC,OAAAC,KAAAC,IAAAT,EAAArB,KAAAD,OAAAkB,OAAAS,EAAA1B,KAAAD,OAAAkB,OAAA,EAAA,IAAAc,KAAA,IACAL,GAAA1B,KAAAD,OAAA2B,EAAA1B,KAAAD,OAAA4B,KAKA,QAAAK,GAAAC,GAIA,IAHA,GAAAC,MACAC,EAAAC,EAAAH,GAEAE,GACAF,EAAAA,EAAAI,QAAAF,E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M,EAAAC,EAEA,OAAAA,EACAZ,KAEAA,EAAAjE,MACA0E,KAAA,SACAJ,OAAAA,OAMA9E,EAAA4E,QAAA,WACA9C,MAAAiG,UAAApG,QAAAqG,KAAAC,UAAA,SAAA5C,GACA,MAAAA,EAAA,IACArF,EAAA+E,OAAAM,EAAA6C,OAAA,GAGA,IAAApD,GAAAM,EAAAC,EAEA,OAAAA,EACAZ,IACAS,KAAA,UACAJ,OAAAA,IAGAL,EAAAjE,MACA0E,KAAA,UACAJ,OAAAA,MAUA,IAAAqD,IAAA,QAAA,MAAA,OAAA,OAAA,QACAA,GAAAxG,QAAA,SAAAoC,GACA/D,EAAA+H,UAAAhE,GAAA,WACA,IAAAM,EAAAlE,MAAA,CAIA,GAAAuD,GACAF,EAAA1B,MAAAiG,UAAAK,MAAAJ,KAAAC,UAAA,EAEAjH,MACA0C,EAAAH,EAAAC,EAAArD,MAKAkI,SAAAN,UAAAO,MAAAN,KACAlC,QAAA/B,IAAA+B,QAAAyC,IACAzC,QACApC,IAEAtC,MACAsC,EAAAI,EAAAN,EAAAO,EAAA5D,OACA2F,QAAA/B,IAAA+B,QAAAyC,KAAAD,MACAxC,QACApC,OAmYA,IAAArC,GAAA,WACA,GAAAmH,GAAA,EACAC,IACA,GAAA,KACA,GAAA,KACA,GAAA,KACA,GAAA,KACA,GAAA,KACA,GAAA,IAGA,OAAA,YAEA,MADAD,IAAA,EACAC,EAAAD,EAAAC,EAAAtH,WAKAC,KACAwF,OAAAC,QAAA7G,EACAgB,MACA6E,OAAA7F,QAAAA","file":"logdown.min.js","sourcesContent":["/**\n * logdown - Debug utility with markdown support that runs on browser and server\n *\n * @version v2.0.3\n * @link https://github.com/caiogondim/logdown\n * @author Caio Gondim (http://caiogondim.com)\n * @license MIT\n */\n/* global console, module, window, document, navigator, process */\n\n;(function () {\n 'use strict'\n\n var lastUsedColorIndex = 0\n // Solarized accent colors http://ethanschoonover.com/solarized\n var colors = [\n '#B58900',\n '#CB4B16',\n '#DC322F',\n '#D33682',\n '#6C71C4',\n '#268BD2',\n '#2AA198',\n '#859900'\n ]\n // Taken from ansi-styles npm module\n // https://github.com/sindresorhus/ansi-styles/blob/master/index.js\n var ansiColors = {\n modifiers: {\n reset: [0, 0],\n bold: [1, 22], // 21 isn't widely supported and 22 does the same thing\n dim: [2, 22],\n italic: [3, 23],\n underline: [4, 24],\n inverse: [7, 27],\n hidden: [8, 28],\n strikethrough: [9, 29]\n },\n colors: {\n black: [30, 39],\n red: [31, 39],\n green: [32, 39],\n yellow: [33, 39],\n blue: [34, 39],\n magenta: [35, 39],\n cyan: [36, 39],\n white: [37, 39],\n gray: [90, 39]\n },\n bgColors: {\n bgBlack: [40, 49],\n bgRed: [41, 49],\n bgGreen: [42, 49],\n bgYellow: [43, 49],\n bgBlue: [44, 49],\n bgMagenta: [45, 49],\n bgCyan: [46, 49],\n bgWhite: [47, 49]\n }\n }\n var filterRegExps = []\n\n function Logdown (prefix, opts) {\n if (!(this instanceof Logdown)) {\n return new Logdown(prefix, opts)\n }\n\n this.opts = normalizeOpts(prefix, opts)\n\n if (isPrefixAlreadyInUse(this.opts.prefix, Logdown._instances)) {\n return getInstanceByPrefix(this.opts.prefix, Logdown._instances)\n }\n\n Logdown._instances.push(this)\n alignPrefixes(Logdown._instances)\n\n return this\n }\n\n //\n // Static\n //\n\n Logdown._instances = []\n\n Logdown.enable = function () {\n Array.prototype.forEach.call(arguments, function (str) {\n if (str[0] === '-') {\n Logdown.disable(str.substr(1))\n }\n\n var regExp = prepareRegExpForPrefixSearch(str)\n\n if (str === '*') {\n filterRegExps = []\n } else {\n filterRegExps.push({\n type: 'enable',\n regExp: regExp\n })\n }\n })\n }\n\n Logdown.disable = function () {\n Array.prototype.forEach.call(arguments, function (str) {\n if (str[0] === '-') {\n Logdown.enable(str.substr(1))\n }\n\n var regExp = prepareRegExpForPrefixSearch(str)\n\n if (str === '*') {\n filterRegExps = [{\n type: 'disable',\n regExp: regExp\n }]\n } else {\n filterRegExps.push({\n type: 'disable',\n regExp: regExp\n })\n }\n })\n }\n\n //\n // Public\n //\n\n var methods = ['debug', 'log', 'info', 'warn', 'error']\n methods.forEach(function (method) {\n Logdown.prototype[method] = function () {\n if (isDisabled(this)) {\n return\n }\n\n var preparedOutput\n var args = Array.prototype.slice.call(arguments, 0)\n\n if (isBrowser()) {\n preparedOutput = prepareOutputToBrowser(args, this)\n\n // IE9 workaround\n // http://stackoverflow.com/questions/5538972/\n // console-log-apply-not-working-in-ie9\n Function.prototype.apply.call(\n console[method] || console.log,\n console,\n preparedOutput\n )\n } else if (isNode()) {\n preparedOutput = prepareOutputToNode(args, method, this)\n ;(console[method] || console.log).apply(\n console,\n preparedOutput\n )\n }\n }\n })\n\n //\n // Private\n //\n\n function normalizeOpts (prefix, opts) {\n if (typeof prefix === 'object') opts = prefix\n opts = opts || {}\n\n if (typeof prefix !== 'string') prefix = opts.prefix || ''\n prefix = sanitizeStringToBrowser(prefix)\n\n var alignOutput = Boolean(opts.alignOutput)\n var markdown = opts.markdown === undefined ? true : Boolean(opts.markdown)\n\n var prefixColor\n if (isBrowser()) {\n prefixColor = colors[lastUsedColorIndex % colors.length]\n lastUsedColorIndex += 1\n } else if (isNode()) {\n prefixColor = getNextPrefixColor()\n }\n\n return {\n prefix: prefix,\n alignOutput: alignOutput,\n markdown: markdown,\n prefixColor: prefixColor\n }\n }\n\n function alignPrefixes (instances) {\n var longest = instances.sort(function (a, b) {\n return b.opts.prefix.length - a.opts.prefix.length\n })[0]\n\n instances.forEach(function (instance) {\n if (instance.opts.alignOutput) {\n var padding = new Array(Math.max(longest.opts.prefix.length - instance.opts.prefix.length + 1, 0)).join(' ')\n instance.opts.prefix = instance.opts.prefix + padding\n }\n })\n }\n\n function parseMarkdown (text) {\n var styles = []\n var match = getNextMatch(text)\n\n while (match) {\n text = text.replace(match.rule.regexp, match.rule.replacer)\n\n if (isBrowser()) {\n styles.push(match.rule.style)\n styles.push('') // Empty string resets style.\n }\n\n match = getNextMatch(text)\n }\n\n return {text: text, styles: styles}\n }\n\n function getNextMatch (text) {\n var matches = []\n var rules = []\n if (isBrowser()) {\n rules = [\n {\n regexp: /\\*([^\\*]+)\\*/,\n replacer: function (match, submatch1) {\n return '%c' + submatch1 + '%c'\n },\n style: 'font-weight:bold;'\n },\n {\n regexp: /_([^_]+)_/,\n replacer: function (match, submatch1) {\n return '%c' + submatch1 + '%c'\n },\n style: 'font-style:italic;'\n },\n {\n regexp: /`([^`]+)`/,\n replacer: function (match, submatch1) {\n return '%c' + submatch1 + '%c'\n },\n style:\n 'background:#FDF6E3; ' +\n 'color:#586E75; ' +\n 'padding:1px 5px; ' +\n 'border-radius:4px;'\n }\n ]\n } else if (isNode()) {\n rules = [\n {\n regexp: /\\*([^\\*]+)\\*/,\n replacer: function (match, submatch1) {\n return '\\u001b[' + ansiColors.modifiers.bold[0] + 'm' +\n submatch1 +\n '\\u001b[' + ansiColors.modifiers.bold[1] + 'm'\n }\n },\n {\n regexp: /_([^_]+)_/,\n replacer: function (match, submatch1) {\n return '\\u001b[' + ansiColors.modifiers.italic[0] + 'm' +\n submatch1 +\n '\\u001b[' + ansiColors.modifiers.italic[1] + 'm'\n }\n },\n {\n regexp: /`([^`]+)`/,\n replacer: function (match, submatch1) {\n return '\\u001b[' + ansiColors.bgColors.bgYellow[0] + 'm' +\n '\\u001b[' + ansiColors.colors.black[0] + 'm' +\n ' ' + submatch1 + ' ' +\n '\\u001b[' + ansiColors.colors.black[1] + 'm' +\n '\\u001b[' + ansiColors.bgColors.bgYellow[1] + 'm'\n }\n }\n ]\n }\n\n //\n rules.forEach(function (rule) {\n var match = text.match(rule.regexp)\n if (match) {\n matches.push({\n rule: rule,\n match: match\n })\n }\n })\n if (matches.length === 0) {\n return null\n }\n\n //\n matches.sort(function (a, b) {\n return a.match.index - b.match.index\n })\n\n return matches[0]\n }\n\n function prepareOutputToBrowser (args, instance) {\n var preparedOutput = []\n var parsedMarkdown\n\n if (instance.opts.prefix) {\n if (isColorSupported()) {\n preparedOutput.push('%c' + instance.opts.prefix + '%c ')\n preparedOutput.push(\n 'color:' + instance.opts.prefixColor + '; font-weight:bold;',\n '' // Empty string resets style.\n )\n } else {\n preparedOutput.push('[' + instance.prefix + '] ')\n }\n } else {\n preparedOutput.push('')\n }\n\n // Only first argument on `console` can have style.\n if (typeof args[0] === 'string') {\n if (instance.opts.markdown && isColorSupported()) {\n parsedMarkdown = parseMarkdown(args[0])\n preparedOutput[0] = preparedOutput[0] + parsedMarkdown.text\n preparedOutput = preparedOutput.concat(parsedMarkdown.styles)\n } else {\n preparedOutput[0] = preparedOutput[0] + args[0]\n }\n } else {\n preparedOutput[0] = args[0]\n }\n\n if (args.length > 1) {\n preparedOutput = preparedOutput.concat(args.splice(1))\n }\n\n return preparedOutput\n }\n\n function prepareOutputToNode (args, method, instance) {\n var preparedOutput = []\n\n if (instance.opts.prefix) {\n if (isColorSupported()) {\n preparedOutput[0] =\n '\\u001b[' + instance.opts.prefixColor[0] + 'm' +\n '\\u001b[' + ansiColors.modifiers.bold[0] + 'm' +\n instance.opts.prefix +\n '\\u001b[' + ansiColors.modifiers.bold[1] + 'm' +\n '\\u001b[' + instance.opts.prefixColor[1] + 'm'\n } else {\n preparedOutput[0] = '[' + instance.opts.prefix + ']'\n }\n }\n\n if (method === 'warn') {\n preparedOutput[0] =\n '\\u001b[' + ansiColors.colors.yellow[0] + 'm' +\n '⚠' +\n '\\u001b[' + ansiColors.colors.yellow[1] + 'm ' +\n (preparedOutput[0] || '')\n } else if (method === 'error') {\n preparedOutput[0] =\n '\\u001b[' + ansiColors.colors.red[0] + 'm' +\n '✖' +\n '\\u001b[' + ansiColors.colors.red[1] + 'm ' +\n (preparedOutput[0] || '')\n } else if (method === 'info') {\n preparedOutput[0] =\n '\\u001b[' + ansiColors.colors.blue[0] + 'm' +\n 'ℹ' +\n '\\u001b[' + ansiColors.colors.blue[1] + 'm ' +\n (preparedOutput[0] || '')\n } else if (method === 'debug') {\n preparedOutput[0] =\n '\\u001b[' + ansiColors.colors.gray[0] + 'm' +\n '🐛' +\n '\\u001b[' + ansiColors.colors.gray[1] + 'm ' +\n (preparedOutput[0] || '')\n }\n\n args.forEach(function (arg) {\n if (typeof arg === 'string') {\n if (instance.opts.markdown) {\n preparedOutput.push(parseMarkdown(arg).text)\n } else {\n preparedOutput.push(arg)\n }\n } else {\n preparedOutput.push(arg)\n }\n })\n\n return preparedOutput\n }\n\n function isDisabled (instance) {\n // Parsing `NODE_DEBUG` and `DEBUG` env var.\n // We verify `NODE_DEBUG` and `DEBUG` env vars on runtime so it is\n // easier to test.\n var envVar = null\n if (typeof process !== 'undefined' &&\n process.env !== undefined &&\n filterRegExps.length === 0) {\n // `NODE_DEBUG` has precedence over `DEBUG`\n if (process.env.NODE_DEBUG !== undefined &&\n process.env.NODE_DEBUG !== '') {\n envVar = 'NODE_DEBUG'\n } else if (process.env.DEBUG !== undefined &&\n process.env.DEBUG !== '') {\n envVar = 'DEBUG'\n }\n\n if (envVar) {\n Logdown.disable('*')\n process.env[envVar]\n .split(',')\n .forEach(function (regExp) {\n Logdown.enable(regExp)\n })\n }\n }\n\n // Now checks if instance is disabled\n var isDisabled_ = false\n filterRegExps.forEach(function (filter) {\n if (filter.type === 'enable' && filter.regExp.test(instance.opts.prefix)) {\n isDisabled_ = false\n } else if (filter.type === 'disable' &&\n filter.regExp.test(instance.opts.prefix)) {\n isDisabled_ = true\n }\n })\n\n return isDisabled_\n }\n\n function prepareRegExpForPrefixSearch (str) {\n return new RegExp('^' + str.replace(/\\*/g, '.*?') + '$')\n }\n\n function isPrefixAlreadyInUse (prefix, instances) {\n var isPrefixAlreadyInUse_ = false\n\n instances.forEach(function (instance) {\n if (instance.opts.prefix === prefix) {\n isPrefixAlreadyInUse_ = true\n return\n }\n })\n return isPrefixAlreadyInUse_\n }\n\n function getInstanceByPrefix (prefix, instances) {\n var instance\n\n instances.forEach(function (instanceCur) {\n if (instanceCur.opts.prefix === prefix) {\n instance = instanceCur\n return\n }\n })\n\n return instance\n }\n\n function sanitizeStringToBrowser (str) {\n if (typeof str === 'string') {\n return str.replace(/%c/g, '')\n } else {\n return str\n }\n }\n\n /**\n * Currently only WebKit-based Web Inspectors, Firefox >= v31,\n * and the Firebug extension (any Firefox version) are known\n * to support \"%c\" CSS customizations.\n *\n * Code took from https://github.com/visionmedia/debug/blob/master/browser.js\n */\n function isColorSupported () {\n if (isBrowser()) {\n // Is webkit? http://stackoverflow.com/a/16459606/376773\n var isWebkit = ('WebkitAppearance' in document.documentElement.style)\n // Is firebug? http://stackoverflow.com/a/398120/376773\n var isFirebug = (\n window.console &&\n (console.firebug || (console.exception && console.table))\n )\n // Is firefox >= v31?\n // https://developer.mozilla.org/en-US/docs/Tools/\n // Web_Console#Styling_messages\n var isFirefox31Plus = (\n navigator.userAgent.toLowerCase().match(/firefox\\/(\\d+)/) &&\n parseInt(RegExp.$1, 10) >= 31\n )\n\n return (isWebkit || isFirebug || isFirefox31Plus)\n } else if (isNode()) {\n if (process.stdout && !process.stdout.isTTY) {\n return false\n }\n\n if (process.platform === 'win32') {\n return true\n }\n\n if ('COLORTERM' in process.env) {\n return true\n }\n\n if (process.env.TERM === 'dumb') {\n return false\n }\n\n if (\n /^screen|^xterm|^vt100|color|ansi|cygwin|linux/i.test(process.env.TERM)\n ) {\n return true\n }\n\n return false\n }\n }\n\n function isNode () {\n return (\n typeof module !== 'undefined' &&\n typeof module.exports !== 'undefined'\n )\n }\n\n function isBrowser () {\n return (typeof window !== 'undefined')\n }\n\n var getNextPrefixColor = (function () {\n var lastUsed = 0\n var nodePrefixColors = [\n [31, 39], // red\n [32, 39], // green\n [33, 39], // yellow\n [34, 39], // blue\n [35, 39], // magenta\n [36, 39] // cyan\n ]\n\n return function () {\n lastUsed += 1\n return nodePrefixColors[lastUsed % nodePrefixColors.length]\n }\n })()\n\n // Export module\n if (isNode()) {\n module.exports = Logdown\n } else if (isBrowser()) {\n window.Logdown = Logdown\n }\n}())\n"],"sourceRoot":"/source/"} \ No newline at end of file +{"version":3,"sources":["logdown.js"],"names":["Logdown","prefix","opts","this","normalizeOpts","isPrefixAlreadyInUse","_instances","getInstanceByPrefix","push","alignPrefixes","sanitizeStringToBrowser","prefixColor","alignOutput","Boolean","markdown","undefined","isBrowser","colors","lastUsedColorIndex","length","isNode","getNextPrefixColor","instances","longest","sort","a","b","forEach","instance","padding","Array","Math","max","join","parseMarkdown","text","styles","match","getNextMatch","replace","rule","regexp","replacer","style","matches","rules","submatch1","ansiColors","modifiers","bold","italic","bgColors","bgYellow","black","index","prepareOutputToBrowser","args","parsedMarkdown","preparedOutput","isColorSupported","concat","splice","prepareOutputToNode","method","yellow","red","blue","gray","arg","isDisabled","envVar","process","env","filterRegExps","NODE_DEBUG","DEBUG","disable","split","regExp","enable","isDisabled_","filter","type","test","prepareRegExpForPrefixSearch","str","RegExp","isPrefixAlreadyInUse_","instanceCur","isWebkit","document","documentElement","isFirebug","window","console","firebug","exception","table","isFirefox31Plus","navigator","userAgent","toLowerCase","parseInt","$1","stdout","isTTY","platform","TERM","module","exports","reset","dim","underline","inverse","hidden","strikethrough","green","magenta","cyan","white","bgBlack","bgRed","bgGreen","bgBlue","bgMagenta","bgCyan","bgWhite","prototype","call","arguments","substr","methods","slice","Function","apply","log","lastUsed","nodePrefixColors"],"mappings":";;;;;;;;CAEA,WACA,YAmDA,SAAAA,GAAAC,EAAAC,GACA,MAAAC,gBAAAH,IAIAG,KAAAD,KAAAE,EAAAH,EAAAC,GAEAG,EAAAF,KAAAD,KAAAD,OAAAD,EAAAM,YACAC,EAAAJ,KAAAD,KAAAD,OAAAD,EAAAM,aAGAN,EAAAM,WAAAE,KAAAL,MACAM,EAAAT,EAAAM,YAEAH,OAZA,GAAAH,GAAAC,EAAAC,GAqGA,QAAAE,GAAAH,EAAAC,GACA,gBAAAD,KAAAC,EAAAD,GACAC,EAAAA,MAEA,gBAAAD,KAAAA,EAAAC,EAAAD,QAAA,IACAA,EAAAS,EAAAT,EAEA,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AAAH,EAAAC,EAAArD,MAKAkI,SAAAN,UAAAO,MAAAN,KACAlC,QAAA/B,IAAA+B,QAAAyC,IACAzC,QACApC,IAEAtC,MACAsC,EAAAI,EAAAN,EAAAO,EAAA5D,OACA2F,QAAA/B,IAAA+B,QAAAyC,KAAAD,MACAxC,QACApC,OAmYA,IAAArC,GAAA,WACA,GAAAmH,GAAA,EACAC,IACA,GAAA,KACA,GAAA,KACA,GAAA,KACA,GAAA,KACA,GAAA,KACA,GAAA,IAGA,OAAA,YAEA,MADAD,IAAA,EACAC,EAAAD,EAAAC,EAAAtH,WAKAC,KACAwF,OAAAC,QAAA7G,EACAgB,MACA6E,OAAA7F,QAAAA","file":"logdown.min.js","sourcesContent":["/**\n * logdown - Debug utility with markdown support that runs on browser and server\n *\n * @version v2.1.0\n * @link https://github.com/caiogondim/logdown\n * @author Caio Gondim (http://caiogondim.com)\n * @license MIT\n */\n/* global console, module, window, document, navigator, process */\n\n;(function () {\n 'use strict'\n\n var lastUsedColorIndex = 0\n // Solarized accent colors http://ethanschoonover.com/solarized\n var colors = [\n '#B58900',\n '#CB4B16',\n '#DC322F',\n '#D33682',\n '#6C71C4',\n '#268BD2',\n '#2AA198',\n '#859900'\n ]\n // Taken from ansi-styles npm module\n // https://github.com/sindresorhus/ansi-styles/blob/master/index.js\n var ansiColors = {\n modifiers: {\n reset: [0, 0],\n bold: [1, 22], // 21 isn't widely supported and 22 does the same thing\n dim: [2, 22],\n italic: [3, 23],\n underline: [4, 24],\n inverse: [7, 27],\n hidden: [8, 28],\n strikethrough: [9, 29]\n },\n colors: {\n black: [30, 39],\n red: [31, 39],\n green: [32, 39],\n yellow: [33, 39],\n blue: [34, 39],\n magenta: [35, 39],\n cyan: [36, 39],\n white: [37, 39],\n gray: [90, 39]\n },\n bgColors: {\n bgBlack: [40, 49],\n bgRed: [41, 49],\n bgGreen: [42, 49],\n bgYellow: [43, 49],\n bgBlue: [44, 49],\n bgMagenta: [45, 49],\n bgCyan: [46, 49],\n bgWhite: [47, 49]\n }\n }\n var filterRegExps = []\n\n function Logdown (prefix, opts) {\n if (!(this instanceof Logdown)) {\n return new Logdown(prefix, opts)\n }\n\n this.opts = normalizeOpts(prefix, opts)\n\n if (isPrefixAlreadyInUse(this.opts.prefix, Logdown._instances)) {\n return getInstanceByPrefix(this.opts.prefix, Logdown._instances)\n }\n\n Logdown._instances.push(this)\n alignPrefixes(Logdown._instances)\n\n return this\n }\n\n //\n // Static\n //\n\n Logdown._instances = []\n\n Logdown.enable = function () {\n Array.prototype.forEach.call(arguments, function (str) {\n if (str[0] === '-') {\n Logdown.disable(str.substr(1))\n }\n\n var regExp = prepareRegExpForPrefixSearch(str)\n\n if (str === '*') {\n filterRegExps = []\n } else {\n filterRegExps.push({\n type: 'enable',\n regExp: regExp\n })\n }\n })\n }\n\n Logdown.disable = function () {\n Array.prototype.forEach.call(arguments, function (str) {\n if (str[0] === '-') {\n Logdown.enable(str.substr(1))\n }\n\n var regExp = prepareRegExpForPrefixSearch(str)\n\n if (str === '*') {\n filterRegExps = [{\n type: 'disable',\n regExp: regExp\n }]\n } else {\n filterRegExps.push({\n type: 'disable',\n regExp: regExp\n })\n }\n })\n }\n\n //\n // Public\n //\n\n var methods = ['debug', 'log', 'info', 'warn', 'error']\n methods.forEach(function (method) {\n Logdown.prototype[method] = function () {\n if (isDisabled(this)) {\n return\n }\n\n var preparedOutput\n var args = Array.prototype.slice.call(arguments, 0)\n\n if (isBrowser()) {\n preparedOutput = prepareOutputToBrowser(args, this)\n\n // IE9 workaround\n // http://stackoverflow.com/questions/5538972/\n // console-log-apply-not-working-in-ie9\n Function.prototype.apply.call(\n console[method] || console.log,\n console,\n preparedOutput\n )\n } else if (isNode()) {\n preparedOutput = prepareOutputToNode(args, method, this)\n ;(console[method] || console.log).apply(\n console,\n preparedOutput\n )\n }\n }\n })\n\n //\n // Private\n //\n\n function normalizeOpts (prefix, opts) {\n if (typeof prefix === 'object') opts = prefix\n opts = opts || {}\n\n if (typeof prefix !== 'string') prefix = opts.prefix || ''\n prefix = sanitizeStringToBrowser(prefix)\n\n var alignOutput = Boolean(opts.alignOutput)\n var markdown = opts.markdown === undefined ? true : Boolean(opts.markdown)\n\n var prefixColor\n if (isBrowser()) {\n prefixColor = colors[lastUsedColorIndex % colors.length]\n lastUsedColorIndex += 1\n } else if (isNode()) {\n prefixColor = getNextPrefixColor()\n }\n\n return {\n prefix: prefix,\n alignOutput: alignOutput,\n markdown: markdown,\n prefixColor: prefixColor\n }\n }\n\n function alignPrefixes (instances) {\n var longest = instances.sort(function (a, b) {\n return b.opts.prefix.length - a.opts.prefix.length\n })[0]\n\n instances.forEach(function (instance) {\n if (instance.opts.alignOutput) {\n var padding = new Array(Math.max(longest.opts.prefix.length - instance.opts.prefix.length + 1, 0)).join(' ')\n instance.opts.prefix = instance.opts.prefix + padding\n }\n })\n }\n\n function parseMarkdown (text) {\n var styles = []\n var match = getNextMatch(text)\n\n while (match) {\n text = text.replace(match.rule.regexp, match.rule.replacer)\n\n if (isBrowser()) {\n styles.push(match.rule.style)\n styles.push('') // Empty string resets style.\n }\n\n match = getNextMatch(text)\n }\n\n return {text: text, styles: styles}\n }\n\n function getNextMatch (text) {\n var matches = []\n var rules = []\n if (isBrowser()) {\n rules = [\n {\n regexp: /\\*([^\\*]+)\\*/,\n replacer: function (match, submatch1) {\n return '%c' + submatch1 + '%c'\n },\n style: 'font-weight:bold;'\n },\n {\n regexp: /_([^_]+)_/,\n replacer: function (match, submatch1) {\n return '%c' + submatch1 + '%c'\n },\n style: 'font-style:italic;'\n },\n {\n regexp: /`([^`]+)`/,\n replacer: function (match, submatch1) {\n return '%c' + submatch1 + '%c'\n },\n style:\n 'background:#FDF6E3; ' +\n 'color:#586E75; ' +\n 'padding:1px 5px; ' +\n 'border-radius:4px;'\n }\n ]\n } else if (isNode()) {\n rules = [\n {\n regexp: /\\*([^\\*]+)\\*/,\n replacer: function (match, submatch1) {\n return '\\u001b[' + ansiColors.modifiers.bold[0] + 'm' +\n submatch1 +\n '\\u001b[' + ansiColors.modifiers.bold[1] + 'm'\n }\n },\n {\n regexp: /_([^_]+)_/,\n replacer: function (match, submatch1) {\n return '\\u001b[' + ansiColors.modifiers.italic[0] + 'm' +\n submatch1 +\n '\\u001b[' + ansiColors.modifiers.italic[1] + 'm'\n }\n },\n {\n regexp: /`([^`]+)`/,\n replacer: function (match, submatch1) {\n return '\\u001b[' + ansiColors.bgColors.bgYellow[0] + 'm' +\n '\\u001b[' + ansiColors.colors.black[0] + 'm' +\n ' ' + submatch1 + ' ' +\n '\\u001b[' + ansiColors.colors.black[1] + 'm' +\n '\\u001b[' + ansiColors.bgColors.bgYellow[1] + 'm'\n }\n }\n ]\n }\n\n //\n rules.forEach(function (rule) {\n var match = text.match(rule.regexp)\n if (match) {\n matches.push({\n rule: rule,\n match: match\n })\n }\n })\n if (matches.length === 0) {\n return null\n }\n\n //\n matches.sort(function (a, b) {\n return a.match.index - b.match.index\n })\n\n return matches[0]\n }\n\n function prepareOutputToBrowser (args, instance) {\n var preparedOutput = []\n var parsedMarkdown\n\n if (instance.opts.prefix) {\n if (isColorSupported()) {\n preparedOutput.push('%c' + instance.opts.prefix + '%c ')\n preparedOutput.push(\n 'color:' + instance.opts.prefixColor + '; font-weight:bold;',\n '' // Empty string resets style.\n )\n } else {\n preparedOutput.push('[' + instance.prefix + '] ')\n }\n } else {\n preparedOutput.push('')\n }\n\n // Only first argument on `console` can have style.\n if (typeof args[0] === 'string') {\n if (instance.opts.markdown && isColorSupported()) {\n parsedMarkdown = parseMarkdown(args[0])\n preparedOutput[0] = preparedOutput[0] + parsedMarkdown.text\n preparedOutput = preparedOutput.concat(parsedMarkdown.styles)\n } else {\n preparedOutput[0] = preparedOutput[0] + args[0]\n }\n } else {\n preparedOutput[0] = args[0]\n }\n\n if (args.length > 1) {\n preparedOutput = preparedOutput.concat(args.splice(1))\n }\n\n return preparedOutput\n }\n\n function prepareOutputToNode (args, method, instance) {\n var preparedOutput = []\n\n if (instance.opts.prefix) {\n if (isColorSupported()) {\n preparedOutput[0] =\n '\\u001b[' + instance.opts.prefixColor[0] + 'm' +\n '\\u001b[' + ansiColors.modifiers.bold[0] + 'm' +\n instance.opts.prefix +\n '\\u001b[' + ansiColors.modifiers.bold[1] + 'm' +\n '\\u001b[' + instance.opts.prefixColor[1] + 'm'\n } else {\n preparedOutput[0] = '[' + instance.opts.prefix + ']'\n }\n }\n\n if (method === 'warn') {\n preparedOutput[0] =\n '\\u001b[' + ansiColors.colors.yellow[0] + 'm' +\n '⚠' +\n '\\u001b[' + ansiColors.colors.yellow[1] + 'm ' +\n (preparedOutput[0] || '')\n } else if (method === 'error') {\n preparedOutput[0] =\n '\\u001b[' + ansiColors.colors.red[0] + 'm' +\n '✖' +\n '\\u001b[' + ansiColors.colors.red[1] + 'm ' +\n (preparedOutput[0] || '')\n } else if (method === 'info') {\n preparedOutput[0] =\n '\\u001b[' + ansiColors.colors.blue[0] + 'm' +\n 'ℹ' +\n '\\u001b[' + ansiColors.colors.blue[1] + 'm ' +\n (preparedOutput[0] || '')\n } else if (method === 'debug') {\n preparedOutput[0] =\n '\\u001b[' + ansiColors.colors.gray[0] + 'm' +\n '🐛' +\n '\\u001b[' + ansiColors.colors.gray[1] + 'm ' +\n (preparedOutput[0] || '')\n }\n\n args.forEach(function (arg) {\n if (typeof arg === 'string') {\n if (instance.opts.markdown) {\n preparedOutput.push(parseMarkdown(arg).text)\n } else {\n preparedOutput.push(arg)\n }\n } else {\n preparedOutput.push(arg)\n }\n })\n\n return preparedOutput\n }\n\n function isDisabled (instance) {\n // Parsing `NODE_DEBUG` and `DEBUG` env var.\n // We verify `NODE_DEBUG` and `DEBUG` env vars on runtime so it is\n // easier to test.\n var envVar = null\n if (typeof process !== 'undefined' &&\n process.env !== undefined &&\n filterRegExps.length === 0) {\n // `NODE_DEBUG` has precedence over `DEBUG`\n if (process.env.NODE_DEBUG !== undefined &&\n process.env.NODE_DEBUG !== '') {\n envVar = 'NODE_DEBUG'\n } else if (process.env.DEBUG !== undefined &&\n process.env.DEBUG !== '') {\n envVar = 'DEBUG'\n }\n\n if (envVar) {\n Logdown.disable('*')\n process.env[envVar]\n .split(',')\n .forEach(function (regExp) {\n Logdown.enable(regExp)\n })\n }\n }\n\n // Now checks if instance is disabled\n var isDisabled_ = false\n filterRegExps.forEach(function (filter) {\n if (filter.type === 'enable' && filter.regExp.test(instance.opts.prefix)) {\n isDisabled_ = false\n } else if (filter.type === 'disable' &&\n filter.regExp.test(instance.opts.prefix)) {\n isDisabled_ = true\n }\n })\n\n return isDisabled_\n }\n\n function prepareRegExpForPrefixSearch (str) {\n return new RegExp('^' + str.replace(/\\*/g, '.*?') + '$')\n }\n\n function isPrefixAlreadyInUse (prefix, instances) {\n var isPrefixAlreadyInUse_ = false\n\n instances.forEach(function (instance) {\n if (instance.opts.prefix === prefix) {\n isPrefixAlreadyInUse_ = true\n return\n }\n })\n return isPrefixAlreadyInUse_\n }\n\n function getInstanceByPrefix (prefix, instances) {\n var instance\n\n instances.forEach(function (instanceCur) {\n if (instanceCur.opts.prefix === prefix) {\n instance = instanceCur\n return\n }\n })\n\n return instance\n }\n\n function sanitizeStringToBrowser (str) {\n if (typeof str === 'string') {\n return str.replace(/%c/g, '')\n } else {\n return str\n }\n }\n\n /**\n * Currently only WebKit-based Web Inspectors, Firefox >= v31,\n * and the Firebug extension (any Firefox version) are known\n * to support \"%c\" CSS customizations.\n *\n * Code took from https://github.com/visionmedia/debug/blob/master/browser.js\n */\n function isColorSupported () {\n if (isBrowser()) {\n // Is webkit? http://stackoverflow.com/a/16459606/376773\n var isWebkit = ('WebkitAppearance' in document.documentElement.style)\n // Is firebug? http://stackoverflow.com/a/398120/376773\n var isFirebug = (\n window.console &&\n (console.firebug || (console.exception && console.table))\n )\n // Is firefox >= v31?\n // https://developer.mozilla.org/en-US/docs/Tools/\n // Web_Console#Styling_messages\n var isFirefox31Plus = (\n navigator.userAgent.toLowerCase().match(/firefox\\/(\\d+)/) &&\n parseInt(RegExp.$1, 10) >= 31\n )\n\n return (isWebkit || isFirebug || isFirefox31Plus)\n } else if (isNode()) {\n if (process.stdout && !process.stdout.isTTY) {\n return false\n }\n\n if (process.platform === 'win32') {\n return true\n }\n\n if ('COLORTERM' in process.env) {\n return true\n }\n\n if (process.env.TERM === 'dumb') {\n return false\n }\n\n if (\n /^screen|^xterm|^vt100|color|ansi|cygwin|linux/i.test(process.env.TERM)\n ) {\n return true\n }\n\n return false\n }\n }\n\n function isNode () {\n return (\n typeof module !== 'undefined' &&\n typeof module.exports !== 'undefined'\n )\n }\n\n function isBrowser () {\n return (typeof window !== 'undefined')\n }\n\n var getNextPrefixColor = (function () {\n var lastUsed = 0\n var nodePrefixColors = [\n [31, 39], // red\n [32, 39], // green\n [33, 39], // yellow\n [34, 39], // blue\n [35, 39], // magenta\n [36, 39] // cyan\n ]\n\n return function () {\n lastUsed += 1\n return nodePrefixColors[lastUsed % nodePrefixColors.length]\n }\n })()\n\n // Export module\n if (isNode()) {\n module.exports = Logdown\n } else if (isBrowser()) {\n window.Logdown = Logdown\n }\n}())\n"],"sourceRoot":"/source/"} \ No newline at end of file diff --git a/example/lib/logdown.js b/example/lib/logdown.js index b2c2c29..299ebcc 100644 --- a/example/lib/logdown.js +++ b/example/lib/logdown.js @@ -1,7 +1,7 @@ /** * logdown - Debug utility with markdown support that runs on browser and server * - * @version v2.0.3 + * @version v2.1.0 * @link https://github.com/caiogondim/logdown * @author Caio Gondim (http://caiogondim.com) * @license MIT diff --git a/package.json b/package.json index e818951..da89635 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "logdown", - "version": "2.0.3", + "version": "2.1.0", "description": "Debug utility with markdown support that runs on browser and server", "main": "dist/logdown.js", "types": "dist/logdown.d.ts",