cli-sprintf-format is a utility package that provides an enhanced `sprintf`-like formatting function specifically tailored for command-line interface (CLI) applications. It builds upon Node.js's `util.formatWithOptions`, offering more robust type resolution, error handling, and intelligent color support. The package automatically detects terminal color capabilities via `supports-color` and applies coloring not only to inspected objects but also to primitive values, including colored JSON output. The current stable version is 1.1.1, released in late 2021, suggesting a relatively stable but infrequent release cadence focused on maintenance and bug fixes. Key differentiators include its improved object inspection depth (defaulting to 4, configurable via `FORMAT_INSPECT_DEPTH`) and specialized handling of `%s` and `%#s` format specifiers for string output, allowing for colored and inline display or raw string output, respectively.
npm install cli-sprintf-formatVerified import paths — ran on the pinned version, not inferred.
Demonstrates basic string, number, object, and JSON formatting, including the effect of environment variables on object inspection depth.
Use `%#s` instead of `%s` for string arguments that should not be processed by `util.inspect`.
Set the `FORMAT_INSPECT_DEPTH` environment variable (e.g., `FORMAT_INSPECT_DEPTH=6 node your_script.js`) to increase the inspection depth, or consider stringifying objects explicitly if full depth is always required.
Review string literal outputs in Node.js v12+ after upgrading to v1.1.1 to ensure no unintended formatting changes occurred. No code change is typically required unless specific literal formatting was being implicitly relied upon.
For ESM, use `import cliFormat from 'cli-sprintf-format';`. For CommonJS, use `const cliFormat = require('cli-sprintf-format');`.If raw string output is desired, switch to `%#s` instead of `%s`.