UNPKG

jc-color

Version:

A JavaScript tool for color compute and console print tool both for NodeJS and Browser.

1 lines 2.16 kB
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.templates=exports.getPlatform=void 0;const types_1=require("../types");function hasDomAndWin(){return"undefined"!=typeof window&&"undefined"!=typeof document}function hasProcessObj(){return"undefined"!=typeof process}function getPlatform(){var e=hasDomAndWin(),r=hasProcessObj();return e&&r?"Electron":r?"Node":"Browser"}exports.getPlatform=getPlatform;const styles={remove_all:"",bold:"",dark:"",italic:"",underline:"",glimmer:"",reverse:"",hidden:"",delete:"",underline_double:"",remove_bold:"",remove_underline:"",remove_glimmer:"",remove_reverse:"",remove_hidden:"",remove_delete:"",overline:"",remove_overline:"",clear:""},countNodeStyle=(e,r)=>{let o="";var t={red:-1,green:-1,blue:-1};return e.clear&&(o+=styles.clear),o+=styles.remove_all,e.bold?o+=styles.bold:e.dark&&(o+=styles.dark),e.italic&&(o+=styles.italic),e.underline&&(o+=styles.underline),e.underline_double&&(o+=styles.underline_double),e.glimmer&&(o+=styles.glimmer),e.reverse&&(o+=styles.reverse),e.hidden&&(o+=styles.hidden),e.delete&&(o+=styles.delete),e.overline&&(o+=styles.overline),r.foreColor!==t&&(r.modes.inverseFore?o+=`[1;${types_1.ColorTypeCode.frColor};2;${255-parseInt(r.foreColor.red.toString())};${255-parseInt(r.foreColor.green.toString(),10)};${255-parseInt(r.foreColor.blue.toString(),10)}m`:o+=`[1;${types_1.ColorTypeCode.frColor};2;${parseInt(r.foreColor.red.toString())};${parseInt(r.foreColor.green.toString(),10)};${parseInt(r.foreColor.blue.toString(),10)}m`),r.bgColor!==t&&(r.modes.inverseBg?o+=`[1;${types_1.ColorTypeCode.bgClolr};2;${255-parseInt(r.bgColor.red.toString())};${255-parseInt(r.bgColor.green.toString())};${255-parseInt(r.bgColor.blue.toString())}m`:o+=`[1;${types_1.ColorTypeCode.bgClolr};2;${parseInt(r.bgColor.red.toString())};${parseInt(r.bgColor.green.toString())};${parseInt(r.bgColor.blue.toString())}m`),o+=r.text,r.endstyle&&(o+=""),o},templates=e=>({Node:{default:countNodeStyle(e.modes,e),styless:""+e.text},Browser:"%c"+e.text});exports.templates=templates;