magiclogger - v0.1.0
    Preparing search index...

    Class Colorizer

    Static utility class for applying ANSI color codes.

    This class provides low-level color application functionality used by other components. It handles:

    • ANSI escape code generation
    • Color validation
    • Terminal capability detection
    • Performance optimizations

    Colorizer

    Index

    Constructors

    Methods

    • Apply an array of colors/styles to text

      Parameters

      • text: string

        The text to format

      • colors: string[]

        Array of color names to apply

      • useColors: boolean = true

        Whether to use colors (defaults to true)

      Returns string

      Text with all styles applied

    • Apply colors from a preset style

      Parameters

      • text: string

        The text to format

      • preset:
            | "info"
            | "success"
            | "warning"
            | "error"
            | "debug"
            | "important"
            | "highlight"
            | "muted"
            | "special"
            | "code"
            | "header"

        The preset style name

      • useColors: boolean = true

        Whether to use colors (defaults to true)

      Returns string

      Formatted text with preset colors applied

    • Apply blue color.

      Parameters

      • text: string

      Returns string

    • Apply bold style.

      Parameters

      • text: string

      Returns string

    • Apply bright blue color.

      Parameters

      • text: string

      Returns string

    • Apply bright cyan color.

      Parameters

      • text: string

      Returns string

    • Apply bright green color.

      Parameters

      • text: string

      Returns string

    • Apply bright magenta color.

      Parameters

      • text: string

      Returns string

    • Apply bright red color.

      Parameters

      • text: string

      Returns string

    • Apply bright white color.

      Parameters

      • text: string

      Returns string

    • Apply bright yellow color.

      Parameters

      • text: string

      Returns string

    • Apply a single color or style to text

      Parameters

      • text: string

        The text to colorize

      • color: string

        The color or style name to apply

      • useColors: boolean = true

        Whether to use colors (defaults to true)

      Returns string

      Formatted text with color codes

    • Apply multiple colors to different parts of a string

      Parameters

      • parts: { color: string; text: string }[]

        Array of objects containing text and color information

      • useColors: boolean = true

        Whether to use colors (defaults to true)

      Returns string

      Combined string with each part colored accordingly

    • Create a color function for repeated use.

      Parameters

      • ...colors: string[]

        Colors to apply

      Returns (text: string) => string

      Color function

    • Apply cyan color.

      Parameters

      • text: string

      Returns string

    • Apply dim style.

      Parameters

      • text: string

      Returns string

    • Format a key-value pair with colored key

      Parameters

      • key: string

        The key to display

      • value: unknown

        The value to display

      • keyColor: string = 'cyan'

        Color for the key

      • useColors: boolean = true

        Whether to use colors (defaults to true)

      Returns string

      Formatted string like "key: value"

    • Get color level support.

      Returns number

      Color level (0, 1, 2, or 3)

    • Apply gray color.

      Parameters

      • text: string

      Returns string

    • Apply green color.

      Parameters

      • text: string

      Returns string

    • Check if text has ANSI codes.

      Parameters

      • text: string

        Text to check

      Returns boolean

      True if has ANSI codes

    • Highlight specific matches in text with a given color

      Parameters

      • text: string

        The source text

      • pattern: string | RegExp

        RegExp or string to match

      • highlightColor: string = 'yellow'

        Color to apply to matches

      • useColors: boolean = true

        Whether to use colors (defaults to true)

      Returns string

      Text with highlighted matches

    • Apply inverse style.

      Parameters

      • text: string

      Returns string

    • Utility: Check if a string looks like a URL or file path.

      Parameters

      • text: string

        The text to check.

      Returns boolean

      True if it is link-like.

    • Apply italic style.

      Parameters

      • text: string

      Returns string

    • Apply magenta color.

      Parameters

      • text: string

      Returns string

    • Create a rainbow effect on text (each character gets a different color)

      Parameters

      • text: string

        The text to rainbow-ify

      • useColors: boolean = true

        Whether to use colors (defaults to true)

      Returns string

      Text with rainbow coloring

    • Apply red color.

      Parameters

      • text: string

      Returns string

    • Force color support on or off.

      Parameters

      • supported: boolean

        Whether colors are supported

      Returns void

    • Apply strikethrough style.

      Parameters

      • text: string

      Returns string

    • Strip ANSI codes from text.

      Parameters

      • text: string

        Text with ANSI codes

      Returns string

      Plain text

    • Check if the terminal supports color.

      Returns boolean

      True if colors are supported

    • Apply underline style.

      Parameters

      • text: string

      Returns string

    • Get visible length of text (excluding ANSI codes).

      Parameters

      • text: string

        Text to measure

      Returns number

      Visible length

    • Apply white color.

      Parameters

      • text: string

      Returns string

    • Apply yellow color.

      Parameters

      • text: string

      Returns string