@tlyboy/message
š¬ Labeled terminal messages with zero dependencies
Install#
Requires Node.js 22.13 or later. Published as ESM only.
Usage#
Custom labels#
message.defaults holds the labels and is read on every call. Set it once, for example at your app's entry, and keep using message.xxx() everywhere. A string is printed as is, so you can pass an emoji or any text. Levels you leave out keep the built-in label.
- Pass
format: nullto print the text without styling. - Delete a level or set it to
undefinedto restore the built-in label.message.defaults = {}resets all of them. message.defaultsapplies to the whole process, so set it in apps and CLIs. Libraries should usemessage.create()instead.
Instances#
message.create() returns a new instance whose defaults are a copy of the current message.defaults merged with the given config. After that, changes on either side don't affect the other.
Instances can create instances too: log.create().
Theme file#
End users can theme every CLI built on this package with a JSON file at ~/.config/tlyboy/message.json (or $XDG_CONFIG_HOME/tlyboy/message.json). It takes the same labels as message.defaults:
- The theme only replaces built-in labels. Labels set in code with
message.defaultsormessage.create()still win. - The file is read once, on the first message. A missing or broken file, or an invalid entry, is ignored.
- Set
TLYBOY_MESSAGE_CONFIGto use another file, or tofalseto turn the theme off.
info and success are written to stdout, error and warning to stderr, so errors stay visible when stdout is redirected. Colors follow NO_COLOR, FORCE_COLOR and whether each stream is a TTY.
Development#
Release#
bumpp bumps the version, commits, tags and pushes. The tag triggers the release workflow, which stages the package on npm with trusted publishing (provenance included) and creates a GitHub release with changelogithub. The version goes live after a maintainer approves it with 2FA on the package's Staged Packages tab on npmjs.com, or with npm stage approve <stage-id>.
License#
MIT Ā© tlyboy