CLI Boxes
cli-boxes is a utility package providing a collection of pre-defined ASCII and Unicode box character sets, formatted as JSON objects, for rendering borders in terminal applications. It is currently at version 4.0.1 and is actively maintained by Sindre Sorhus, with releases primarily driven by Node.js LTS version compatibility and major architectural shifts like the move to pure ESM. Unlike full terminal UI libraries, cli-boxes focuses solely on delivering the raw character data, allowing other packages (like `boxen`) to handle the actual drawing logic. This makes it a lightweight and foundational component for console-based interfaces, distinguishing it from more comprehensive alternatives by its single-purpose design.
Common errors
-
Error [ERR_REQUIRE_ESM]: require() of ES Module ...cli-boxes/index.js from ... not supported.
cause `cli-boxes` version 4.0.0 and above is pure ESM, but your project is trying to import it using CommonJS `require()` syntax.fixChange your `require('cli-boxes')` statement to `import cliBoxes from 'cli-boxes';` and ensure your `package.json` has `"type": "module"` or your file uses the `.mjs` extension. Upgrade Node.js to version 18 or higher. If you cannot migrate to ESM, downgrade `cli-boxes` to version `3.x`. -
TypeError: Cannot read properties of undefined (reading 'vertical')
cause You are attempting to access `vertical` or `horizontal` properties on a custom box definition using `cli-boxes` version 3.0.0 or higher.fixUpdate your custom box definitions to use the new property names: `left`, `right`, `top`, and `bottom` instead of `vertical` and `horizontal`. -
TypeError: Cannot read properties of undefined (reading 'single-double')
cause You are trying to access a box style using its old, hyphenated name (e.g., 'single-double') with `cli-boxes` version 2.0.0 or higher.fixUse the camelCase equivalent for the box name, e.g., `cliBoxes.singleDouble` instead of `cliBoxes['single-double']`.
Warnings
- breaking Version 4.0.0 of `cli-boxes` is pure ESM (ECMAScript Modules) and requires Node.js 18 or higher. Projects using CommonJS or older Node.js versions must either remain on `cli-boxes@3.x` or refactor to use ESM.
- breaking Version 3.0.0 introduced a change in the configuration keys for custom box definitions. The `vertical` and `horizontal` keys were renamed to `left`, `right`, `top`, and `bottom` respectively. This affects users providing custom box objects.
- breaking Version 2.0.0 renamed two box styles: `single-double` became `singleDouble` and `double-single` became `doubleSingle`. Accessing the old hyphenated names will result in undefined values.
Install
-
npm install cli-boxes -
yarn add cli-boxes -
pnpm add cli-boxes
Imports
- cliBoxes
const cliBoxes = require('cli-boxes');import cliBoxes from 'cli-boxes';
- cliBoxes.single
import cliBoxes from 'cli-boxes'; const singleBox = cliBoxes.single;
- Box
import type { Box } from 'cli-boxes';
Quickstart
import cliBoxes from 'cli-boxes';
// Log the character definitions for the 'single' box style
console.log(cliBoxes.single);
/*
{
topLeft: '┌',
top: '─',
topRight: '┐',
right: '│',
bottomRight: '┘',
bottom: '─',
bottomLeft: '└',
left: '│'
}
*/
// You can use these characters to construct a box
const { topLeft, top, topRight, left, right, bottomLeft, bottom, bottomRight } = cliBoxes.double;
console.log(topLeft + top.repeat(5) + topRight);
console.log(left + ' Hello ' + right);
console.log(bottomLeft + bottom.repeat(5) + bottomRight);