chalky
Version:
Like chalk.js, but smaller and with fewer features
2 lines (1 loc) • 1.49 kB
JavaScript
;const e={black:0,red:1,green:2,yellow:3,blue:4,magenta:5,cyan:6,white:7},t={bold:1,light:2,italic:3,underline:4,blink:5,inverse:7,hidden:8};function r(e,t=""){return Object.keys(e).map(r=>({name:r,value:`[${t}${e[r]}m`}))}var o={createFormatStyles:function(){return r(t)},createColors:function(t){const o="fg"===t||"foreground"===t,n="bg"===t||"background"===t,c=r(e,o?"3":n?"4":null);if(!c)throw new Error(`Unable to create ${o?"foreground":n?"background":"object. No parameters supplied. Params are required to create"} colors`);return o?c:n?c&&c.map(e=>({...e,name:"bg"+(e.name.charAt(0).toUpperCase()+e.name.slice(1))})):[]},rainbowify:function(e){const t=["1","3","2","4"];let r=0;return Array.from(e).reduce((e,o)=>{let n=" ",c=o.replace(/\s+/g,"");return c&&(n=`[3${t[r%t.length]}m${c}`,r+=1),e+=n},"")+"[0m"}};const{createColors:n,createFormatStyles:c,rainbowify:a}=o,i=n("foreground"),l=n("background"),s=c(),u="[0m";function b(){const e={};return Object.setPrototypeOf(e,b.prototype),e}const f=Object.create(null);f.rainbow={get:()=>e=>a(e)};for(const{name:e,value:t}of[...i,...l,...s])f[e]={get(){let r=t;const o=this._styleChain;void 0!==o&&(r=o.color+r);const n={color:r,existing:o},c=(...e)=>{const t=1===e.length?""+e[0]:e.join(" ");return n.color+t+u};return Object.setPrototypeOf(c,d),c._styleChain=n,Object.defineProperty(this,e,{value:c}),c}};const d=Object.defineProperties(()=>{},{...f});Object.defineProperties(b.prototype,f);var g=b();module.exports=g;