@bracketed/logger
Version:
An alternative to your run-of-the-mill node console logging functions!
1 lines • 2.11 kB
Source Map (JSON)
{"version":3,"sources":["../../../src/Style/Style.ts"],"names":["LoggerStyle","style","resolvable","effects","styles","push","map","text","Colorette","background","length","string","reduce","out","reset","run"],"mappings":"+EAOaA,IAAN,OAPP,CAAA,OAOaA,CAAAA,CAAAA,IAAAA,CAAAA,aACIC,QAEhB,CAAA,WAAmBC,CAAoC,CAAC,CAAA,EACvD,KAAI,OAAOA,CAAe,YACzB,CAAA,IAAKD,CAAAA,aAEL,CAAA,IAAkC,CAAA,CAAA,GACnBE,CAAAA,CAAAA,OAASC,EAAOC,MAAI,CAAA,GAAeF,SAAQG,CAAAA,GAAKC,CAAAA,CAASC,EAAUD,CAAAA,CAAK,CAAA,CAAA,CACnFL,CAAAA,CAAWK,MAAMH,EAAOC,CAAAA,CAAAA,KAAeH,CAAAA,CAAWK,CAAAA,CAAAA,IAAK,CACvDL,CAAAA,CAAWO,YAAYL,EAAOC,CAAAA,CAAAA,KAAeH,CAAAA,CAAWO,CAAAA,CAAAA,UAAW,CAEvE,CAAA,CAAA,UAAaL,CAAOM,CAAAA,CAAAA,OACVA,CAAAA,CAAAA,MAAAA,GACNN,EAAO,CAAA,CAAA,CACNO,GAAWP,EAAOQ,CAAAA,CAAAA,MAAQC,CAAAA,CAAKZ,CAAAA,CAAAA,CAAAA,GAAgBY,CAAAA,CAAAA,CAAMF,CAAAA,CAAAA,CAC7CG,CAAAA,CAAAA,CAAAA,CAAAA,MASRC,CAAAA,CAAAA,IAA6B,CACnC,CAAA,CAAA,WAAYd,CAAAA,KAAMU,CACnB,CACD,CAAA,CAAA","file":"Style.mjs","sourcesContent":["import * as Colorette from '../Colouring';\nimport type { LoggerStyleResolvable } from './Resolvable';\n\n/**\n * Logger utility that applies a style to a string.\n * @since 1.0.0\n */\nexport class LoggerStyle {\n\tpublic readonly style: Colorette.Color;\n\n\tpublic constructor(resolvable: LoggerStyleResolvable = {}) {\n\t\tif (typeof resolvable === 'function') {\n\t\t\tthis.style = resolvable;\n\t\t} else {\n\t\t\tconst styles: Colorette.Color[] = [];\n\t\t\tif (resolvable.effects) styles.push(...resolvable.effects.map((text) => Colorette[text]));\n\t\t\tif (resolvable.text) styles.push(Colorette[resolvable.text]);\n\t\t\tif (resolvable.background) styles.push(Colorette[resolvable.background]);\n\n\t\t\tthis.style = styles.length\n\t\t\t\t? styles.length === 1\n\t\t\t\t\t? styles[0]\n\t\t\t\t\t: (string) => styles.reduce((out, style) => style(out), string) as string\n\t\t\t\t: Colorette.reset;\n\t\t}\n\t}\n\n\t/**\n\t * Applies the style to a string.\n\t * @since 1.0.0\n\t * @param string The value to apply the style to.\n\t */\n\tpublic run(string: string | number) {\n\t\treturn this.style(string);\n\t}\n}\n"]}