us (similar to applyUndefinedStyles)
applyUndefinedStyles (aliased as us) is a safe wrapper around s() that only applies styling when a StyleOptions object is actually provided. If style is undefined, the original string is returned unchanged — making it ideal for optional styling in components and utilities.
Signature
function applyUndefinedStyles(str: string, style?: StyleOptions): string
Parameters
str: The string to optionally style.style: An optionalStyleOptionsobject. If omitted orundefined,stris returned as-is.
Return Value
The styled string if style was provided, otherwise the original str.
Aliases
Exported as both applyUndefinedStyles and us.
Usage
import { us } from "ts-better-console";
function label(text: string, style?: StyleOptions) {return us(text, style);}
// Styled when style is provided
label("OK", { color: "green" });
// Plain string when style is omitted
label("OK");
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!