ansi-fragments is a compact JavaScript library designed for constructing aesthetically pleasing command-line interface (CLI) outputs using ANSI escape codes. Currently at version 0.2.1, it adopts a unique builder-pattern approach, allowing developers to compose styled text fragments programmatically. The library provides functions like `color`, `modifier`, `container`, `pad`, `fixed`, `ifElse`, and `provide` to encapsulate styling logic. Its core differentiator is the explicit fragment building and the `.build()` method, which converts the fragment tree into a single ANSI-encoded string. While a relatively new project, its focus is on providing a 'nice DX' for structured CLI logging rather than offering an exhaustive list of all possible ANSI features. Release cadence is infrequent, typical for a micro-utility library in its early stages.
npm install ansi-fragmentsVerified import paths — ran on the pinned version, not inferred.
Demonstrates creating complex, conditional, and fixed-width CLI log messages using various ansi-fragments builders like color, modifier, container, fixed, and ifElse.
Always consult the project's changelog or release notes before updating minor versions. Pin exact versions for production use if stability is critical.
Ensure that the final fragment or container in your chain always has `.build()` appended to convert it into a printable string with ANSI escape codes.
For advanced color requirements, consider alternative CLI styling libraries or implement custom ANSI escape code sequences if direct control is needed.
Ensure your project is configured for ESM (e.g., by setting `"type": "module"` in your `package.json` for Node.js projects) or use dynamic `import()` for compatibility in mixed environments.
Ensure your project is configured for ESM. For Node.js, set `"type": "module"` in your `package.json`. For bundlers, verify your configuration supports ESM output/resolution.
Always call `.build()` at the end of your fragment chain or container to obtain the final ANSI-formatted string. For example, `container(...).build()`.
Run `npm install ansi-fragments` or `yarn add ansi-fragments` to install the package. Double-check your `import` statement for any typos in the module name.
No dependency data recorded yet.