consolecolor/dist/index.js
2017-01-21 18:10:27 +01:00

54 lines
4.1 KiB
JavaScript

"use strict";
require("typings-global");
const ansiColors = require("ansi-256-colors");
/**
* the color translator function
*/
let colorTranslator = (colorArg) => {
switch (colorArg) {
case 'blue':
return { r: 0, g: 1, b: 5 };
case 'cyan':
return { r: 0, g: 4, b: 4 };
case 'green':
return { r: 2, g: 5, b: 0 };
case 'red':
return { r: 5, g: 0, b: 0 };
case 'orange':
return { r: 5, g: 3, b: 0 };
case 'brown':
return { r: 1, g: 0, b: 0 };
case 'black':
return { r: 0, g: 0, b: 0 };
case 'white':
return { r: 5, g: 5, b: 5 };
default:
return { r: 5, g: 5, b: 5 };
}
};
/**
* colors the font of a string
*/
let coloredFont = (stringArg, colorArg) => {
let rgbCode = colorTranslator(colorArg);
return ansiColors.fg.getRgb(rgbCode.r, rgbCode.g, rgbCode.b) + stringArg;
};
/**
* colors the back of a string
*/
let coloredBackground = (stringArg, colorArg) => {
let rgbCode = colorTranslator(colorArg);
return ansiColors.bg.getRgb(rgbCode.r, rgbCode.g, rgbCode.b) + stringArg;
};
/**
* color a string with xterm
*/
exports.coloredString = (stringArg, colorFontArg, colorBackgroundArg) => {
let returnString = coloredFont(stringArg, colorFontArg);
if (colorBackgroundArg) {
returnString = coloredBackground(returnString, colorBackgroundArg);
}
returnString = returnString + ansiColors.reset;
return returnString;
};
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsMEJBQXVCO0FBQ3ZCLDhDQUE2QztBQW9CN0M7O0dBRUc7QUFDSCxJQUFJLGVBQWUsR0FBRyxDQUFDLFFBQW9CO0lBQ3ZDLE1BQU0sQ0FBQyxDQUFDLFFBQVEsQ0FBQyxDQUFDLENBQUM7UUFDZixLQUFLLE1BQU07WUFDUCxN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