Skip to content
Columnated lists for the CLI. Unicode and ANSI safe.
JavaScript
Branch: master
Clone or download
Latest commit b9e986b Oct 15, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.editorconfig initial commit Feb 13, 2016
.gitattributes initial commit Feb 13, 2016
.gitignore initial commit Feb 13, 2016
.travis.yml Added travis caching. Updated example output. Jul 27, 2017
color.js Fixed lint error. Jul 27, 2017
index.js Use native `Object.assign`. Mar 2, 2017
license Update copyright info Jan 20, 2018
package.json 3.1.2 Jul 27, 2017
readme.md Update readme.md Oct 15, 2019
test.js chore: Updated deps. Jun 14, 2017

readme.md

cli-columns

NPM version Downloads Build Status Coverage Status Chat Tip

Columnated lists for the CLI. Unicode and ANSI safe.

Install

$ npm install --save cli-columns

Usage

const columns = require('cli-columns');
const chalk = require('chalk');

const values = [
    'blue' + chalk.bgBlue('berry'),
    '笔菠萝' + chalk.yellow('苹果笔'),
    chalk.red('apple'), 'pomegranate',
    'durian', chalk.green('star fruit'),
    'パイナップル', 'apricot', 'banana',
    'pineapple', chalk.bgRed.yellow('orange')
];

console.log(columns(values));

screenshot

API

columns(values [, options]): String

  • values {Array<String>} Array of strings to display.
  • options {Object}
    • character {String} (default: ' ') Padding character.
    • newline {String} (default: '\n') Newline character.
    • padding {Number} (default: 2) Space between columns.
    • sort {Boolean} (default: true) Whether to sort results.
    • width {Number} (default: process.stdout.columns) Max width of list.

Sorts and formats a list of values into columns suitable to display in a given width.

Contribute

Standards for this project, including tests, code coverage, and semantics are enforced with a build tool. Pull requests must include passing tests with 100% code coverage and no linting errors.

Test

$ npm test

MIT © Shannon Moeller

You can’t perform that action at this time.