StyleOptions

The StyleOptions type defines the various styling options that can be applied to console logs when using the s function from ts-better-console. These options allow you to customize the appearance of your logs with different colors, backgrounds, and styles to make them more visually appealing and easier to read.

Type Definition

The StyleOptions type includes the following properties:

  • color: The text color — a named color string, an 8-bit color via eightBit(), or a 24-bit color via rgb() / hex().
  • backgroundColor: The background color (same types as color).
  • styles: An array of strings representing additional styles to apply to the log, such as "bold", "italic", or "underline".
  • endless : A boolean indicating whether the styled log should persist indefinitely until manually cleared, or if it should be removed after a certain duration. When set to true, the log will remain in the console until explicitly cleared by the developer, allowing for long-term visibility of important logs. When set to false or omitted, the log will be removed after a default duration, which can be customized using the duration property.
type StyleOptions = {
  color?: AnyColor;
  backgroundColor?: AnyColor;
  styles?: style[];
  endless?: boolean;
}

Usage

You can use the StyleOptions type when calling the s function to apply custom styles to your console logs. For example:

import betterConsole, { s } from "ts-better-console";

betterConsole.(("This is a styled log", {
color: "white",
backgroundColor: "blue",
styles: ["bold", "italic"],
}));

Examples

Here are some examples of how you can use the StyleOptions type to create styled console logs:

betterConsole.("Styled Log", {color: "red", backgroundColor: "yellow", styles: ["bold", "underline"],});
This is a styled log!✨

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!