UNPKG

vue-unicorn-log

Version:

A magical 🦄 plugin to make coloring the console output easier and more flexible.

14 lines • 8.98 kB
/*! * Vue UnicornLog Plugin * * @name vue-unicorn-log * @version 1.0.7 * @description A magical 🦄 plugin to make coloring the console output easier and more flexible. * @author WebDevNerdStuff & Bunnies... lots and lots of bunnies! <webdevnerdstuff@gmail.com> (https://webdevnerdstuff.com) * @copyright Copyright 2023, WebDevNerdStuff * @homepage https://webdevnerdstuff.github.io/vue-unicorn-log/ * @repository https://github.com/webdevnerdstuff/vue-unicorn-log * @license https://github.com/webdevnerdstuff/vue-unicorn-log/blob/main/LICENSE.md * @supports Magical Creatures */ !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports["vue-unicorn-log"]=e():t["vue-unicorn-log"]=e()}(self,(function(){return function(){"use strict";var t={d:function(e,o){for(var r in o)t.o(o,r)&&!t.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:o[r]})},o:function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r:function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},e={};function o(t,e){var o=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),o.push.apply(o,r)}return o}function r(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?o(Object(r),!0).forEach((function(e){n(t,e,r[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):o(Object(r)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))}))}return t}function n(t,e,o){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var o=t[Symbol.toPrimitive];if(void 0!==o){var r=o.call(t,e||"default");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:String(e)}(e))in t?Object.defineProperty(t,e,{value:o,enumerable:!0,configurable:!0,writable:!0}):t[e]=o,t}t.r(e),t.d(e,{default:function(){return y},version:function(){return f}});const i="linear-gradient(to right,\n\thsl(0, 100%, 50%),\n\thsl(39, 100%, 50%),\n\thsl(60, 100%, 50%),\n\thsl(120, 100%, 50%),\n\thsl(180, 100%, 50%),\n\thsl(240, 100%, 50%),\n\thsl(300, 100%, 50%),\n\thsl(360, 100%, 50%)\n)",s={errors:0,logOptions:{},name:"UnicornLog",output:null,pluginOptions:{},types:["clear","count","countReset","debug","dir","error","group","groupCollapsed","groupEnd","info","log","table","time","timeEnd","timeLog","trace","warn"],defaultStyles:{log:["background-color: black",`border-image: ${i} 1`,"border-style: solid","border-width: 4px","color: #fff","font-weight: normal","padding: 8px"],info:["background-color: hsla(225, 100%, 8%, 1)","box-shadow: 999px 0 0 hsla(225, 100%, 8%, 1)","color: hsla(225, 100%, 85%, 1)","display: block","padding: 2px"],goNuts:[`background: ${i}`,"color: #f7f7f7","display: block",'font-family: "Helvetica", "Arial"',"font-size: 15px","font-weight: bold","margin: 5px 0","padding: 10px","text-shadow: 1px 1px 2px #000"]},magicalStyleNames:["magic","magical","prism","psychedelic","rainbow","trippy","unicorn"],defaultOptions:{array:[],defaultStyles:{},disabled:!0,logPrefix:!1,magical:!1,name:"[UnicornLog]:",objects:{},styles:"",text:"🦄",type:"log"},init(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return!e.disabled&&!o.disabled&&(this.pluginOptions=e,this.logOptions=r(r(r({},this.defaultOptions),this.pluginOptions),o),this.defaultStyles=r(r(r({},this.defaultStyles),this.pluginOptions.defaultStyles),o.defaultStyles),Object.values(this.validateOptions).map((t=>"function"==typeof t&&t.call())),Object.values(this.build).map((t=>"function"==typeof t&&t.call())),this.errors||this.consoleOutput(this.logOptions.type),!1)},validateOptions:{type(){const t=s.logOptions.type;return!s.types.includes(t)&&(s.errors+=1,"dirXml"===t?(s.logger("console.dir() is not supported console method.","warn"),!1):(s.logger(`console.${t}() is not supported at this time or is not a valid console method.`,"warn"),!1))},styles(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:s.logOptions.styles;t instanceof Array||"object"!=typeof t&&!Number.isInteger(t)||s.logger('The "styles" option is not a String or an Array.',"error")},logPrefix(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:s.logOptions.logPrefix;("object"==typeof t||t instanceof Boolean)&&s.logger('The "logPrefix" option is not a string or boolean.',"error")},text(){"string"!=typeof(arguments.length>0&&void 0!==arguments[0]?arguments[0]:s.logOptions.text)&&s.logger('The "text" option is not a string.',"error")},objects(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:s.logOptions.objects;(t instanceof Array||"string"==typeof t||Number.isInteger(t))&&s.logger('The "objects" option is not an object.',"error")},array(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:s.logOptions.array;t instanceof Array&&"string"!=typeof t&&!Number.isInteger(t)||s.logger('The "array" option is not an array.',"error")}},build:{prefix(){const t=s.logOptions;t.logPrefix&&("string"==typeof t.logPrefix?t.text=`${t.logPrefix} ${t.text}`:t.text=`${t.name} ${t.text}`)},styles(){const t=s.logOptions;let e=t.styles;e=!1===e?"":"log"!==t.type&&"info"!==t.type||!s.magicalStyleNames.includes(t.styles)&&!t.magical?""!==e&&!0!==e||"info"!==t.type?e||s.defaultStyles.log.join(";"):s.defaultStyles.info.join(";"):s.defaultStyles.goNuts.join(";"),Array.isArray(e)&&(e=e.join(";")),t.styles=e},output(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:s.logOptions;const e=["%c%s",t.styles];t.text&&e.push(t.text),t.array.length&&e.push(t.array),Object.keys(t.objects).length&&e.push(t.objects),s.output=e}},consoleDir(){const t={};return Object.keys(this.logOptions.objects).length&&(Object.keys(this.logOptions.array).length?t.objects=this.logOptions.objects:Object.assign(t,this.logOptions.objects)),Object.keys(this.logOptions.array).length&&(Object.keys(this.logOptions.objects).length?t.array=this.logOptions.array:Object.assign(t,this.logOptions.array)),Object.keys(t).length?(s.logger("console.dir() does not support colors.","info"),t):s.logger('console.dir() expects the "objects" and/or array option value to be set.',"error")},consoleTable(){return s.logger("console.table() does not support colors.","info"),this.logOptions.array},consoleMethodNotSupported(t){this.errors+=1,s.logger(`console.${t}() does not support colors.`,"info")},consoleOutput(t){"dir"===t&&(this.output=[this.consoleDir()]),"table"===t&&(this.output=[this.consoleTable()]),"count"!==t&&"countReset"!==t&&"time"!==t&&"timeEnd"!==t&&"timeLog"!==t||(this.output=[this.consoleMethodNotSupported(t)]),this.errors||console[t](...this.output)},logger(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"An error has occurred.",e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"log";const o=e.charAt(0).toUpperCase()+e.slice(1);let r="";return"error"===e&&(this.errors+=1),"info"===e&&(r=this.defaultStyles.info.join(";")),console[e]("%c%s",r,`[${s.name} ${o}]: ${t}`),!1}};var l=s;function a(t,e){var o=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),o.push.apply(o,r)}return o}function c(t){for(var e=1;e<arguments.length;e++){var o=null!=arguments[e]?arguments[e]:{};e%2?a(Object(o),!0).forEach((function(e){p(t,e,o[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(o)):a(Object(o)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(o,e))}))}return t}function p(t,e,o){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var o=t[Symbol.toPrimitive];if(void 0!==o){var r=o.call(t,e||"default");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:String(e)}(e))in t?Object.defineProperty(t,e,{value:o,enumerable:!0,configurable:!0,writable:!0}):t[e]=o,t}const u={install(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const o=t;t.prototype.$unicornLog||t.prototype.$uniLog||(this.options=c(c({},this.options),e),o.prototype.$unicornLog=function(e){return l.init(t,u.options,e),!1},o.prototype.$uniLog=function(e){return l.init(t,u.options,e),!1})},options:{defaultStyles:{},disabled:!1,logPrefix:!1,styles:"",type:"log"}};var g=u;const f="__VERSION__";"undefined"!=typeof window&&window.Vue&&window.Vue.use(g);var y=g;return e}()}));