UNPKG

bows

Version:

Rainbowed console logs for chrome, opera and firefox in development.

253 lines (213 loc) 7.31 kB
!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var f;"undefined"!=typeof window?f=window:"undefined"!=typeof global?f=global:"undefined"!=typeof self&&(f=self),f.bows=e()}}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ (function (process){ (function() { function checkColorSupport() { if (typeof window === 'undefined' || typeof navigator === 'undefined') { return false; } var chrome = !!window.chrome, firefox = /firefox/i.test(navigator.userAgent), firefoxVersion, electron = process && process.versions && process.versions.electron; if (firefox) { var match = navigator.userAgent.match(/Firefox\/(\d+\.\d+)/); if (match && match[1] && Number(match[1])) { firefoxVersion = Number(match[1]); } } return chrome || firefoxVersion >= 31.0 || electron; } function getLocalStorageSafely() { var localStorage; try { localStorage = window.localStorage; } catch (e) { // failed: access to localStorage is denied } return localStorage; } var yieldColor = function() { var goldenRatio = 0.618033988749895; hue += goldenRatio; hue = hue % 1; return hue * 360; }; var inNode = typeof window === 'undefined', ls = !inNode && getLocalStorageSafely(), debugKey = ls && ls.andlogKey ? ls.andlogKey : 'debug', debug = ls && ls[debugKey] ? ls[debugKey] : false, logger = require('andlog'), bind = Function.prototype.bind, hue = 0, padding = true, separator = '|', padLength = 15, noop = function() {}, // if ls.debugColors is set, use that, otherwise check for support colorsSupported = ls && ls.debugColors ? ls.debugColors !== 'false' : checkColorSupport(), bows = null, debugRegex = null, invertRegex = false, moduleColorsMap = {}; if (debug && debug[0] === '!' && debug[1] === '/') { invertRegex = true; debug = debug.slice(1); } debugRegex = debug && debug[0] === '/' && new RegExp(debug.substring(1, debug.length - 1)); var logLevels = ['log', 'debug', 'warn', 'error', 'info']; //Noop should noop for (var i = 0, ii = logLevels.length; i < ii; i++) { noop[logLevels[i]] = noop; } bows = function(str) { // If localStorage is not available just don't log if (!ls) return noop; var msg, colorString, logfn; if (padding) { msg = str.slice(0, padLength); msg += Array(padLength + 3 - msg.length).join(' ') + separator; } else { msg = str + Array(3).join(' ') + separator; } if (debugRegex) { var matches = str.match(debugRegex); if ((!invertRegex && !matches) || (invertRegex && matches)) return noop; } if (!bind) return noop; var logArgs = [logger]; if (colorsSupported) { if (!moduleColorsMap[str]) { moduleColorsMap[str] = yieldColor(); } var color = moduleColorsMap[str]; msg = '%c' + msg; colorString = 'color: hsl(' + color + ',99%,40%); font-weight: bold'; logArgs.push(msg, colorString); } else { logArgs.push(msg); } if (arguments.length > 1) { var args = Array.prototype.slice.call(arguments, 1); logArgs = logArgs.concat(args); } logfn = bind.apply(logger.log, logArgs); logLevels.forEach(function(f) { logfn[f] = bind.apply(logger[f] || logfn, logArgs); }); return logfn; }; bows.config = function(config) { if (config.padLength) { padLength = config.padLength; } if (typeof config.padding === 'boolean') { padding = config.padding; } if (config.separator) { separator = config.separator; } else if (config.separator === false || config.separator === '') { separator = ''; } }; if (typeof module !== 'undefined') { module.exports = bows; } else { window.bows = bows; } }.call()); }).call(this,require('_process')) },{"_process":3,"andlog":2}],2:[function(require,module,exports){ // follow @HenrikJoreteg and @andyet if you like this ;) (function () { function getLocalStorageSafely() { var localStorage; try { localStorage = window.localStorage; } catch (e) { // failed: access to localStorage is denied } return localStorage; } var inNode = typeof window === 'undefined', ls = !inNode && getLocalStorageSafely(), out = {}; if (inNode || !ls) { module.exports = console; return; } var andlogKey = ls.andlogKey || 'debug' if (ls && ls[andlogKey] && window.console) { out = window.console; } else { var methods = "assert,count,debug,dir,dirxml,error,exception,group,groupCollapsed,groupEnd,info,log,markTimeline,profile,profileEnd,time,timeEnd,trace,warn".split(","), l = methods.length, fn = function () {}; while (l--) { out[methods[l]] = fn; } } if (typeof exports !== 'undefined') { module.exports = out; } else { window.console = out; } })(); },{}],3:[function(require,module,exports){ // shim for using process in browser var process = module.exports = {}; process.nextTick = (function () { var canSetImmediate = typeof window !== 'undefined' && window.setImmediate; var canPost = typeof window !== 'undefined' && window.postMessage && window.addEventListener ; if (canSetImmediate) { return function (f) { return window.setImmediate(f) }; } if (canPost) { var queue = []; window.addEventListener('message', function (ev) { var source = ev.source; if ((source === window || source === null) && ev.data === 'process-tick') { ev.stopPropagation(); if (queue.length > 0) { var fn = queue.shift(); fn(); } } }, true); return function nextTick(fn) { queue.push(fn); window.postMessage('process-tick', '*'); }; } return function nextTick(fn) { setTimeout(fn, 0); }; })(); process.title = 'browser'; process.browser = true; process.env = {}; process.argv = []; function noop() {} process.on = noop; process.addListener = noop; process.once = noop; process.off = noop; process.removeListener = noop; process.removeAllListeners = noop; process.emit = noop; process.binding = function (name) { throw new Error('process.binding is not supported'); } // TODO(shtylman) process.cwd = function () { return '/' }; process.chdir = function (dir) { throw new Error('process.chdir is not supported'); }; },{}]},{},[1])(1) });