magiclogger - v0.1.0
    Preparing search index...

    Class StyleBuilder

    StyleBuilder provides a chainable API for building styled strings.

    Similar to popular libraries like Chalk, it allows intuitive chaining of color and style modifiers. The builder uses a Proxy-based approach to provide dynamic property access and efficient caching of style combinations.

    StyleBuilder

    const style = new StyleBuilder();

    // Chain multiple styles
    const text = style.red.bold('Error message');

    // Create reusable style functions
    const errorStyle = style.red.bold.underline;
    const successStyle = style.green.bold;

    console.log(errorStyle('Critical error'));
    console.log(successStyle('Operation complete'));

    // Combine with template literals
    const message = `${style.cyan('User')} ${style.yellow.bold('logged in')}`;
    Index

    Constructors

    • Creates a new StyleBuilder instance.

      Parameters

      • useColors: boolean = true

        Whether to apply colors to output

      • initialStyles: string[] = []

        Initial styles to apply (used internally for chaining)

      Returns StyleBuilder

    Accessors

    Methods

    • Gets the current style stack.

      Useful for debugging or introspection.

      Returns string[]

      Array of accumulated styles

    • Checks if colors are enabled for this builder.

      Returns boolean

      Whether colors are enabled

    • Clears the style cache.

      Useful for testing or when color support changes.

      Returns void

    • Creates a new StyleBuilder with specified color setting.

      Useful for creating conditional styling based on environment.

      Parameters

      • useColors: boolean

        Whether to use colors

      Returns StyleBuilder

      New StyleBuilder instance