You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1 lines
7.7 KiB
1 lines
7.7 KiB
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t=t||self).consola=e()}(this,function(){"use strict";function t(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function e(t,e){for(var r=0;r<e.length;r++){var o=e[r];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,o.key,o)}}function r(t,r,o){return r&&e(t.prototype,r),o&&e(t,o),t}function o(t,e,r){return e in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function s(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(t);e&&(o=o.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),r.push.apply(r,o)}return r}function n(t){return function(t){if(Array.isArray(t)){for(var e=0,r=new Array(t.length);e<t.length;e++)r[e]=t[e];return r}}(t)||function(t){if(Symbol.iterator in Object(t)||"[object Arguments]"===Object.prototype.toString.call(t))return Array.from(t)}(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance")}()}var i={fatal:{level:0},error:{level:0},warn:{level:1},log:{level:2},info:{level:3},success:{level:3},debug:{level:4},trace:{level:5},silent:{level:1/0},ready:{level:3},start:{level:3}};function l(t){return e=t,"[object Object]"===Object.prototype.toString.call(e)&&(!(!t.message&&!t.args)&&!t.stack);var e}var a=!1,u=[],c=function(){function e(){var r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};for(var o in t(this,e),this._reporters=r.reporters||[],this._types=r.types||i,this._level=null!=r.level?r.level:3,this._defaults=r.defaults||{},this._async=void 0!==r.async?r.async:null,this._stdout=r.stdout,this._stderr=r.stderr,this._mockFn=r.mockFn,this._throttle=r.throttle||2e3,this._types)this[o]=this._wrapLogFn(Object.assign({type:o},this._types[o],this._defaults));this._mockFn&&this.mockTypes(),this._lastLogSerialized=null,this._lastLog=null,this._lastLogTime=null,this._lastLogCount=0,this._throttleTimeout=null}return r(e,[{key:"create",value:function(t){return new e(Object.assign({reporters:this._reporters,level:this._level,types:this._types,defaults:this._defaults,stdout:this._stdout,stderr:this._stderr,mockFn:this._mockFn},t))}},{key:"withDefaults",value:function(t){return this.create({defaults:Object.assign({},this._defaults,t)})}},{key:"withTag",value:function(t){return this.withDefaults({tag:this._defaults.tag?this._defaults.tag+":"+t:t})}},{key:"addReporter",value:function(t){return this._reporters.push(t),this}},{key:"removeReporter",value:function(t){if(t){var e=this._reporters.indexOf(t);if(e>=0)return this._reporters.splice(e,1)}else this._reporters.splice(0);return this}},{key:"setReporters",value:function(t){return this._reporters=Array.isArray(t)?t:[t],this}},{key:"wrapAll",value:function(){this.wrapConsole(),this.wrapStd()}},{key:"restoreAll",value:function(){this.restoreConsole(),this.restoreStd()}},{key:"wrapConsole",value:function(){for(var t in this._types)console["__"+t]||(console["__"+t]=console[t]),console[t]=this[t]}},{key:"restoreConsole",value:function(){for(var t in this._types)console["__"+t]&&(console[t]=console["__"+t],delete console["__"+t])}},{key:"wrapStd",value:function(){this._wrapStream(this.stdout,"log"),this._wrapStream(this.stderr,"log")}},{key:"_wrapStream",value:function(t,e){var r=this;t&&(t.__write||(t.__write=t.write),t.write=function(t){r[e](String(t).trim())})}},{key:"restoreStd",value:function(){this._restoreStream(this.stdout),this._restoreStream(this.stderr)}},{key:"_restoreStream",value:function(t){t&&t.__write&&(t.write=t.__write,delete t.__write)}},{key:"pauseLogs",value:function(){a=!0}},{key:"resumeLogs",value:function(){a=!1;var t=u.splice(0),e=!0,r=!1,o=void 0;try{for(var s,n=t[Symbol.iterator]();!(e=(s=n.next()).done);e=!0){var i=s.value;i[0]._logFn(i[1],i[2])}}catch(t){r=!0,o=t}finally{try{e||null==n.return||n.return()}finally{if(r)throw o}}}},{key:"mockTypes",value:function(t){if(this._mockFn=t||this._mockFn,"function"==typeof this._mockFn)for(var e in this._types)this[e]=this._mockFn(e,this._types[e])||this[e]}},{key:"_wrapLogFn",value:function(t){return function(){if(!a)return this._logFn(t,arguments);u.push([this,t,arguments])}.bind(this)}},{key:"_logFn",value:function(t,e){var r=this;if(t.level>this._level)return!!this._async&&Promise.resolve(!1);var i=Object.assign({date:new Date,args:[]},t);1===e.length&&l(e[0])?Object.assign(i,e[0]):i.args=Array.from(e),i.message&&(i.args.unshift(i.message),delete i.message),i.additional&&(Array.isArray(i.additional)||(i.additional=i.additional.split("\n")),i.args.push("\n"+i.additional.join("\n")),delete i.additional),i.type="string"==typeof i.type?i.type.toLowerCase():"",i.tag="string"==typeof i.tag?i.tag.toLowerCase():"";var a=function(){var t=arguments.length>0&&void 0!==arguments[0]&&arguments[0];if(r._lastLogCount&&(r._log(function(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?s(Object(r),!0).forEach(function(e){o(t,e,r[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):s(Object(r)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))})}return t}({},r._lastLog,{args:[].concat(n(r._lastLog.args),["(repeated ".concat(r._lastLogCount-(t?1:0)," times)")])})),r._lastLogCount=0),r._lastLog=i,t){if(r._async)return r._logAsync(i);r._log(i)}};clearTimeout(this._throttleTimeout);var u=this._lastLogTime?i.date-this._lastLogTime:0;if(this._lastLogTime=i.date,u<this._throttle)try{var c=JSON.stringify([i.type,i.tag,i.args]),p=this._lastLogSerialized===c;if(this._lastLogSerialized=c,p)return this._lastLogCount++,void(this._throttleTimeout=setTimeout(a,this._throttle))}catch(t){}a(!0)}},{key:"_log",value:function(t){var e=!0,r=!1,o=void 0;try{for(var s,n=this._reporters[Symbol.iterator]();!(e=(s=n.next()).done);e=!0){s.value.log(t,{async:!1,stdout:this.stdout,stderr:this.stderr})}}catch(t){r=!0,o=t}finally{try{e||null==n.return||n.return()}finally{if(r)throw o}}}},{key:"_logAsync",value:function(t){var e=this;return Promise.all(this._reporters.map(function(r){return r.log(t,{async:!0,stdout:e.stdout,stderr:e.stderr})}))}},{key:"level",get:function(){return this._level},set:function(t){var e=0,r=0;for(var o in this._types){var s=this._types[o];s.level>r?r=s.level:s.level<e&&(e=s.level)}this._level=Math.min(r,Math.max(e,t))}},{key:"stdout",get:function(){return this._stdout||console._stdout}},{key:"stderr",get:function(){return this._stderr||console._stderr}}]),e}();c.prototype.add=c.prototype.addReporter,c.prototype.remove=c.prototype.removeReporter,c.prototype.clear=c.prototype.removeReporter,c.prototype.withScope=c.prototype.withTag,c.prototype.mock=c.prototype.mockTypes,c.prototype.pause=c.prototype.pauseLogs,c.prototype.resume=c.prototype.resumeLogs;var p,h=function(){function e(r){t(this,e),this.options=Object.assign({},r),this.defaultColor="#7f8c8d",this.levelColorMap={0:"#c0392b",1:"#f39c12",3:"#00BCD4"},this.typeColorMap={success:"#2ecc71"}}return r(e,[{key:"log",value:function(t){var e=t.level<1?console.__error||console.error:1===t.level&&console.warn?console.__warn||console.warn:console.__log||console.log,r="log"!==t.type?t.type:"",o=t.tag?t.tag:"",s=this.typeColorMap[t.type]||this.levelColorMap[t.level]||this.defaultColor,i="\n background: ".concat(s,";\n border-radius: 0.5em;\n color: white;\n font-weight: bold;\n padding: 2px 0.5em;\n "),l="%c".concat([o,r].filter(Boolean).join(":"));"string"==typeof t.args[0]?e.apply(void 0,["".concat(l,"%c ").concat(t.args[0]),i,""].concat(n(t.args.slice(1)))):e.apply(void 0,[l,i].concat(n(t.args)))}}]),e}();return"undefined"!=typeof window&&window.consola||((p=new c({reporters:[new h]})).Consola=c,p.BrowserReporter=h,p)});
|
|
|