UNPKG

styled-string-builder

Version:

String Styler class based on a builder design pattern

1 lines 4.37 kB
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("styled-string-builder",[],t):"object"==typeof exports?exports["styled-string-builder"]=t():e["styled-string-builder"]=t()}(this,(()=>(()=>{"use strict";var e={73:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.colorizeANSI=function(e,t,r=!1){return isNaN(t)?(console.warn(`Invalid color number on the ANSI scale: ${t}. ignoring...`),e):(r&&(t>30&&t<=40||t>90&&t<=100)&&(t+=10),`[${t}m${e}${o.AnsiReset}`)},t.colorize256=function(e,t,r=!1){return isNaN(t)||t<0||t>255?(console.warn(`Invalid color number on the 256 scale: ${t}. ignoring...`),e):`[${r?48:38};5;${t}m${e}${o.AnsiReset}`},t.colorizeRGB=function(e,t,r,n,i=!1){return isNaN(t)||isNaN(r)||isNaN(n)||[t,r,n].some((e=>e<0||e>255))?(console.warn(`Invalid RGB color values: r=${t}, g=${r}, b=${n}. Ignoring...`),e):`[${i?48:38};2;${t};${r};${n}m${e}${o.AnsiReset}`},t.applyStyle=function(e,t){return`[${"number"==typeof t?t:o.styles[t]}m${e}${o.AnsiReset}`},t.clear=function(e){return e.replace(/\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])/g,"")},t.raw=function(e,t){return`${t}${e}${o.AnsiReset}`};const o=r(640)},347:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.StyledString=void 0,t.style=function(...e){return new i(e.join(" "))};const o=r(640),n=r(73);class i{constructor(e){this.text=e,Object.entries(o.StandardForegroundColors).forEach((([e,t])=>{Object.defineProperty(this,e,{get:()=>this.foreground(t)})})),Object.entries(o.BrightForegroundColors).forEach((([e,t])=>{Object.defineProperty(this,e,{get:()=>this.foreground(t)})})),Object.entries(o.StandardBackgroundColors).forEach((([e,t])=>{Object.defineProperty(this,e,{get:()=>this.background(t)})})),Object.entries(o.BrightBackgroundColors).forEach((([e,t])=>{Object.defineProperty(this,e,{get:()=>this.background(t)})})),Object.entries(o.styles).forEach((([e,t])=>{Object.defineProperty(this,e,{get:()=>this.style(t)})}))}clear(){return this.text=(0,n.clear)(this.text),this}raw(e){return this.text=(0,n.raw)(this.text,e),this}foreground(e){return this.text=(0,n.colorizeANSI)(this.text,e),this}background(e){return this.text=(0,n.colorizeANSI)(this.text,e,!0),this}style(e){return"string"!=typeof e||e in o.styles?(this.text=(0,n.applyStyle)(this.text,e),this):(console.warn(`Invalid style: ${e}`),this)}color256(e){return this.text=(0,n.colorize256)(this.text,e),this}bgColor256(e){return this.text=(0,n.colorize256)(this.text,e,!0),this}rgb(e,t,r){return this.text=(0,n.colorizeRGB)(this.text,e,t,r),this}bgRgb(e,t,r){return this.text=(0,n.colorizeRGB)(this.text,e,t,r,!0),this}toString(){return this.text}}t.StyledString=i},640:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.styles=t.BrightBackgroundColors=t.StandardBackgroundColors=t.BrightForegroundColors=t.StandardForegroundColors=t.AnsiReset=void 0,t.AnsiReset="",t.StandardForegroundColors={black:30,red:31,green:32,yellow:33,blue:34,magenta:35,cyan:36,white:37},t.BrightForegroundColors={brightBlack:90,brightRed:91,brightGreen:92,brightYellow:93,brightBlue:94,brightMagenta:95,brightCyan:96,brightWhite:97},t.StandardBackgroundColors={bgBlack:40,bgRed:41,bgGreen:42,bgYellow:43,bgBlue:44,bgMagenta:45,bgCyan:46,bgWhite:47},t.BrightBackgroundColors={bgBrightBlack:100,bgBrightRed:101,bgBrightGreen:102,bgBrightYellow:103,bgBrightBlue:104,bgBrightMagenta:105,bgBrightCyan:106,bgBrightWhite:107},t.styles={reset:0,bold:1,dim:2,italic:3,underline:4,blink:5,inverse:7,hidden:8,strikethrough:9,doubleUnderline:21,normalColor:22,noItalicOrFraktur:23,noUnderline:24,noBlink:25,noInverse:27,noHidden:28,noStrikethrough:29}},729:function(e,t,r){var o=this&&this.__createBinding||(Object.create?function(e,t,r,o){void 0===o&&(o=r);var n=Object.getOwnPropertyDescriptor(t,r);n&&!("get"in n?!t.__esModule:n.writable||n.configurable)||(n={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,o,n)}:function(e,t,r,o){void 0===o&&(o=r),e[o]=t[r]}),n=this&&this.__exportStar||function(e,t){for(var r in e)"default"===r||Object.prototype.hasOwnProperty.call(t,r)||o(t,e,r)};Object.defineProperty(t,"__esModule",{value:!0}),n(r(73),t),n(r(640),t),n(r(347),t)}},t={};return function r(o){var n=t[o];if(void 0!==n)return n.exports;var i=t[o]={exports:{}};return e[o].call(i.exports,i,i.exports,r),i.exports}(729)})()));