diff --git a/CHANGELOG.md b/CHANGELOG.md index 4b730d8..a366865 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,8 @@ 2016-02-02 ========== + * docs: Update changelog + * fix: Add dist to package.json file * fix: Add files to package.json so the new npm install won't use tape anymore * Merge branch 'master' of https://github.com/edravis/logatim * chore: Remove post install script diff --git a/dist/logatim.amd.min.js b/dist/logatim.amd.min.js index d0bfa61..032b70c 100644 --- a/dist/logatim.amd.min.js +++ b/dist/logatim.amd.min.js @@ -1,368 +1 @@ -define("logatim", [], function() { return /******/ (function(modules) { // webpackBootstrap -/******/ // The module cache -/******/ var installedModules = {}; - -/******/ // The require function -/******/ function __webpack_require__(moduleId) { - -/******/ // Check if module is in cache -/******/ if(installedModules[moduleId]) -/******/ return installedModules[moduleId].exports; - -/******/ // Create a new module (and put it into the cache) -/******/ var module = installedModules[moduleId] = { -/******/ exports: {}, -/******/ id: moduleId, -/******/ loaded: false -/******/ }; - -/******/ // Execute the module function -/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); - -/******/ // Flag the module as loaded -/******/ module.loaded = true; - -/******/ // Return the exports of the module -/******/ return module.exports; -/******/ } - - -/******/ // expose the modules object (__webpack_modules__) -/******/ __webpack_require__.m = modules; - -/******/ // expose the module cache -/******/ __webpack_require__.c = installedModules; - -/******/ // __webpack_public_path__ -/******/ __webpack_require__.p = ""; - -/******/ // Load entry module and return exports -/******/ return __webpack_require__(0); -/******/ }) -/************************************************************************/ -/******/ ([ -/* 0 */ -/***/ function(module, exports, __webpack_require__) { - - 'use strict'; - - module.exports = __webpack_require__(1)(); - -/***/ }, -/* 1 */ -/***/ function(module, exports, __webpack_require__) { - - 'use strict'; - - var constants = __webpack_require__(2); - var levels = __webpack_require__(3); - var logs = __webpack_require__(4); - var isNode = __webpack_require__(5); - - var currentLevel = constants.DEFAULT_LEVEL; - - var logatim = module.exports = function (str) { - if (str) logs.addChunk({ key: 'str', val: str }); - - var speaker = function speaker(message) { - return logatim(message); - }; - - // Leveling - speaker.setEnv = function (env) { - return isNode = env === 'node'; - }; - speaker.getLevel = function () { - return levels.getLevel(currentLevel); - }; - speaker.setLevel = function (level) { - currentLevel = levels.setLevel(level, isNode); - logs.updateLogMethods(speaker, currentLevel); - }; - - Object.keys(constants.STYLES).forEach(function (styleName) { - Object.defineProperty(speaker, styleName, { - get: function get() { - logs.addChunk({ key: 'style', val: styleName }); - return logatim(); - } - }); - }); - - // Get the unformatted message - speaker.raw = logs.raw.bind(null, isNode); - - // Refresh reachable methods - speaker.setLevel(levels.getPersistedLevel(isNode) || currentLevel); - logs.updateLogMethods(speaker, currentLevel, isNode, logatim); - - return speaker; - }; - -/***/ }, -/* 2 */ -/***/ function(module, exports) { - - 'use strict'; - - var constants = module.exports = {}; - - constants.DEFAULT_LEVEL = 3; // WARN - constants.EOL = '\u001b[49m\u001b[0m'; // bgColor and rest of styles - constants.LEVELS = { - TRACE: 0, - DEBUG: 1, - INFO: 2, - WARN: 3, - ERROR: 4, - SILENT: 5 - }; - constants.LEVELS_KEYS = Object.keys(constants.LEVELS); - constants.STORAGE_KEY = 'logatimLevel'; - constants.STYLES = { - // sets - bold: { ansi: '\u001b[1m', css: 'font-weight: 900' }, - dim: { ansi: '\u001b[2m', css: 'opacity: .8' }, - italic: { ansi: '\u001b[3m', css: 'font-style: italic' }, - underline: { ansi: '\u001b[4m', css: 'text-decoration: underline' }, - blink: { ansi: '\u001b[5m', css: 'text-decoration: blink' }, - inverse: { ansi: '\u001b[7m', css: '-moz-filter: invert(100%); -webkit-filter: invert(100%); filter: invert(100%)' }, - hidden: { ansi: '\u001b[8m', css: 'visibility: hidden' }, - strikethrough: { ansi: '\u001b[9m', css: 'text-decoration: line-through' }, - // colors - black: { ansi: '\u001b[30m', css: 'color: #333' }, - red: { ansi: '\u001b[31m', css: 'color: #e74c3c' }, - green: { ansi: '\u001b[32m', css: 'color: #2ecc71' }, - yellow: { ansi: '\u001b[33m', css: 'color: #f1c40f' }, - blue: { ansi: '\u001b[34m', css: 'color: #3498db' }, - magenta: { ansi: '\u001b[35m', css: 'color: #8e44ad' }, - cyan: { ansi: '\u001b[36m', css: 'color: #00FFFF' }, - white: { ansi: '\u001b[37m', css: 'color: #fff' }, - gray: { ansi: '\u001b[90m', css: 'color: #7f8c8d' }, - grey: { ansi: '\u001b[90m', css: 'color: #7f8c8d' }, - // background colors - bgBlack: { ansi: '\u001b[40m', css: 'background-color: #333' }, - bgRed: { ansi: '\u001b[41m', css: 'background-color: #e74c3c' }, - bgGreen: { ansi: '\u001b[42m', css: 'background-color: #2ecc71' }, - bgYellow: { ansi: '\u001b[43m', css: 'background-color: #f1c40f' }, - bgBlue: { ansi: '\u001b[44m', css: 'background-color: #3498db' }, - bgMagenta: { ansi: '\u001b[45m', css: 'background-color: #8e44ad' }, - bgCyan: { ansi: '\u001b[46m', css: 'background-color: #00ffff' }, - bgWhite: { ansi: '\u001b[47m', css: 'background-color: #fff' }, - bgGray: { ansi: '\u001b[47m', css: 'background-color: #7f8c8d' }, - bgGrey: { ansi: '\u001b[47m', css: 'background-color: #7f8c8d' } - }; - -/***/ }, -/* 3 */ -/***/ function(module, exports, __webpack_require__) { - - 'use strict'; - - var constants = __webpack_require__(2); - - var levels = module.exports = {}; - - levels.getLevel = function (level) { - return constants.LEVELS_KEYS[level]; - }; - - levels.setLevel = function (level, isNode) { - if (typeof level === 'string' && constants.LEVELS[level.toUpperCase()] !== undefined) { - level = constants.LEVELS[level.toUpperCase()]; - } - - if (typeof level === 'number' && level >= 0 && level <= constants.LEVELS.SILENT) { - levels.persistLevel(level, isNode); - - return level; - } else { - throw new Error('logatim.setLevel() called with invalid level: ' + level); - } - }; - - levels.persistLevel = function (levelNum, isNode) { - var levelName = constants.LEVELS_KEYS[levelNum] || 'SILENT'; - var sk = constants.STORAGE_KEY; - - // server side - if (isNode) { - GLOBAL[sk] = levelName; - } else { - // front side - // Use localStorage if available - try { - window.localStorage[sk] = levelName; - } catch (ignore) {} - - // Use session cookie as fallback - try { - window.document.cookie = encodeURIComponent(sk) + '=' + levelName + ';'; - } catch (ignore) {} - } - }; - - levels.getPersistedLevel = function (isNode) { - var storedLevel = undefined; - var sk = constants.STORAGE_KEY; - - // server side - if (isNode) { - storedLevel = GLOBAL[sk]; - } else { - // front side - // try to get it from localStorage - try { - storedLevel = window.localStorage[sk]; - } catch (ignore) {} - - // if fails look for it on the cookies document - if (typeof storedLevel === 'undefined') { - try { - var cookie = window.document.cookie; - var location = cookie.indexOf(encodeURIComponent(sk) + '='); - - if (location) storedLevel = /^([^;]+)/.exec(cookie.slice(location))[1]; - } catch (ignore) {} - } - - // if everything fails return undefined, like nothing happened - if (constants.LEVELS[storedLevel] === undefined) { - storedLevel = undefined; - } - } - - return storedLevel; - }; - -/***/ }, -/* 4 */ -/***/ function(module, exports, __webpack_require__) { - - 'use strict'; - - var constants = __webpack_require__(2); - - var chunking = []; - - var reset = function reset(logatim) { - chunking = []; - return logatim(); - }; - - var log = function log(level, isNode, logatim) { - var message = Array.prototype.slice.call(arguments, 3).join(' '); - var output = buildOutput(message, isNode); - - isNode ? console[level](output) : console[level].apply(console, output); - - return reset(logatim); - }; - - var buildOutput = function buildOutput(message, isNode) { - return isNode ? buildOutputNode([message]) : buildOutputBrowser(message); - }; - - var buildOutputNode = function buildOutputNode(message) { - chunking.reverse().forEach(function (chunk) { - var val = chunk.val; - - if (chunk.key === 'style') { - val = constants.STYLES[val].ansi; - } - - message = [val].concat(message); - }); - - return '' + message.join('') + constants.EOL; - }; - - /** - * Return an array as the following: - * ['%cMessage1 %cMessage2', 'css style', 'as many as messages'] - * expressed as: - * [ [messages], [styles] ] - * The styleHolder variable represents the concatenation of different styles for a single message. - */ - var buildOutputBrowser = function buildOutputBrowser(message) { - var styles = []; - var styleHolder = []; - var messages = []; - - chunking.forEach(function (chunk, idx) { - var val = chunk.val; - - if (chunk.key === 'str') { - val = '%c' + val; - messages.push(val); - - // if we stacked styles it's time to append them to the styles array - if (styleHolder.length !== 0) { - styles.push(styleHolder.join(';')); - styleHolder = []; - } - } else if (chunk.key === 'style') { - val = constants.STYLES[val].css; - - // stack styles - styleHolder.push(val); - } - }); - - // resolve pending styles - if (styleHolder.length !== 0) { - styles.push(styleHolder.join(';')); - styleHolder = []; - } - - // if there's an inputed message add it to the messages array - if (message) { - var chunk = chunking[chunking.length - 1]; - - // if the message has the same styles as the last message don't add the %c - if (chunk && chunk.key === 'style') { - message = '%c' + message; - } - - messages.push(message); - } - - return [messages.join('')].concat(styles); - }; - - var logs = module.exports = {}; - - logs.addChunk = function (chunk) { - return chunking.push(chunk); - }; - - logs.raw = function (isNode, message) { - var currentRaw = buildOutput(message, isNode); - chunking = []; - - return currentRaw; - }; - - logs.updateLogMethods = function (speaker, currentLevel, isNode, logatim) { - constants.LEVELS_KEYS.forEach(function (level, idx) { - level = level.toLowerCase();idx >= currentLevel ? speaker[level] = log.bind(null, level, isNode, logatim) : speaker[level] = function noop() { - return reset(logatim); - }; - }); - }; - -/***/ }, -/* 5 */ -/***/ function(module, exports) { - - /* WEBPACK VAR INJECTION */(function(global) {module.exports = false; - - // Only Node.JS has a process variable that is of [[Class]] process - try { - module.exports = Object.prototype.toString.call(global.process) === '[object process]' - } catch(e) {} - - /* WEBPACK VAR INJECTION */}.call(exports, (function() { return this; }()))) - -/***/ } -/******/ ])});; \ No newline at end of file +define("logatim",[],function(){return function(e){function n(t){if(o[t])return o[t].exports;var r=o[t]={exports:{},id:t,loaded:!1};return e[t].call(r.exports,r,r.exports,n),r.loaded=!0,r.exports}var o={};return n.m=e,n.c=o,n.p="",n(0)}([function(e,n,o){"use strict";e.exports=o(3)()},function(e,n){"use strict";var o=e.exports={};o.DEFAULT_LEVEL=3,o.EOL="",o.LEVELS={TRACE:0,DEBUG:1,INFO:2,WARN:3,ERROR:4,SILENT:5},o.LEVELS_KEYS=Object.keys(o.LEVELS),o.STORAGE_KEY="logatimLevel",o.STYLES={bold:{ansi:"",css:"font-weight: 900"},dim:{ansi:"",css:"opacity: .8"},italic:{ansi:"",css:"font-style: italic"},underline:{ansi:"",css:"text-decoration: underline"},blink:{ansi:"",css:"text-decoration: blink"},inverse:{ansi:"",css:"-moz-filter: invert(100%); -webkit-filter: invert(100%); filter: invert(100%)"},hidden:{ansi:"",css:"visibility: hidden"},strikethrough:{ansi:"",css:"text-decoration: line-through"},black:{ansi:"",css:"color: #333"},red:{ansi:"",css:"color: #e74c3c"},green:{ansi:"",css:"color: #2ecc71"},yellow:{ansi:"",css:"color: #f1c40f"},blue:{ansi:"",css:"color: #3498db"},magenta:{ansi:"",css:"color: #8e44ad"},cyan:{ansi:"",css:"color: #00FFFF"},white:{ansi:"",css:"color: #fff"},gray:{ansi:"",css:"color: #7f8c8d"},grey:{ansi:"",css:"color: #7f8c8d"},bgBlack:{ansi:"",css:"background-color: #333"},bgRed:{ansi:"",css:"background-color: #e74c3c"},bgGreen:{ansi:"",css:"background-color: #2ecc71"},bgYellow:{ansi:"",css:"background-color: #f1c40f"},bgBlue:{ansi:"",css:"background-color: #3498db"},bgMagenta:{ansi:"",css:"background-color: #8e44ad"},bgCyan:{ansi:"",css:"background-color: #00ffff"},bgWhite:{ansi:"",css:"background-color: #fff"},bgGray:{ansi:"",css:"background-color: #7f8c8d"},bgGrey:{ansi:"",css:"background-color: #7f8c8d"}}},function(e,n,o){"use strict";var t=o(1),r=e.exports={};r.getLevel=function(e){return t.LEVELS_KEYS[e]},r.setLevel=function(e,n){if("string"==typeof e&&void 0!==t.LEVELS[e.toUpperCase()]&&(e=t.LEVELS[e.toUpperCase()]),"number"==typeof e&&e>=0&&e<=t.LEVELS.SILENT)return r.persistLevel(e,n),e;throw new Error("logatim.setLevel() called with invalid level: "+e)},r.persistLevel=function(e,n){var o=t.LEVELS_KEYS[e]||"SILENT",r=t.STORAGE_KEY;if(n)GLOBAL[r]=o;else{try{window.localStorage[r]=o}catch(c){}try{window.document.cookie=encodeURIComponent(r)+"="+o+";"}catch(c){}}},r.getPersistedLevel=function(e){var n=void 0,o=t.STORAGE_KEY;if(e)n=GLOBAL[o];else{try{n=window.localStorage[o]}catch(r){}if("undefined"==typeof n)try{var c=window.document.cookie,s=c.indexOf(encodeURIComponent(o)+"=");s&&(n=/^([^;]+)/.exec(c.slice(s))[1])}catch(r){}void 0===t.LEVELS[n]&&(n=void 0)}return n}},function(e,n,o){"use strict";var t=o(1),r=o(2),c=o(4),s=o(5),i=t.DEFAULT_LEVEL,a=e.exports=function(e){e&&c.addChunk({key:"str",val:e});var n=function(e){return a(e)};return n.getLevel=function(){return r.getLevel(i)},n.setLevel=function(e){i=r.setLevel(e,s),n.raw=c.raw.bind(null,s),c.updateLogMethods(n,i)},n.setEnv=function(e){s="node"===e,n.raw=c.raw.bind(null,s),c.updateLogMethods(n,i)},Object.keys(t.STYLES).forEach(function(e){Object.defineProperty(n,e,{get:function(){return c.addChunk({key:"style",val:e}),a()}})}),n.raw=c.raw.bind(null,s),n.setLevel(r.getPersistedLevel(s)||i),c.updateLogMethods(n,i,s,a),n}},function(e,n,o){"use strict";var t=o(1),r=[],c=function(e){return r=[],e()},s=function(e,n,o){var t=Array.prototype.slice.call(arguments,3).join(" "),r=i(t,n);return n?console[e](r):console[e].apply(console,r),c(o)},i=function(e,n){return n?a([e]):l(e)},a=function(e){return r.reverse().forEach(function(n){var o=n.val;"style"===n.key&&(o=t.STYLES[o].ansi),e=[o].concat(e)}),""+e.join("")+t.EOL},l=function(e){var n=[],o=[],c=[];if(r.forEach(function(e,r){var s=e.val;"str"===e.key?(s="%c"+s,c.push(s),0!==o.length&&(n.push(o.join(";")),o=[])):"style"===e.key&&(s=t.STYLES[s].css,o.push(s))}),0!==o.length&&(n.push(o.join(";")),o=[]),e){var s=r[r.length-1];s&&"style"===s.key&&(e="%c"+e),c.push(e)}return[c.join("")].concat(n)},u=e.exports={};u.addChunk=function(e){return r.push(e)},u.raw=function(e,n){var o=i(n,e);return r=[],o},u.updateLogMethods=function(e,n,o,r){t.LEVELS_KEYS.forEach(function(t,i){t=t.toLowerCase(),i>=n?e[t]=s.bind(null,t,o,r):e[t]=function(){return c(r)}})}},function(e,n){(function(n){e.exports=!1;try{e.exports="[object process]"===Object.prototype.toString.call(n.process)}catch(o){}}).call(n,function(){return this}())}])}); \ No newline at end of file diff --git a/dist/logatim.commonjs2.min.js b/dist/logatim.commonjs2.min.js index ddaa0fe..9edb650 100644 --- a/dist/logatim.commonjs2.min.js +++ b/dist/logatim.commonjs2.min.js @@ -1,369 +1 @@ -module.exports = -/******/ (function(modules) { // webpackBootstrap -/******/ // The module cache -/******/ var installedModules = {}; - -/******/ // The require function -/******/ function __webpack_require__(moduleId) { - -/******/ // Check if module is in cache -/******/ if(installedModules[moduleId]) -/******/ return installedModules[moduleId].exports; - -/******/ // Create a new module (and put it into the cache) -/******/ var module = installedModules[moduleId] = { -/******/ exports: {}, -/******/ id: moduleId, -/******/ loaded: false -/******/ }; - -/******/ // Execute the module function -/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); - -/******/ // Flag the module as loaded -/******/ module.loaded = true; - -/******/ // Return the exports of the module -/******/ return module.exports; -/******/ } - - -/******/ // expose the modules object (__webpack_modules__) -/******/ __webpack_require__.m = modules; - -/******/ // expose the module cache -/******/ __webpack_require__.c = installedModules; - -/******/ // __webpack_public_path__ -/******/ __webpack_require__.p = ""; - -/******/ // Load entry module and return exports -/******/ return __webpack_require__(0); -/******/ }) -/************************************************************************/ -/******/ ([ -/* 0 */ -/***/ function(module, exports, __webpack_require__) { - - 'use strict'; - - module.exports = __webpack_require__(1)(); - -/***/ }, -/* 1 */ -/***/ function(module, exports, __webpack_require__) { - - 'use strict'; - - var constants = __webpack_require__(2); - var levels = __webpack_require__(3); - var logs = __webpack_require__(4); - var isNode = __webpack_require__(5); - - var currentLevel = constants.DEFAULT_LEVEL; - - var logatim = module.exports = function (str) { - if (str) logs.addChunk({ key: 'str', val: str }); - - var speaker = function speaker(message) { - return logatim(message); - }; - - // Leveling - speaker.setEnv = function (env) { - return isNode = env === 'node'; - }; - speaker.getLevel = function () { - return levels.getLevel(currentLevel); - }; - speaker.setLevel = function (level) { - currentLevel = levels.setLevel(level, isNode); - logs.updateLogMethods(speaker, currentLevel); - }; - - Object.keys(constants.STYLES).forEach(function (styleName) { - Object.defineProperty(speaker, styleName, { - get: function get() { - logs.addChunk({ key: 'style', val: styleName }); - return logatim(); - } - }); - }); - - // Get the unformatted message - speaker.raw = logs.raw.bind(null, isNode); - - // Refresh reachable methods - speaker.setLevel(levels.getPersistedLevel(isNode) || currentLevel); - logs.updateLogMethods(speaker, currentLevel, isNode, logatim); - - return speaker; - }; - -/***/ }, -/* 2 */ -/***/ function(module, exports) { - - 'use strict'; - - var constants = module.exports = {}; - - constants.DEFAULT_LEVEL = 3; // WARN - constants.EOL = '\u001b[49m\u001b[0m'; // bgColor and rest of styles - constants.LEVELS = { - TRACE: 0, - DEBUG: 1, - INFO: 2, - WARN: 3, - ERROR: 4, - SILENT: 5 - }; - constants.LEVELS_KEYS = Object.keys(constants.LEVELS); - constants.STORAGE_KEY = 'logatimLevel'; - constants.STYLES = { - // sets - bold: { ansi: '\u001b[1m', css: 'font-weight: 900' }, - dim: { ansi: '\u001b[2m', css: 'opacity: .8' }, - italic: { ansi: '\u001b[3m', css: 'font-style: italic' }, - underline: { ansi: '\u001b[4m', css: 'text-decoration: underline' }, - blink: { ansi: '\u001b[5m', css: 'text-decoration: blink' }, - inverse: { ansi: '\u001b[7m', css: '-moz-filter: invert(100%); -webkit-filter: invert(100%); filter: invert(100%)' }, - hidden: { ansi: '\u001b[8m', css: 'visibility: hidden' }, - strikethrough: { ansi: '\u001b[9m', css: 'text-decoration: line-through' }, - // colors - black: { ansi: '\u001b[30m', css: 'color: #333' }, - red: { ansi: '\u001b[31m', css: 'color: #e74c3c' }, - green: { ansi: '\u001b[32m', css: 'color: #2ecc71' }, - yellow: { ansi: '\u001b[33m', css: 'color: #f1c40f' }, - blue: { ansi: '\u001b[34m', css: 'color: #3498db' }, - magenta: { ansi: '\u001b[35m', css: 'color: #8e44ad' }, - cyan: { ansi: '\u001b[36m', css: 'color: #00FFFF' }, - white: { ansi: '\u001b[37m', css: 'color: #fff' }, - gray: { ansi: '\u001b[90m', css: 'color: #7f8c8d' }, - grey: { ansi: '\u001b[90m', css: 'color: #7f8c8d' }, - // background colors - bgBlack: { ansi: '\u001b[40m', css: 'background-color: #333' }, - bgRed: { ansi: '\u001b[41m', css: 'background-color: #e74c3c' }, - bgGreen: { ansi: '\u001b[42m', css: 'background-color: #2ecc71' }, - bgYellow: { ansi: '\u001b[43m', css: 'background-color: #f1c40f' }, - bgBlue: { ansi: '\u001b[44m', css: 'background-color: #3498db' }, - bgMagenta: { ansi: '\u001b[45m', css: 'background-color: #8e44ad' }, - bgCyan: { ansi: '\u001b[46m', css: 'background-color: #00ffff' }, - bgWhite: { ansi: '\u001b[47m', css: 'background-color: #fff' }, - bgGray: { ansi: '\u001b[47m', css: 'background-color: #7f8c8d' }, - bgGrey: { ansi: '\u001b[47m', css: 'background-color: #7f8c8d' } - }; - -/***/ }, -/* 3 */ -/***/ function(module, exports, __webpack_require__) { - - 'use strict'; - - var constants = __webpack_require__(2); - - var levels = module.exports = {}; - - levels.getLevel = function (level) { - return constants.LEVELS_KEYS[level]; - }; - - levels.setLevel = function (level, isNode) { - if (typeof level === 'string' && constants.LEVELS[level.toUpperCase()] !== undefined) { - level = constants.LEVELS[level.toUpperCase()]; - } - - if (typeof level === 'number' && level >= 0 && level <= constants.LEVELS.SILENT) { - levels.persistLevel(level, isNode); - - return level; - } else { - throw new Error('logatim.setLevel() called with invalid level: ' + level); - } - }; - - levels.persistLevel = function (levelNum, isNode) { - var levelName = constants.LEVELS_KEYS[levelNum] || 'SILENT'; - var sk = constants.STORAGE_KEY; - - // server side - if (isNode) { - GLOBAL[sk] = levelName; - } else { - // front side - // Use localStorage if available - try { - window.localStorage[sk] = levelName; - } catch (ignore) {} - - // Use session cookie as fallback - try { - window.document.cookie = encodeURIComponent(sk) + '=' + levelName + ';'; - } catch (ignore) {} - } - }; - - levels.getPersistedLevel = function (isNode) { - var storedLevel = undefined; - var sk = constants.STORAGE_KEY; - - // server side - if (isNode) { - storedLevel = GLOBAL[sk]; - } else { - // front side - // try to get it from localStorage - try { - storedLevel = window.localStorage[sk]; - } catch (ignore) {} - - // if fails look for it on the cookies document - if (typeof storedLevel === 'undefined') { - try { - var cookie = window.document.cookie; - var location = cookie.indexOf(encodeURIComponent(sk) + '='); - - if (location) storedLevel = /^([^;]+)/.exec(cookie.slice(location))[1]; - } catch (ignore) {} - } - - // if everything fails return undefined, like nothing happened - if (constants.LEVELS[storedLevel] === undefined) { - storedLevel = undefined; - } - } - - return storedLevel; - }; - -/***/ }, -/* 4 */ -/***/ function(module, exports, __webpack_require__) { - - 'use strict'; - - var constants = __webpack_require__(2); - - var chunking = []; - - var reset = function reset(logatim) { - chunking = []; - return logatim(); - }; - - var log = function log(level, isNode, logatim) { - var message = Array.prototype.slice.call(arguments, 3).join(' '); - var output = buildOutput(message, isNode); - - isNode ? console[level](output) : console[level].apply(console, output); - - return reset(logatim); - }; - - var buildOutput = function buildOutput(message, isNode) { - return isNode ? buildOutputNode([message]) : buildOutputBrowser(message); - }; - - var buildOutputNode = function buildOutputNode(message) { - chunking.reverse().forEach(function (chunk) { - var val = chunk.val; - - if (chunk.key === 'style') { - val = constants.STYLES[val].ansi; - } - - message = [val].concat(message); - }); - - return '' + message.join('') + constants.EOL; - }; - - /** - * Return an array as the following: - * ['%cMessage1 %cMessage2', 'css style', 'as many as messages'] - * expressed as: - * [ [messages], [styles] ] - * The styleHolder variable represents the concatenation of different styles for a single message. - */ - var buildOutputBrowser = function buildOutputBrowser(message) { - var styles = []; - var styleHolder = []; - var messages = []; - - chunking.forEach(function (chunk, idx) { - var val = chunk.val; - - if (chunk.key === 'str') { - val = '%c' + val; - messages.push(val); - - // if we stacked styles it's time to append them to the styles array - if (styleHolder.length !== 0) { - styles.push(styleHolder.join(';')); - styleHolder = []; - } - } else if (chunk.key === 'style') { - val = constants.STYLES[val].css; - - // stack styles - styleHolder.push(val); - } - }); - - // resolve pending styles - if (styleHolder.length !== 0) { - styles.push(styleHolder.join(';')); - styleHolder = []; - } - - // if there's an inputed message add it to the messages array - if (message) { - var chunk = chunking[chunking.length - 1]; - - // if the message has the same styles as the last message don't add the %c - if (chunk && chunk.key === 'style') { - message = '%c' + message; - } - - messages.push(message); - } - - return [messages.join('')].concat(styles); - }; - - var logs = module.exports = {}; - - logs.addChunk = function (chunk) { - return chunking.push(chunk); - }; - - logs.raw = function (isNode, message) { - var currentRaw = buildOutput(message, isNode); - chunking = []; - - return currentRaw; - }; - - logs.updateLogMethods = function (speaker, currentLevel, isNode, logatim) { - constants.LEVELS_KEYS.forEach(function (level, idx) { - level = level.toLowerCase();idx >= currentLevel ? speaker[level] = log.bind(null, level, isNode, logatim) : speaker[level] = function noop() { - return reset(logatim); - }; - }); - }; - -/***/ }, -/* 5 */ -/***/ function(module, exports) { - - /* WEBPACK VAR INJECTION */(function(global) {module.exports = false; - - // Only Node.JS has a process variable that is of [[Class]] process - try { - module.exports = Object.prototype.toString.call(global.process) === '[object process]' - } catch(e) {} - - /* WEBPACK VAR INJECTION */}.call(exports, (function() { return this; }()))) - -/***/ } -/******/ ]); \ No newline at end of file +module.exports=function(e){function n(t){if(o[t])return o[t].exports;var r=o[t]={exports:{},id:t,loaded:!1};return e[t].call(r.exports,r,r.exports,n),r.loaded=!0,r.exports}var o={};return n.m=e,n.c=o,n.p="",n(0)}([function(e,n,o){"use strict";e.exports=o(3)()},function(e,n){"use strict";var o=e.exports={};o.DEFAULT_LEVEL=3,o.EOL="",o.LEVELS={TRACE:0,DEBUG:1,INFO:2,WARN:3,ERROR:4,SILENT:5},o.LEVELS_KEYS=Object.keys(o.LEVELS),o.STORAGE_KEY="logatimLevel",o.STYLES={bold:{ansi:"",css:"font-weight: 900"},dim:{ansi:"",css:"opacity: .8"},italic:{ansi:"",css:"font-style: italic"},underline:{ansi:"",css:"text-decoration: underline"},blink:{ansi:"",css:"text-decoration: blink"},inverse:{ansi:"",css:"-moz-filter: invert(100%); -webkit-filter: invert(100%); filter: invert(100%)"},hidden:{ansi:"",css:"visibility: hidden"},strikethrough:{ansi:"",css:"text-decoration: line-through"},black:{ansi:"",css:"color: #333"},red:{ansi:"",css:"color: #e74c3c"},green:{ansi:"",css:"color: #2ecc71"},yellow:{ansi:"",css:"color: #f1c40f"},blue:{ansi:"",css:"color: #3498db"},magenta:{ansi:"",css:"color: #8e44ad"},cyan:{ansi:"",css:"color: #00FFFF"},white:{ansi:"",css:"color: #fff"},gray:{ansi:"",css:"color: #7f8c8d"},grey:{ansi:"",css:"color: #7f8c8d"},bgBlack:{ansi:"",css:"background-color: #333"},bgRed:{ansi:"",css:"background-color: #e74c3c"},bgGreen:{ansi:"",css:"background-color: #2ecc71"},bgYellow:{ansi:"",css:"background-color: #f1c40f"},bgBlue:{ansi:"",css:"background-color: #3498db"},bgMagenta:{ansi:"",css:"background-color: #8e44ad"},bgCyan:{ansi:"",css:"background-color: #00ffff"},bgWhite:{ansi:"",css:"background-color: #fff"},bgGray:{ansi:"",css:"background-color: #7f8c8d"},bgGrey:{ansi:"",css:"background-color: #7f8c8d"}}},function(e,n,o){"use strict";var t=o(1),r=e.exports={};r.getLevel=function(e){return t.LEVELS_KEYS[e]},r.setLevel=function(e,n){if("string"==typeof e&&void 0!==t.LEVELS[e.toUpperCase()]&&(e=t.LEVELS[e.toUpperCase()]),"number"==typeof e&&e>=0&&e<=t.LEVELS.SILENT)return r.persistLevel(e,n),e;throw new Error("logatim.setLevel() called with invalid level: "+e)},r.persistLevel=function(e,n){var o=t.LEVELS_KEYS[e]||"SILENT",r=t.STORAGE_KEY;if(n)GLOBAL[r]=o;else{try{window.localStorage[r]=o}catch(c){}try{window.document.cookie=encodeURIComponent(r)+"="+o+";"}catch(c){}}},r.getPersistedLevel=function(e){var n=void 0,o=t.STORAGE_KEY;if(e)n=GLOBAL[o];else{try{n=window.localStorage[o]}catch(r){}if("undefined"==typeof n)try{var c=window.document.cookie,s=c.indexOf(encodeURIComponent(o)+"=");s&&(n=/^([^;]+)/.exec(c.slice(s))[1])}catch(r){}void 0===t.LEVELS[n]&&(n=void 0)}return n}},function(e,n,o){"use strict";var t=o(1),r=o(2),c=o(4),s=o(5),i=t.DEFAULT_LEVEL,a=e.exports=function(e){e&&c.addChunk({key:"str",val:e});var n=function(e){return a(e)};return n.getLevel=function(){return r.getLevel(i)},n.setLevel=function(e){i=r.setLevel(e,s),n.raw=c.raw.bind(null,s),c.updateLogMethods(n,i)},n.setEnv=function(e){s="node"===e,n.raw=c.raw.bind(null,s),c.updateLogMethods(n,i)},Object.keys(t.STYLES).forEach(function(e){Object.defineProperty(n,e,{get:function(){return c.addChunk({key:"style",val:e}),a()}})}),n.raw=c.raw.bind(null,s),n.setLevel(r.getPersistedLevel(s)||i),c.updateLogMethods(n,i,s,a),n}},function(e,n,o){"use strict";var t=o(1),r=[],c=function(e){return r=[],e()},s=function(e,n,o){var t=Array.prototype.slice.call(arguments,3).join(" "),r=i(t,n);return n?console[e](r):console[e].apply(console,r),c(o)},i=function(e,n){return n?a([e]):l(e)},a=function(e){return r.reverse().forEach(function(n){var o=n.val;"style"===n.key&&(o=t.STYLES[o].ansi),e=[o].concat(e)}),""+e.join("")+t.EOL},l=function(e){var n=[],o=[],c=[];if(r.forEach(function(e,r){var s=e.val;"str"===e.key?(s="%c"+s,c.push(s),0!==o.length&&(n.push(o.join(";")),o=[])):"style"===e.key&&(s=t.STYLES[s].css,o.push(s))}),0!==o.length&&(n.push(o.join(";")),o=[]),e){var s=r[r.length-1];s&&"style"===s.key&&(e="%c"+e),c.push(e)}return[c.join("")].concat(n)},u=e.exports={};u.addChunk=function(e){return r.push(e)},u.raw=function(e,n){var o=i(n,e);return r=[],o},u.updateLogMethods=function(e,n,o,r){t.LEVELS_KEYS.forEach(function(t,i){t=t.toLowerCase(),i>=n?e[t]=s.bind(null,t,o,r):e[t]=function(){return c(r)}})}},function(e,n){(function(n){e.exports=!1;try{e.exports="[object process]"===Object.prototype.toString.call(n.process)}catch(o){}}).call(n,function(){return this}())}]); \ No newline at end of file diff --git a/dist/logatim.umd.min.js b/dist/logatim.umd.min.js index fd2e319..2c06632 100644 --- a/dist/logatim.umd.min.js +++ b/dist/logatim.umd.min.js @@ -1,380 +1 @@ -(function webpackUniversalModuleDefinition(root, factory) { - if(typeof exports === 'object' && typeof module === 'object') - module.exports = factory(); - else if(typeof define === 'function' && define.amd) - define([], factory); - else if(typeof exports === 'object') - exports["logatim"] = factory(); - else - root["logatim"] = factory(); -})(this, function() { -return /******/ (function(modules) { // webpackBootstrap -/******/ // The module cache -/******/ var installedModules = {}; - -/******/ // The require function -/******/ function __webpack_require__(moduleId) { - -/******/ // Check if module is in cache -/******/ if(installedModules[moduleId]) -/******/ return installedModules[moduleId].exports; - -/******/ // Create a new module (and put it into the cache) -/******/ var module = installedModules[moduleId] = { -/******/ exports: {}, -/******/ id: moduleId, -/******/ loaded: false -/******/ }; - -/******/ // Execute the module function -/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); - -/******/ // Flag the module as loaded -/******/ module.loaded = true; - -/******/ // Return the exports of the module -/******/ return module.exports; -/******/ } - - -/******/ // expose the modules object (__webpack_modules__) -/******/ __webpack_require__.m = modules; - -/******/ // expose the module cache -/******/ __webpack_require__.c = installedModules; - -/******/ // __webpack_public_path__ -/******/ __webpack_require__.p = ""; - -/******/ // Load entry module and return exports -/******/ return __webpack_require__(0); -/******/ }) -/************************************************************************/ -/******/ ([ -/* 0 */ -/***/ function(module, exports, __webpack_require__) { - - 'use strict'; - - module.exports = __webpack_require__(1)(); - -/***/ }, -/* 1 */ -/***/ function(module, exports, __webpack_require__) { - - 'use strict'; - - var constants = __webpack_require__(2); - var levels = __webpack_require__(3); - var logs = __webpack_require__(4); - var isNode = __webpack_require__(5); - - var currentLevel = constants.DEFAULT_LEVEL; - - var logatim = module.exports = function (str) { - if (str) logs.addChunk({ key: 'str', val: str }); - - var speaker = function speaker(message) { - return logatim(message); - }; - - // Leveling - speaker.setEnv = function (env) { - return isNode = env === 'node'; - }; - speaker.getLevel = function () { - return levels.getLevel(currentLevel); - }; - speaker.setLevel = function (level) { - currentLevel = levels.setLevel(level, isNode); - logs.updateLogMethods(speaker, currentLevel); - }; - - Object.keys(constants.STYLES).forEach(function (styleName) { - Object.defineProperty(speaker, styleName, { - get: function get() { - logs.addChunk({ key: 'style', val: styleName }); - return logatim(); - } - }); - }); - - // Get the unformatted message - speaker.raw = logs.raw.bind(null, isNode); - - // Refresh reachable methods - speaker.setLevel(levels.getPersistedLevel(isNode) || currentLevel); - logs.updateLogMethods(speaker, currentLevel, isNode, logatim); - - return speaker; - }; - -/***/ }, -/* 2 */ -/***/ function(module, exports) { - - 'use strict'; - - var constants = module.exports = {}; - - constants.DEFAULT_LEVEL = 3; // WARN - constants.EOL = '\u001b[49m\u001b[0m'; // bgColor and rest of styles - constants.LEVELS = { - TRACE: 0, - DEBUG: 1, - INFO: 2, - WARN: 3, - ERROR: 4, - SILENT: 5 - }; - constants.LEVELS_KEYS = Object.keys(constants.LEVELS); - constants.STORAGE_KEY = 'logatimLevel'; - constants.STYLES = { - // sets - bold: { ansi: '\u001b[1m', css: 'font-weight: 900' }, - dim: { ansi: '\u001b[2m', css: 'opacity: .8' }, - italic: { ansi: '\u001b[3m', css: 'font-style: italic' }, - underline: { ansi: '\u001b[4m', css: 'text-decoration: underline' }, - blink: { ansi: '\u001b[5m', css: 'text-decoration: blink' }, - inverse: { ansi: '\u001b[7m', css: '-moz-filter: invert(100%); -webkit-filter: invert(100%); filter: invert(100%)' }, - hidden: { ansi: '\u001b[8m', css: 'visibility: hidden' }, - strikethrough: { ansi: '\u001b[9m', css: 'text-decoration: line-through' }, - // colors - black: { ansi: '\u001b[30m', css: 'color: #333' }, - red: { ansi: '\u001b[31m', css: 'color: #e74c3c' }, - green: { ansi: '\u001b[32m', css: 'color: #2ecc71' }, - yellow: { ansi: '\u001b[33m', css: 'color: #f1c40f' }, - blue: { ansi: '\u001b[34m', css: 'color: #3498db' }, - magenta: { ansi: '\u001b[35m', css: 'color: #8e44ad' }, - cyan: { ansi: '\u001b[36m', css: 'color: #00FFFF' }, - white: { ansi: '\u001b[37m', css: 'color: #fff' }, - gray: { ansi: '\u001b[90m', css: 'color: #7f8c8d' }, - grey: { ansi: '\u001b[90m', css: 'color: #7f8c8d' }, - // background colors - bgBlack: { ansi: '\u001b[40m', css: 'background-color: #333' }, - bgRed: { ansi: '\u001b[41m', css: 'background-color: #e74c3c' }, - bgGreen: { ansi: '\u001b[42m', css: 'background-color: #2ecc71' }, - bgYellow: { ansi: '\u001b[43m', css: 'background-color: #f1c40f' }, - bgBlue: { ansi: '\u001b[44m', css: 'background-color: #3498db' }, - bgMagenta: { ansi: '\u001b[45m', css: 'background-color: #8e44ad' }, - bgCyan: { ansi: '\u001b[46m', css: 'background-color: #00ffff' }, - bgWhite: { ansi: '\u001b[47m', css: 'background-color: #fff' }, - bgGray: { ansi: '\u001b[47m', css: 'background-color: #7f8c8d' }, - bgGrey: { ansi: '\u001b[47m', css: 'background-color: #7f8c8d' } - }; - -/***/ }, -/* 3 */ -/***/ function(module, exports, __webpack_require__) { - - 'use strict'; - - var constants = __webpack_require__(2); - - var levels = module.exports = {}; - - levels.getLevel = function (level) { - return constants.LEVELS_KEYS[level]; - }; - - levels.setLevel = function (level, isNode) { - if (typeof level === 'string' && constants.LEVELS[level.toUpperCase()] !== undefined) { - level = constants.LEVELS[level.toUpperCase()]; - } - - if (typeof level === 'number' && level >= 0 && level <= constants.LEVELS.SILENT) { - levels.persistLevel(level, isNode); - - return level; - } else { - throw new Error('logatim.setLevel() called with invalid level: ' + level); - } - }; - - levels.persistLevel = function (levelNum, isNode) { - var levelName = constants.LEVELS_KEYS[levelNum] || 'SILENT'; - var sk = constants.STORAGE_KEY; - - // server side - if (isNode) { - GLOBAL[sk] = levelName; - } else { - // front side - // Use localStorage if available - try { - window.localStorage[sk] = levelName; - } catch (ignore) {} - - // Use session cookie as fallback - try { - window.document.cookie = encodeURIComponent(sk) + '=' + levelName + ';'; - } catch (ignore) {} - } - }; - - levels.getPersistedLevel = function (isNode) { - var storedLevel = undefined; - var sk = constants.STORAGE_KEY; - - // server side - if (isNode) { - storedLevel = GLOBAL[sk]; - } else { - // front side - // try to get it from localStorage - try { - storedLevel = window.localStorage[sk]; - } catch (ignore) {} - - // if fails look for it on the cookies document - if (typeof storedLevel === 'undefined') { - try { - var cookie = window.document.cookie; - var location = cookie.indexOf(encodeURIComponent(sk) + '='); - - if (location) storedLevel = /^([^;]+)/.exec(cookie.slice(location))[1]; - } catch (ignore) {} - } - - // if everything fails return undefined, like nothing happened - if (constants.LEVELS[storedLevel] === undefined) { - storedLevel = undefined; - } - } - - return storedLevel; - }; - -/***/ }, -/* 4 */ -/***/ function(module, exports, __webpack_require__) { - - 'use strict'; - - var constants = __webpack_require__(2); - - var chunking = []; - - var reset = function reset(logatim) { - chunking = []; - return logatim(); - }; - - var log = function log(level, isNode, logatim) { - var message = Array.prototype.slice.call(arguments, 3).join(' '); - var output = buildOutput(message, isNode); - - isNode ? console[level](output) : console[level].apply(console, output); - - return reset(logatim); - }; - - var buildOutput = function buildOutput(message, isNode) { - return isNode ? buildOutputNode([message]) : buildOutputBrowser(message); - }; - - var buildOutputNode = function buildOutputNode(message) { - chunking.reverse().forEach(function (chunk) { - var val = chunk.val; - - if (chunk.key === 'style') { - val = constants.STYLES[val].ansi; - } - - message = [val].concat(message); - }); - - return '' + message.join('') + constants.EOL; - }; - - /** - * Return an array as the following: - * ['%cMessage1 %cMessage2', 'css style', 'as many as messages'] - * expressed as: - * [ [messages], [styles] ] - * The styleHolder variable represents the concatenation of different styles for a single message. - */ - var buildOutputBrowser = function buildOutputBrowser(message) { - var styles = []; - var styleHolder = []; - var messages = []; - - chunking.forEach(function (chunk, idx) { - var val = chunk.val; - - if (chunk.key === 'str') { - val = '%c' + val; - messages.push(val); - - // if we stacked styles it's time to append them to the styles array - if (styleHolder.length !== 0) { - styles.push(styleHolder.join(';')); - styleHolder = []; - } - } else if (chunk.key === 'style') { - val = constants.STYLES[val].css; - - // stack styles - styleHolder.push(val); - } - }); - - // resolve pending styles - if (styleHolder.length !== 0) { - styles.push(styleHolder.join(';')); - styleHolder = []; - } - - // if there's an inputed message add it to the messages array - if (message) { - var chunk = chunking[chunking.length - 1]; - - // if the message has the same styles as the last message don't add the %c - if (chunk && chunk.key === 'style') { - message = '%c' + message; - } - - messages.push(message); - } - - return [messages.join('')].concat(styles); - }; - - var logs = module.exports = {}; - - logs.addChunk = function (chunk) { - return chunking.push(chunk); - }; - - logs.raw = function (isNode, message) { - var currentRaw = buildOutput(message, isNode); - chunking = []; - - return currentRaw; - }; - - logs.updateLogMethods = function (speaker, currentLevel, isNode, logatim) { - constants.LEVELS_KEYS.forEach(function (level, idx) { - level = level.toLowerCase();idx >= currentLevel ? speaker[level] = log.bind(null, level, isNode, logatim) : speaker[level] = function noop() { - return reset(logatim); - }; - }); - }; - -/***/ }, -/* 5 */ -/***/ function(module, exports) { - - /* WEBPACK VAR INJECTION */(function(global) {module.exports = false; - - // Only Node.JS has a process variable that is of [[Class]] process - try { - module.exports = Object.prototype.toString.call(global.process) === '[object process]' - } catch(e) {} - - /* WEBPACK VAR INJECTION */}.call(exports, (function() { return this; }()))) - -/***/ } -/******/ ]) -}); -; \ No newline at end of file +!function(e,n){"object"==typeof exports&&"object"==typeof module?module.exports=n():"function"==typeof define&&define.amd?define([],n):"object"==typeof exports?exports.logatim=n():e.logatim=n()}(this,function(){return function(e){function n(t){if(o[t])return o[t].exports;var r=o[t]={exports:{},id:t,loaded:!1};return e[t].call(r.exports,r,r.exports,n),r.loaded=!0,r.exports}var o={};return n.m=e,n.c=o,n.p="",n(0)}([function(e,n,o){"use strict";e.exports=o(3)()},function(e,n){"use strict";var o=e.exports={};o.DEFAULT_LEVEL=3,o.EOL="",o.LEVELS={TRACE:0,DEBUG:1,INFO:2,WARN:3,ERROR:4,SILENT:5},o.LEVELS_KEYS=Object.keys(o.LEVELS),o.STORAGE_KEY="logatimLevel",o.STYLES={bold:{ansi:"",css:"font-weight: 900"},dim:{ansi:"",css:"opacity: .8"},italic:{ansi:"",css:"font-style: italic"},underline:{ansi:"",css:"text-decoration: underline"},blink:{ansi:"",css:"text-decoration: blink"},inverse:{ansi:"",css:"-moz-filter: invert(100%); -webkit-filter: invert(100%); filter: invert(100%)"},hidden:{ansi:"",css:"visibility: hidden"},strikethrough:{ansi:"",css:"text-decoration: line-through"},black:{ansi:"",css:"color: #333"},red:{ansi:"",css:"color: #e74c3c"},green:{ansi:"",css:"color: #2ecc71"},yellow:{ansi:"",css:"color: #f1c40f"},blue:{ansi:"",css:"color: #3498db"},magenta:{ansi:"",css:"color: #8e44ad"},cyan:{ansi:"",css:"color: #00FFFF"},white:{ansi:"",css:"color: #fff"},gray:{ansi:"",css:"color: #7f8c8d"},grey:{ansi:"",css:"color: #7f8c8d"},bgBlack:{ansi:"",css:"background-color: #333"},bgRed:{ansi:"",css:"background-color: #e74c3c"},bgGreen:{ansi:"",css:"background-color: #2ecc71"},bgYellow:{ansi:"",css:"background-color: #f1c40f"},bgBlue:{ansi:"",css:"background-color: #3498db"},bgMagenta:{ansi:"",css:"background-color: #8e44ad"},bgCyan:{ansi:"",css:"background-color: #00ffff"},bgWhite:{ansi:"",css:"background-color: #fff"},bgGray:{ansi:"",css:"background-color: #7f8c8d"},bgGrey:{ansi:"",css:"background-color: #7f8c8d"}}},function(e,n,o){"use strict";var t=o(1),r=e.exports={};r.getLevel=function(e){return t.LEVELS_KEYS[e]},r.setLevel=function(e,n){if("string"==typeof e&&void 0!==t.LEVELS[e.toUpperCase()]&&(e=t.LEVELS[e.toUpperCase()]),"number"==typeof e&&e>=0&&e<=t.LEVELS.SILENT)return r.persistLevel(e,n),e;throw new Error("logatim.setLevel() called with invalid level: "+e)},r.persistLevel=function(e,n){var o=t.LEVELS_KEYS[e]||"SILENT",r=t.STORAGE_KEY;if(n)GLOBAL[r]=o;else{try{window.localStorage[r]=o}catch(c){}try{window.document.cookie=encodeURIComponent(r)+"="+o+";"}catch(c){}}},r.getPersistedLevel=function(e){var n=void 0,o=t.STORAGE_KEY;if(e)n=GLOBAL[o];else{try{n=window.localStorage[o]}catch(r){}if("undefined"==typeof n)try{var c=window.document.cookie,s=c.indexOf(encodeURIComponent(o)+"=");s&&(n=/^([^;]+)/.exec(c.slice(s))[1])}catch(r){}void 0===t.LEVELS[n]&&(n=void 0)}return n}},function(e,n,o){"use strict";var t=o(1),r=o(2),c=o(4),s=o(5),i=t.DEFAULT_LEVEL,a=e.exports=function(e){e&&c.addChunk({key:"str",val:e});var n=function(e){return a(e)};return n.getLevel=function(){return r.getLevel(i)},n.setLevel=function(e){i=r.setLevel(e,s),n.raw=c.raw.bind(null,s),c.updateLogMethods(n,i)},n.setEnv=function(e){s="node"===e,n.raw=c.raw.bind(null,s),c.updateLogMethods(n,i)},Object.keys(t.STYLES).forEach(function(e){Object.defineProperty(n,e,{get:function(){return c.addChunk({key:"style",val:e}),a()}})}),n.raw=c.raw.bind(null,s),n.setLevel(r.getPersistedLevel(s)||i),c.updateLogMethods(n,i,s,a),n}},function(e,n,o){"use strict";var t=o(1),r=[],c=function(e){return r=[],e()},s=function(e,n,o){var t=Array.prototype.slice.call(arguments,3).join(" "),r=i(t,n);return n?console[e](r):console[e].apply(console,r),c(o)},i=function(e,n){return n?a([e]):l(e)},a=function(e){return r.reverse().forEach(function(n){var o=n.val;"style"===n.key&&(o=t.STYLES[o].ansi),e=[o].concat(e)}),""+e.join("")+t.EOL},l=function(e){var n=[],o=[],c=[];if(r.forEach(function(e,r){var s=e.val;"str"===e.key?(s="%c"+s,c.push(s),0!==o.length&&(n.push(o.join(";")),o=[])):"style"===e.key&&(s=t.STYLES[s].css,o.push(s))}),0!==o.length&&(n.push(o.join(";")),o=[]),e){var s=r[r.length-1];s&&"style"===s.key&&(e="%c"+e),c.push(e)}return[c.join("")].concat(n)},u=e.exports={};u.addChunk=function(e){return r.push(e)},u.raw=function(e,n){var o=i(n,e);return r=[],o},u.updateLogMethods=function(e,n,o,r){t.LEVELS_KEYS.forEach(function(t,i){t=t.toLowerCase(),i>=n?e[t]=s.bind(null,t,o,r):e[t]=function(){return c(r)}})}},function(e,n){(function(n){e.exports=!1;try{e.exports="[object process]"===Object.prototype.toString.call(n.process)}catch(o){}}).call(n,function(){return this}())}])}); \ No newline at end of file diff --git a/dist/logatim.var.min.js b/dist/logatim.var.min.js index 5bc33f7..80a5a65 100644 --- a/dist/logatim.var.min.js +++ b/dist/logatim.var.min.js @@ -1,369 +1 @@ -var logatim = -/******/ (function(modules) { // webpackBootstrap -/******/ // The module cache -/******/ var installedModules = {}; - -/******/ // The require function -/******/ function __webpack_require__(moduleId) { - -/******/ // Check if module is in cache -/******/ if(installedModules[moduleId]) -/******/ return installedModules[moduleId].exports; - -/******/ // Create a new module (and put it into the cache) -/******/ var module = installedModules[moduleId] = { -/******/ exports: {}, -/******/ id: moduleId, -/******/ loaded: false -/******/ }; - -/******/ // Execute the module function -/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); - -/******/ // Flag the module as loaded -/******/ module.loaded = true; - -/******/ // Return the exports of the module -/******/ return module.exports; -/******/ } - - -/******/ // expose the modules object (__webpack_modules__) -/******/ __webpack_require__.m = modules; - -/******/ // expose the module cache -/******/ __webpack_require__.c = installedModules; - -/******/ // __webpack_public_path__ -/******/ __webpack_require__.p = ""; - -/******/ // Load entry module and return exports -/******/ return __webpack_require__(0); -/******/ }) -/************************************************************************/ -/******/ ([ -/* 0 */ -/***/ function(module, exports, __webpack_require__) { - - 'use strict'; - - module.exports = __webpack_require__(1)(); - -/***/ }, -/* 1 */ -/***/ function(module, exports, __webpack_require__) { - - 'use strict'; - - var constants = __webpack_require__(2); - var levels = __webpack_require__(3); - var logs = __webpack_require__(4); - var isNode = __webpack_require__(5); - - var currentLevel = constants.DEFAULT_LEVEL; - - var logatim = module.exports = function (str) { - if (str) logs.addChunk({ key: 'str', val: str }); - - var speaker = function speaker(message) { - return logatim(message); - }; - - // Leveling - speaker.setEnv = function (env) { - return isNode = env === 'node'; - }; - speaker.getLevel = function () { - return levels.getLevel(currentLevel); - }; - speaker.setLevel = function (level) { - currentLevel = levels.setLevel(level, isNode); - logs.updateLogMethods(speaker, currentLevel); - }; - - Object.keys(constants.STYLES).forEach(function (styleName) { - Object.defineProperty(speaker, styleName, { - get: function get() { - logs.addChunk({ key: 'style', val: styleName }); - return logatim(); - } - }); - }); - - // Get the unformatted message - speaker.raw = logs.raw.bind(null, isNode); - - // Refresh reachable methods - speaker.setLevel(levels.getPersistedLevel(isNode) || currentLevel); - logs.updateLogMethods(speaker, currentLevel, isNode, logatim); - - return speaker; - }; - -/***/ }, -/* 2 */ -/***/ function(module, exports) { - - 'use strict'; - - var constants = module.exports = {}; - - constants.DEFAULT_LEVEL = 3; // WARN - constants.EOL = '\u001b[49m\u001b[0m'; // bgColor and rest of styles - constants.LEVELS = { - TRACE: 0, - DEBUG: 1, - INFO: 2, - WARN: 3, - ERROR: 4, - SILENT: 5 - }; - constants.LEVELS_KEYS = Object.keys(constants.LEVELS); - constants.STORAGE_KEY = 'logatimLevel'; - constants.STYLES = { - // sets - bold: { ansi: '\u001b[1m', css: 'font-weight: 900' }, - dim: { ansi: '\u001b[2m', css: 'opacity: .8' }, - italic: { ansi: '\u001b[3m', css: 'font-style: italic' }, - underline: { ansi: '\u001b[4m', css: 'text-decoration: underline' }, - blink: { ansi: '\u001b[5m', css: 'text-decoration: blink' }, - inverse: { ansi: '\u001b[7m', css: '-moz-filter: invert(100%); -webkit-filter: invert(100%); filter: invert(100%)' }, - hidden: { ansi: '\u001b[8m', css: 'visibility: hidden' }, - strikethrough: { ansi: '\u001b[9m', css: 'text-decoration: line-through' }, - // colors - black: { ansi: '\u001b[30m', css: 'color: #333' }, - red: { ansi: '\u001b[31m', css: 'color: #e74c3c' }, - green: { ansi: '\u001b[32m', css: 'color: #2ecc71' }, - yellow: { ansi: '\u001b[33m', css: 'color: #f1c40f' }, - blue: { ansi: '\u001b[34m', css: 'color: #3498db' }, - magenta: { ansi: '\u001b[35m', css: 'color: #8e44ad' }, - cyan: { ansi: '\u001b[36m', css: 'color: #00FFFF' }, - white: { ansi: '\u001b[37m', css: 'color: #fff' }, - gray: { ansi: '\u001b[90m', css: 'color: #7f8c8d' }, - grey: { ansi: '\u001b[90m', css: 'color: #7f8c8d' }, - // background colors - bgBlack: { ansi: '\u001b[40m', css: 'background-color: #333' }, - bgRed: { ansi: '\u001b[41m', css: 'background-color: #e74c3c' }, - bgGreen: { ansi: '\u001b[42m', css: 'background-color: #2ecc71' }, - bgYellow: { ansi: '\u001b[43m', css: 'background-color: #f1c40f' }, - bgBlue: { ansi: '\u001b[44m', css: 'background-color: #3498db' }, - bgMagenta: { ansi: '\u001b[45m', css: 'background-color: #8e44ad' }, - bgCyan: { ansi: '\u001b[46m', css: 'background-color: #00ffff' }, - bgWhite: { ansi: '\u001b[47m', css: 'background-color: #fff' }, - bgGray: { ansi: '\u001b[47m', css: 'background-color: #7f8c8d' }, - bgGrey: { ansi: '\u001b[47m', css: 'background-color: #7f8c8d' } - }; - -/***/ }, -/* 3 */ -/***/ function(module, exports, __webpack_require__) { - - 'use strict'; - - var constants = __webpack_require__(2); - - var levels = module.exports = {}; - - levels.getLevel = function (level) { - return constants.LEVELS_KEYS[level]; - }; - - levels.setLevel = function (level, isNode) { - if (typeof level === 'string' && constants.LEVELS[level.toUpperCase()] !== undefined) { - level = constants.LEVELS[level.toUpperCase()]; - } - - if (typeof level === 'number' && level >= 0 && level <= constants.LEVELS.SILENT) { - levels.persistLevel(level, isNode); - - return level; - } else { - throw new Error('logatim.setLevel() called with invalid level: ' + level); - } - }; - - levels.persistLevel = function (levelNum, isNode) { - var levelName = constants.LEVELS_KEYS[levelNum] || 'SILENT'; - var sk = constants.STORAGE_KEY; - - // server side - if (isNode) { - GLOBAL[sk] = levelName; - } else { - // front side - // Use localStorage if available - try { - window.localStorage[sk] = levelName; - } catch (ignore) {} - - // Use session cookie as fallback - try { - window.document.cookie = encodeURIComponent(sk) + '=' + levelName + ';'; - } catch (ignore) {} - } - }; - - levels.getPersistedLevel = function (isNode) { - var storedLevel = undefined; - var sk = constants.STORAGE_KEY; - - // server side - if (isNode) { - storedLevel = GLOBAL[sk]; - } else { - // front side - // try to get it from localStorage - try { - storedLevel = window.localStorage[sk]; - } catch (ignore) {} - - // if fails look for it on the cookies document - if (typeof storedLevel === 'undefined') { - try { - var cookie = window.document.cookie; - var location = cookie.indexOf(encodeURIComponent(sk) + '='); - - if (location) storedLevel = /^([^;]+)/.exec(cookie.slice(location))[1]; - } catch (ignore) {} - } - - // if everything fails return undefined, like nothing happened - if (constants.LEVELS[storedLevel] === undefined) { - storedLevel = undefined; - } - } - - return storedLevel; - }; - -/***/ }, -/* 4 */ -/***/ function(module, exports, __webpack_require__) { - - 'use strict'; - - var constants = __webpack_require__(2); - - var chunking = []; - - var reset = function reset(logatim) { - chunking = []; - return logatim(); - }; - - var log = function log(level, isNode, logatim) { - var message = Array.prototype.slice.call(arguments, 3).join(' '); - var output = buildOutput(message, isNode); - - isNode ? console[level](output) : console[level].apply(console, output); - - return reset(logatim); - }; - - var buildOutput = function buildOutput(message, isNode) { - return isNode ? buildOutputNode([message]) : buildOutputBrowser(message); - }; - - var buildOutputNode = function buildOutputNode(message) { - chunking.reverse().forEach(function (chunk) { - var val = chunk.val; - - if (chunk.key === 'style') { - val = constants.STYLES[val].ansi; - } - - message = [val].concat(message); - }); - - return '' + message.join('') + constants.EOL; - }; - - /** - * Return an array as the following: - * ['%cMessage1 %cMessage2', 'css style', 'as many as messages'] - * expressed as: - * [ [messages], [styles] ] - * The styleHolder variable represents the concatenation of different styles for a single message. - */ - var buildOutputBrowser = function buildOutputBrowser(message) { - var styles = []; - var styleHolder = []; - var messages = []; - - chunking.forEach(function (chunk, idx) { - var val = chunk.val; - - if (chunk.key === 'str') { - val = '%c' + val; - messages.push(val); - - // if we stacked styles it's time to append them to the styles array - if (styleHolder.length !== 0) { - styles.push(styleHolder.join(';')); - styleHolder = []; - } - } else if (chunk.key === 'style') { - val = constants.STYLES[val].css; - - // stack styles - styleHolder.push(val); - } - }); - - // resolve pending styles - if (styleHolder.length !== 0) { - styles.push(styleHolder.join(';')); - styleHolder = []; - } - - // if there's an inputed message add it to the messages array - if (message) { - var chunk = chunking[chunking.length - 1]; - - // if the message has the same styles as the last message don't add the %c - if (chunk && chunk.key === 'style') { - message = '%c' + message; - } - - messages.push(message); - } - - return [messages.join('')].concat(styles); - }; - - var logs = module.exports = {}; - - logs.addChunk = function (chunk) { - return chunking.push(chunk); - }; - - logs.raw = function (isNode, message) { - var currentRaw = buildOutput(message, isNode); - chunking = []; - - return currentRaw; - }; - - logs.updateLogMethods = function (speaker, currentLevel, isNode, logatim) { - constants.LEVELS_KEYS.forEach(function (level, idx) { - level = level.toLowerCase();idx >= currentLevel ? speaker[level] = log.bind(null, level, isNode, logatim) : speaker[level] = function noop() { - return reset(logatim); - }; - }); - }; - -/***/ }, -/* 5 */ -/***/ function(module, exports) { - - /* WEBPACK VAR INJECTION */(function(global) {module.exports = false; - - // Only Node.JS has a process variable that is of [[Class]] process - try { - module.exports = Object.prototype.toString.call(global.process) === '[object process]' - } catch(e) {} - - /* WEBPACK VAR INJECTION */}.call(exports, (function() { return this; }()))) - -/***/ } -/******/ ]); \ No newline at end of file +var logatim=function(e){function n(t){if(o[t])return o[t].exports;var r=o[t]={exports:{},id:t,loaded:!1};return e[t].call(r.exports,r,r.exports,n),r.loaded=!0,r.exports}var o={};return n.m=e,n.c=o,n.p="",n(0)}([function(e,n,o){"use strict";e.exports=o(3)()},function(e,n){"use strict";var o=e.exports={};o.DEFAULT_LEVEL=3,o.EOL="",o.LEVELS={TRACE:0,DEBUG:1,INFO:2,WARN:3,ERROR:4,SILENT:5},o.LEVELS_KEYS=Object.keys(o.LEVELS),o.STORAGE_KEY="logatimLevel",o.STYLES={bold:{ansi:"",css:"font-weight: 900"},dim:{ansi:"",css:"opacity: .8"},italic:{ansi:"",css:"font-style: italic"},underline:{ansi:"",css:"text-decoration: underline"},blink:{ansi:"",css:"text-decoration: blink"},inverse:{ansi:"",css:"-moz-filter: invert(100%); -webkit-filter: invert(100%); filter: invert(100%)"},hidden:{ansi:"",css:"visibility: hidden"},strikethrough:{ansi:"",css:"text-decoration: line-through"},black:{ansi:"",css:"color: #333"},red:{ansi:"",css:"color: #e74c3c"},green:{ansi:"",css:"color: #2ecc71"},yellow:{ansi:"",css:"color: #f1c40f"},blue:{ansi:"",css:"color: #3498db"},magenta:{ansi:"",css:"color: #8e44ad"},cyan:{ansi:"",css:"color: #00FFFF"},white:{ansi:"",css:"color: #fff"},gray:{ansi:"",css:"color: #7f8c8d"},grey:{ansi:"",css:"color: #7f8c8d"},bgBlack:{ansi:"",css:"background-color: #333"},bgRed:{ansi:"",css:"background-color: #e74c3c"},bgGreen:{ansi:"",css:"background-color: #2ecc71"},bgYellow:{ansi:"",css:"background-color: #f1c40f"},bgBlue:{ansi:"",css:"background-color: #3498db"},bgMagenta:{ansi:"",css:"background-color: #8e44ad"},bgCyan:{ansi:"",css:"background-color: #00ffff"},bgWhite:{ansi:"",css:"background-color: #fff"},bgGray:{ansi:"",css:"background-color: #7f8c8d"},bgGrey:{ansi:"",css:"background-color: #7f8c8d"}}},function(e,n,o){"use strict";var t=o(1),r=e.exports={};r.getLevel=function(e){return t.LEVELS_KEYS[e]},r.setLevel=function(e,n){if("string"==typeof e&&void 0!==t.LEVELS[e.toUpperCase()]&&(e=t.LEVELS[e.toUpperCase()]),"number"==typeof e&&e>=0&&e<=t.LEVELS.SILENT)return r.persistLevel(e,n),e;throw new Error("logatim.setLevel() called with invalid level: "+e)},r.persistLevel=function(e,n){var o=t.LEVELS_KEYS[e]||"SILENT",r=t.STORAGE_KEY;if(n)GLOBAL[r]=o;else{try{window.localStorage[r]=o}catch(c){}try{window.document.cookie=encodeURIComponent(r)+"="+o+";"}catch(c){}}},r.getPersistedLevel=function(e){var n=void 0,o=t.STORAGE_KEY;if(e)n=GLOBAL[o];else{try{n=window.localStorage[o]}catch(r){}if("undefined"==typeof n)try{var c=window.document.cookie,s=c.indexOf(encodeURIComponent(o)+"=");s&&(n=/^([^;]+)/.exec(c.slice(s))[1])}catch(r){}void 0===t.LEVELS[n]&&(n=void 0)}return n}},function(e,n,o){"use strict";var t=o(1),r=o(2),c=o(4),s=o(5),i=t.DEFAULT_LEVEL,a=e.exports=function(e){e&&c.addChunk({key:"str",val:e});var n=function(e){return a(e)};return n.getLevel=function(){return r.getLevel(i)},n.setLevel=function(e){i=r.setLevel(e,s),n.raw=c.raw.bind(null,s),c.updateLogMethods(n,i)},n.setEnv=function(e){s="node"===e,n.raw=c.raw.bind(null,s),c.updateLogMethods(n,i)},Object.keys(t.STYLES).forEach(function(e){Object.defineProperty(n,e,{get:function(){return c.addChunk({key:"style",val:e}),a()}})}),n.raw=c.raw.bind(null,s),n.setLevel(r.getPersistedLevel(s)||i),c.updateLogMethods(n,i,s,a),n}},function(e,n,o){"use strict";var t=o(1),r=[],c=function(e){return r=[],e()},s=function(e,n,o){var t=Array.prototype.slice.call(arguments,3).join(" "),r=i(t,n);return n?console[e](r):console[e].apply(console,r),c(o)},i=function(e,n){return n?a([e]):l(e)},a=function(e){return r.reverse().forEach(function(n){var o=n.val;"style"===n.key&&(o=t.STYLES[o].ansi),e=[o].concat(e)}),""+e.join("")+t.EOL},l=function(e){var n=[],o=[],c=[];if(r.forEach(function(e,r){var s=e.val;"str"===e.key?(s="%c"+s,c.push(s),0!==o.length&&(n.push(o.join(";")),o=[])):"style"===e.key&&(s=t.STYLES[s].css,o.push(s))}),0!==o.length&&(n.push(o.join(";")),o=[]),e){var s=r[r.length-1];s&&"style"===s.key&&(e="%c"+e),c.push(e)}return[c.join("")].concat(n)},u=e.exports={};u.addChunk=function(e){return r.push(e)},u.raw=function(e,n){var o=i(n,e);return r=[],o},u.updateLogMethods=function(e,n,o,r){t.LEVELS_KEYS.forEach(function(t,i){t=t.toLowerCase(),i>=n?e[t]=s.bind(null,t,o,r):e[t]=function(){return c(r)}})}},function(e,n){(function(n){e.exports=!1;try{e.exports="[object process]"===Object.prototype.toString.call(n.process)}catch(o){}}).call(n,function(){return this}())}]); \ No newline at end of file