Movatterモバイル変換


[0]ホーム

URL:


columnify
DefinitelyTyped icon, indicating that this package has TypeScript declarations provided by the separate @types/columnify package

0.1.1 • Public • Published

Build Status

Create text-based columns suitable for console output.Supports minimum and maximum column widths via truncation and text wrapping.

Designed tohandle sensible wrapping in npm search results.

Installation & Update

$ npm install --save columnify@latest

Usage

varcolumnify=require('columnify')varcolumns=columnify(data,options)console.log(columns)

Examples

Simple Columns

Text is aligned under column headings. Columns are automatically resizedto fit the content of the largest cell. Each cell will be padded withspaces to fill the available space and ensure column contents areleft-aligned.

varcolumnify=require('columnify')varcolumns=columnify([{name:'mod1',version:'0.0.1'},{name:'module2',version:'0.2.0'}])console.log(columns)
NAME    VERSIONmod1    0.0.1  module2 0.2.0

Wrapping Column Cells

You can define the maximum width before wrapping for individual cells incolumns. Minimum width is also supported. Wrapping will happen at wordboundaries. Empty cells or those which do not fill the max/min widthwill be padded with spaces.

varcolumnify=require('columnify')varcolumns=columnify([{name:'mod1',description:'some description which happens to be far larger than the max',version:'0.0.1',},{name:'module-two',description:'another description larger than the max',version:'0.2.0',})console.log(columns)
NAME       DESCRIPTION                    VERSIONmod1       some description which happens 0.0.1           to be far larger than the maxmodule-two another description larger     0.2.0           than the max

Truncated Columns

You can disable wrapping and instead truncate content at the maximumcolumn width. Truncation respects word boundaries. A truncation marker, will appear next to the last word in any truncated line.

varcolumns=columnify(data,{truncate:true,config:{description:{maxWidth:20}}})console.log(columns)
NAME       DESCRIPTION          VERSIONmod1       some description…    0.0.1  module-two another description… 0.2.0

Custom Truncation Marker

You can change the truncation marker to something other than the default.

varcolumns=columnify(data,{truncate:true,truncateMarker:'>',widths:{description:{maxWidth:20}}})console.log(columns)
NAME       DESCRIPTION          VERSIONmod1       some description>    0.0.1  module-two another description> 0.2.0

Custom Column Splitter

If your columns need some bling, you can split columns with customcharacters.

varcolumns=columnify(data,{columnSplitter:' | '})console.log(columns)
NAME       | DESCRIPTION                                                  | VERSIONmod1       | some description which happens to be far larger than the max | 0.0.1module-two | another description larger than the max                      | 0.2.0

Filtering & Ordering Columns

By default, all properties are converted into columns, whether or notthey exist on every object or not.

To explicitly specify which columns to include, and in which order,supply an "include" array:

vardata=[{name:'module1',description:'some description',version:'0.0.1',},{name:'module2',description:'another description',version:'0.2.0',}]varcolumns=columnify(data,{include:['name','version']// note description not included})console.log(columns)
NAME    VERSIONmodule1 0.0.1module2 0.2.0

License

MIT

Package Sidebar

Install

npm i columnify@0.1.1

Version

0.1.1

License

MIT

Last publish

Collaborators

  • timoxley

[8]ページ先頭

©2009-2025 Movatter.jp