consolecolor/dist/index.js
2017-01-21 20:30:53 +01:00

56 lines
4.3 KiB
JavaScript

"use strict";
require("typings-global");
const ansiColors = require("ansi-256-colors");
/**
* the color translator function
*/
let colorTranslator = (colorArg) => {
switch (colorArg) {
case 'black':
return { r: 0, g: 0, b: 0 };
case 'blue':
return { r: 0, g: 2, b: 5 };
case 'brown':
return { r: 1, g: 0, b: 0 };
case 'cyan':
return { r: 2, g: 4, b: 4 };
case 'green':
return { r: 2, g: 4, b: 1 };
case 'orange':
return { r: 5, g: 3, b: 1 };
case 'pink':
return { r: 3, g: 2, b: 4 };
case 'red':
return { r: 5, 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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsMEJBQXVCO0FBQ3ZCLDhDQUE2QztBQXNCN0M7O0dBRUc7QUFDSCxJQUFJLGVBQWUsR0FBRyxDQUFDLFFBQW9CO0lBQ3ZDLE1BQU0sQ0FBQyxDQUFDLFFBQVEsQ0FBQyxDQUFDLENBQUM7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