Skip to content

TextFormat

To use TextFormat, import it from the @gaman/common package:

import { TextFormat } from "@gaman/common/utils/textformat";

ConstantDescription
TextFormat.RESETReset all styles
TextFormat.BOLDBold text
TextFormat.DIMDim text
TextFormat.UNDERLINEUnderlined text
TextFormat.BLINKBlinking text
TextFormat.REVERSEReversed foreground/background
TextFormat.HIDDENHidden text
TextFormat.ITALICItalic text
TextFormat.STRIKETHROUGHStrikethrough text

ConstantColor Name
TextFormat.BLACKBlack
TextFormat.BLUEBlue
TextFormat.GREENGreen
TextFormat.CYANCyan
TextFormat.REDRed
TextFormat.MAGENTAMagenta
TextFormat.YELLOWYellow
TextFormat.WHITEWhite
TextFormat.GRAYGray
TextFormat.LIGHT_BLUELight Blue
TextFormat.LIGHT_GREENLight Green
TextFormat.LIGHT_REDLight Red
TextFormat.LIGHT_PURPLELight Purple
TextFormat.LIGHT_YELLOWLight Yellow
TextFormat.BRIGHT_WHITEBright White

ConstantBackground Color
TextFormat.BG_BLACKBlack
TextFormat.BG_BLUEBlue
TextFormat.BG_GREENGreen
TextFormat.BG_CYANCyan
TextFormat.BG_REDRed
TextFormat.BG_MAGENTAMagenta
TextFormat.BG_YELLOWYellow
TextFormat.BG_WHITEWhite
TextFormat.BG_GRAYGray
TextFormat.BG_LIGHT_BLUELight Blue
TextFormat.BG_LIGHT_GREENLight Green
TextFormat.BG_LIGHT_REDLight Red
TextFormat.BG_LIGHT_PURPLELight Purple
TextFormat.BG_LIGHT_YELLOWLight Yellow
TextFormat.BG_BRIGHT_WHITEBright White

The TextFormat.format() method allows you to apply styles dynamically using codes similar to Minecraft’s § codes.

  • Foreground Colors: §0§9, §a§f

  • Background Colors: §b0§b9, §ba§bf

  • Styles:

    • §l – Bold
    • §n – Underline
    • §o – Italic
    • §m – Strikethrough
    • §r – Reset
    • §k – Obfuscated (Not supported)
console.log(TextFormat.format("§eHello §b1World§r!"));

This will output “Hello World!” with yellow text and a blue background.


console.log(TextFormat.GREEN + "Success!" + TextFormat.RESET);
console.log(TextFormat.BOLD + TextFormat.RED + "Error!" + TextFormat.RESET);
console.log(TextFormat.format("§l§cCritical Error!§r Something went wrong."));

  • Always use TextFormat.RESET at the end to avoid affecting subsequent console output.
  • Prefer format() for inline formatting within messages.
  • Use predefined constants when styling static messages.

This utility works in terminal environments that support ANSI escape sequences. It is not intended for use in web environments or non-ANSI consoles.