iro
Fast and clean terminal coloring and styling utility for Deno and Node.js.
Overview
- No dependencies
- Clean and easy syntax
- No polyfilling
- Lightweight
- Import only what you need
Usage
Deno
// hello.ts
import iro, { bold, red } from 'https://cdn.jsdelivr.net/npm/node-iro@1.0.1/src/iro.ts';
console.log(iro('Hello, World!', bold, red));
Node.js
Install using npm:
npm i node-iro
...or Yarn:
yarn add node-iro
Use it:
// hello.js
const iro = require('node-iro').default;
const { bold, red } = require('node-iro');
console.log(iro('Hello, World!', bold, red));
Advanced Usage
Nesting
// example taken from https://github.com/lukeed/kleur#nested-methods :)
console.log(iro(`foo ${iro('red', red, bold)} bar ${iro('cyan', cyan)} baz`, yellow));
console.log(iro('foo ' + iro('red', red, bold) + ' bar ' + iro('cyan', cyan) + ' baz', yellow));
Supported Formatting
Modifiers: reset, bold, dim, italic, underline, inverse, hidden, strikethrough
Colors: black, red, green, yellow, blue, magenta, cyan, white, gray, grey
Background colors: bgBlack, bgRed, bgGreen, bgYellow, bgBlue, bgMagenta, bgCyan, bgWhite
Note: italic
and strikethrough
are not widely supported.
Credits
This project is heavily inspired by kleur. It was mainly made to be used in Deno, but I've decided to release it for Node.js users too. The syntax is different for two reasons: personal preference and lean typings. If you use Node.js and prefer kleur's syntax, you should definitely choose kleur over iro, it's an awesome library 😊
Planned Features
- Check if terminal supports coloring
- Explicitly provide whether the coloring should happen
- Unit tests
License
MIT.