flag

The flag function prepends a colored debug level flag to the provided arguments. The flag is wrapped in brackets and colored based on the level: DEBUG, INFO, WARN, or ERROR.

Signature

function flag(level: DebugLevel, ...args: any[]): string

Parameters

  • level: A DebugLevel string — "debug", "info", "warn", or "error".
  • ...args: Additional values to append after the flag.

Return Value

Returns a string with a colored level badge followed by the arguments, e.g. [INFO] message.

Usage

import { flag } from "ts-better-console";

console.log(flag("info", "Server started"));
// => [INFO] Server started

console.log(flag("warn", "Deprecated API"));
// => [WARN] Deprecated API

console.log(flag("error", "Connection failed"));
// => [ERROR] Connection failed

console.log(flag("debug", "Variable x =", 42));
// => [DEBUG] Variable x = 42

Want to support this project?

If you find ts-better-console useful and want to support its development, consider starring the GitHub repository or buying me a coffee! Your support helps me dedicate more time to improving the library and adding new features.

Want to contribute to this project?

Contributions are welcome! If you're interested in improving the library, fixing bugs, or adding new features, feel free to check out the GitHub repository and submit a pull request. Whether you're a seasoned developer or new to open source, your contributions can make a difference!