ts (similar to timestamp)
The ts (timestamp) function prepends a formatted timestamp to the provided arguments. It wraps the current date and time in brackets and combines them with the rest of the arguments using cs.
Signature
function ts(date?: boolean, ...args: any[]): string
Parameters
date: Whether to include the date portion (YYYY-MM-DD). Defaults totrue....args: Additional values to append after the timestamp.
Return Value
Returns a string in the format [YYYY-MM-DD - HH:MM:SS] ...args or [HH:MM:SS] ...args when date is false.
Usage
import { ts } from "ts-better-console";
// With date and time
console.log(ts(true, "Server started"));
// => [2026-03-01 - 14:30:00] Server started
// Time only
console.log(ts(false, "Request received"));
// => [14:30:00] Request received
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!