Convert HTML, RGB or HSL to ANSI
Installation
npm install to-ansi
Usage
With commonJs
const toAnsi = require("to-ansi");
With ESM
import toAnsi from "to-ansi";
Examples
Convert Hex, RGB and HSL to ANSI
toAnsi.fromHexa("#00FF00"); // => \x1b[38;5;46m
toAnsi.fromRgb({red: 0, blue: 0, green: 255}) // => \x1b[38;5;46m
toAnsi.fromHsl({hue: 0.5, saturation: 0.5, lightness: 0.5})
Apply colors to the console via the fromHexa function
console.log(
toAnsi.fromHexa("#00FF00") +
toAnsi.fromHexa("#FF0000", false) +
toAnsi.STYLE.Underline +
toAnsi.STYLE.Bold +
"Okay" +
toAnsi.RESET
);
Apply colors to the console via the getText function (Recommended way)
// Yellow
console.log( toAnsi.getTextFromHex("Hello you!", {fg: "#FFFF00"}) );
// Yellow with blue background
console.log( toAnsi.getTextFromHex("Hello you!", {fg: "#FFFF00", bg: "#0000FF"}) );
// Yellow-ish on purple-lish
console.log( toAnsi.getTextFromHex("Hello you!", {fg: "#FFCCFF", bg: "#DD00FF", isUnderline: true}) );