beautify-console-log
Advanced tools
Comparing version 1.0.8 to 1.0.9
@@ -1,2 +0,2 @@ | ||
!function(o,e){if("object"==typeof exports&&"object"==typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var t=e();for(var r in t)("object"==typeof exports?exports:o)[r]=t[r]}}(self,(()=>(()=>{"use strict";var o={943:(o,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.BeautifyConsole=void 0;const t={black:30,red:31,green:32,yellow:33,blue:34,purple:35,cyan:36,white:37},r=(o={})=>{const{color:e="white",colorBg:r=""}=o;return`[${t[r]?t[r]+10:0};${t[e]||0}m`};console.log("process");const s=()=>"object"==typeof process?[r({color:"blue"}),"beautify-console-log info: -> "]:["%cbeautify-console-log info: -> ","color: #5D8EF0;"],i=()=>"object"==typeof process?[r({color:"red"}),"beautify-console-log error: -> "]:["beautify-console-log error: -> "],n=()=>"object"==typeof process?[r({color:"yellow"}),"beautify-console-log warn: -> "]:["beautify-console-log warn: -> "],l=()=>"object"==typeof process?[r({color:"green"}),"beautify-console-log log: -> "]:["%cbeautify-console-log log: -> ","color: green;"];class a{constructor(){this.infoPadStartText=s(),this.errorPadStartText=i(),this.warnPadStartText=n(),this.logPadStartText=l(),this.info=console.info.bind(this,...this.infoPadStartText),this.error=console.error.bind(this,...this.errorPadStartText),this.warn=console.warn.bind(this,...this.warnPadStartText),this.log=console.log.bind(this,...this.logPadStartText)}static getInstance(){return this.instance||(this.instance=new a),this.instance}setShowLog(o){o?(this.info=console.info.bind(this,...this.infoPadStartText),this.error=console.error.bind(this,...this.errorPadStartText),this.warn=console.warn.bind(this,...this.warnPadStartText),this.log=console.log.bind(this,...this.logPadStartText)):(this.info=(...o)=>{},this.error=(...o)=>{},this.warn=(...o)=>{},this.log=(...o)=>{})}openLog(){return this.setShowLog(!0),this}closeLog(){return this.setShowLog(!1),this}setPadStartText(o,...e){return{info:()=>{this.info=console.info.bind(this,...e)},error:()=>{this.error=console.error.bind(this,...e)},warn:()=>{this.warn=console.warn.bind(this,...e)},log:()=>{this.log=console.log.bind(this,...e)},undefined:()=>{console.log(void 0)}}[o||void 0](),this}}e.BeautifyConsole=a}},e={};function t(r){var s=e[r];if(void 0!==s)return s.exports;var i=e[r]={exports:{}};return o[r](i,i.exports,t),i.exports}var r={};return(()=>{var o=r;Object.defineProperty(o,"__esModule",{value:!0}),o.BeautifyConsole=void 0;var e=t(943);Object.defineProperty(o,"BeautifyConsole",{enumerable:!0,get:function(){return e.BeautifyConsole}})})(),r})())); | ||
!function(o,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var e=t();for(var r in e)("object"==typeof exports?exports:o)[r]=e[r]}}(self,(()=>(()=>{"use strict";var o={943:(o,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.BeautifyConsole=void 0;const e={black:30,red:31,green:32,yellow:33,blue:34,purple:35,cyan:36,white:37},r=(o={})=>{const{color:t="white",colorBg:r=""}=o;return`[${e[r]?e[r]+10:0};${e[t]||0}m`},s=()=>"object"==typeof process?[r({color:"blue"}),"beautify-console-log info: -> "]:["%cbeautify-console-log info: -> ","color: #5D8EF0;"],i=()=>"object"==typeof process?[r({color:"red"}),"beautify-console-log error: -> "]:["beautify-console-log error: -> "],n=()=>"object"==typeof process?[r({color:"yellow"}),"beautify-console-log warn: -> "]:["beautify-console-log warn: -> "],a=()=>"object"==typeof process?[r({color:"green"}),"beautify-console-log log: -> "]:["%cbeautify-console-log log: -> ","color: green;"];class l{constructor(){this.infoPadStartText=s(),this.errorPadStartText=i(),this.warnPadStartText=n(),this.logPadStartText=a(),this.info=console.info.bind(this,...this.infoPadStartText),this.error=console.error.bind(this,...this.errorPadStartText),this.warn=console.warn.bind(this,...this.warnPadStartText),this.log=console.log.bind(this,...this.logPadStartText)}static getInstance(){return this.instance||(this.instance=new l),this.instance}setShowLog(o,t){const e={info:()=>{this.info=o?console.info.bind(this,...this.infoPadStartText):(...o)=>{}},error:()=>{this.error=o?console.error.bind(this,...this.errorPadStartText):(...o)=>{}},warn:()=>{this.warn=o?console.warn.bind(this,...this.warnPadStartText):(...o)=>{}},log:()=>{this.log=o?console.log.bind(this,...this.logPadStartText):(...o)=>{}}};t?e[t]?e[t]():console.error("type not supported "):o?(this.info=console.info.bind(this,...this.infoPadStartText),this.error=console.error.bind(this,...this.errorPadStartText),this.warn=console.warn.bind(this,...this.warnPadStartText),this.log=console.log.bind(this,...this.logPadStartText)):(this.info=(...o)=>{},this.error=(...o)=>{},this.warn=(...o)=>{},this.log=(...o)=>{})}open(o){return this.setShowLog(!0,o),this}close(o){return this.setShowLog(!1,o),this}setPadStartText(o,...t){const e={info:()=>{this.info=console.info.bind(this,...t)},error:()=>{this.error=console.error.bind(this,...t)},warn:()=>{this.warn=console.warn.bind(this,...t)},log:()=>{this.log=console.log.bind(this,...t)}};return e[o]?e[o]():console.error("type not supported "),this}}t.BeautifyConsole=l}},t={};function e(r){var s=t[r];if(void 0!==s)return s.exports;var i=t[r]={exports:{}};return o[r](i,i.exports,e),i.exports}var r={};return(()=>{var o=r;Object.defineProperty(o,"__esModule",{value:!0}),o.BeautifyConsole=void 0;var t=e(943);Object.defineProperty(o,"BeautifyConsole",{enumerable:!0,get:function(){return t.BeautifyConsole}})})(),r})())); | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "beautify-console-log", | ||
"version": "1.0.8", | ||
"version": "1.0.9", | ||
"description": "This is a further beautification and encapsulation of the 'console' object, including console. log, console. info, console. warn, and console. error.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -9,3 +9,4 @@ # beautify-console-log | ||
You can add custom console printing prefixes and beautify the content (rule reference https://developer.mozilla.org/en-US/docs/Web/API/Console , node environment reference https://en.wikipedia.org/wiki/ANSI_escape_code#Colors), can close console printing at any time, supporting node.js environments | ||
You can add custom console printing prefixes and beautify the content (rule reference https://developer.mozilla.org/en-US/docs/Web/API/Console , node environment reference https://en.wikipedia.org/wiki/ANSI_escape_code#Colors), can close console printing at any time, supporting node.js environments. | ||
Please view the effect on the console. | ||
@@ -55,8 +56,15 @@ | ||
``` | ||
or | ||
``` | ||
const log = new BeautifyConsole(); | ||
//The usage is consistent with the normal console.info() | ||
Log.info(1234, '4', [3, 5]); | ||
``` | ||
2. Supported console types | ||
@@ -87,5 +95,53 @@ | ||
``` | ||
4. Close log | ||
Close the corresponding console log types when passing in parameters, and close all types without passing them. | ||
supports chain calling. | ||
``` | ||
const log = BeautifyConsole.getInstance(); | ||
log.close('info'); | ||
log.close('log'); | ||
log.close('warn'); | ||
log.close('error'); | ||
log.close(); | ||
log.close().open('error'); | ||
// or | ||
log.open('error').open('log').open('warn').open('info'); | ||
// or | ||
log.close('error').info('closed error'); | ||
log.close('error').error('closed error'); | ||
// or | ||
log.close('error').open('info'); | ||
log.close('error').open('info').info('info...'); | ||
``` | ||
5. Open log | ||
Open the corresponding console log types when passing in parameters, and open all types without passing them. | ||
supports chain calling. | ||
``` | ||
const log = BeautifyConsole.getInstance(); | ||
log.open('info'); | ||
log.open('log'); | ||
log.open('warn'); | ||
log.open('error'); | ||
log.open().close('info'); | ||
//or | ||
log.open('error').open('log').open('warn').open('info'); | ||
// or | ||
log.open().info('closed error'); | ||
log.open('error').error('closed error'); | ||
// or | ||
log.close('error').open('info'); | ||
log.close('error').open('info').info('info...'); | ||
``` | ||
#### Participation contribution | ||
@@ -97,3 +153,3 @@ | ||
2. Create a new Feat_ Xxx branch | ||
2. Create a new Feat_Xxx branch | ||
@@ -100,0 +156,0 @@ 3. Submit Code |
@@ -5,3 +5,4 @@ # beautify-console-log | ||
这是“console”对象的进一步美化和封装,包括console.log、console.info、console.warn、console.error。 | ||
可以加入自定义的console打印前缀、对内容进行美化(web端规则参考 https://developer.mozilla.org/en-US/docs/Web/API/Console ,node环境参考 https://zh.wikipedia.org/wiki/ANSI%E8%BD%AC%E4%B9%89%E5%BA%8F%E5%88%97),可随时关闭console打印,支持node环境 | ||
可以加入自定义的console打印前缀、对内容进行美化(web端规则参考 https://developer.mozilla.org/en-US/docs/Web/API/Console ,node环境参考 https://zh.wikipedia.org/wiki/ANSI%E8%BD%AC%E4%B9%89%E5%BA%8F%E5%88%97),可随时关闭console打印,支持node环境。 | ||
查看效果请在控制台。 | ||
@@ -32,2 +33,11 @@ #### 软件架构 | ||
或 | ||
``` | ||
const log = new BeautifyConsole(); | ||
// 使用方式与正常的console.info()一致 | ||
log.info(1234, '4', [3, 5]); | ||
``` | ||
2. 支持的console类型 | ||
@@ -44,5 +54,49 @@ ``` | ||
const log = BeautifyConsole.getInstance(); | ||
log.setPadStartText('log', 'hello world') | ||
// or | ||
log.setPadStartText('log', 'hello world').info(1234, '4', [3, 5]); | ||
``` | ||
4. 关闭日志,传入参数就关闭对应的console日志类型,不传就关闭所有的类型,支持链式调用 | ||
``` | ||
const log = BeautifyConsole.getInstance(); | ||
log.close('info'); | ||
log.close('log'); | ||
log.close('warn'); | ||
log.close('error'); | ||
log.close(); | ||
log.close().open('error'); | ||
// or | ||
log.open('error').open('log').open('warn').open('info'); | ||
// or | ||
log.close('error').info('closed error'); | ||
log.close('error').error('closed error'); | ||
// or | ||
log.close('error').open('info'); | ||
log.close('error').open('info').info('info...'); | ||
``` | ||
5. 打开日志,传入参数就打开对应的console日志类型,不传就打开所有的类型,支持链式调用 | ||
``` | ||
const log = BeautifyConsole.getInstance(); | ||
log.open('info'); | ||
log.open('log'); | ||
log.open('warn'); | ||
log.open('error'); | ||
log.open(); | ||
log.open().close('info'); | ||
//or | ||
log.open('error').open('log').open('warn').open('info'); | ||
// or | ||
log.open().info('closed error'); | ||
log.open('error').error('closed error'); | ||
// or | ||
log.close('error').open('info'); | ||
log.close('error').open('info').info('info...'); | ||
``` | ||
#### 参与贡献 | ||
@@ -49,0 +103,0 @@ |
Sorry, the diff of this file is not supported yet
Trivial Package
Supply chain riskPackages less than 10 lines of code are easily copied into your own project and may not warrant the additional supply chain risk of an external dependency.
Found 1 instance in 1 package
23104
12
154
0