Create text-based columns suitable for console output. Supports cell wrapping.
Installations
npm install columnify
Developer Guide
Typescript
No
Module System
CommonJS
Min. Node Version
>=8.0.0
Node Version
16.13.2
NPM Version
8.1.2
Releases
Unable to fetch releases
Contributors
Unable to fetch Contributors
Languages
JavaScript (99.67%)
Makefile (0.33%)
Developer
timoxley
Download Statistics
Total Downloads
663,533,452
Last Day
242,897
Last Week
1,432,194
Last Month
12,321,070
Last Year
162,078,510
GitHub Statistics
430 Stars
182 Commits
30 Forks
15 Watching
14 Branches
12 Contributors
Bundle Size
9.67 kB
Minified
3.82 kB
Minified + Gzipped
Package Meta Information
Latest Version
1.6.0
Package Id
columnify@1.6.0
Unpacked Size
37.91 kB
Size
9.48 kB
File Count
9
NPM Version
8.1.2
Node Version
16.13.2
Total Downloads
Cumulative downloads
Total Downloads
663,533,452
Last day
-15.7%
242,897
Compared to previous day
Last week
-46.3%
1,432,194
Compared to previous week
Last month
-15.7%
12,321,070
Compared to previous month
Last year
35.8%
162,078,510
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dependencies
2
Dev Dependencies
5
columnify
Create text-based columns suitable for console output from objects or arrays of objects.
Columns are automatically resized to fit the content of the largest cell. Each cell will be padded with spaces to fill the available space and ensure column contents are left-aligned.
Designed to handle sensible wrapping in npm search results.
npm search
before & after integrating columnify:
Installation
$ npm install columnify
Usage
1var columnify = require('columnify') 2var columns = columnify(data, options) 3console.log(columns)
Examples
Columnify Objects
Objects are converted to a list of key/value pairs:
1var data = { 2 "commander@0.6.1": 1, 3 "minimatch@0.2.14": 3, 4 "mkdirp@0.3.5": 2, 5 "sigmund@1.0.0": 3 6} 7 8console.log(columnify(data))
Output:
KEY VALUE
commander@0.6.1 1
minimatch@0.2.14 3
mkdirp@0.3.5 2
sigmund@1.0.0 3
Custom Column Names
1var data = { 2 "commander@0.6.1": 1, 3 "minimatch@0.2.14": 3, 4 "mkdirp@0.3.5": 2, 5 "sigmund@1.0.0": 3 6} 7 8console.log(columnify(data, {columns: ['MODULE', 'COUNT']}))
Output:
MODULE COUNT
commander@0.6.1 1
minimatch@0.2.14 3
mkdirp@0.3.5 2
sigmund@1.0.0 3
Columnify Arrays of Objects
Column headings are extracted from the keys in supplied objects.
1var columnify = require('columnify') 2 3var columns = columnify([{ 4 name: 'mod1', 5 version: '0.0.1' 6}, { 7 name: 'module2', 8 version: '0.2.0' 9}]) 10 11console.log(columns)
Output:
NAME VERSION
mod1 0.0.1
module2 0.2.0
Filtering & Ordering Columns
By default, all properties are converted into columns, whether or not they exist on every object or not.
To explicitly specify which columns to include, and in which order, supply a "columns" or "include" array ("include" is just an alias).
1var data = [{ 2 name: 'module1', 3 description: 'some description', 4 version: '0.0.1', 5}, { 6 name: 'module2', 7 description: 'another description', 8 version: '0.2.0', 9}] 10 11var columns = columnify(data, { 12 columns: ['name', 'version'] 13}) 14 15console.log(columns)
Output:
NAME VERSION
module1 0.0.1
module2 0.2.0
Global and Per Column Options
You can set a number of options at a global level (ie. for all columns) or on a per column basis.
Set options on a per column basis by using the config
option to specify individual columns:
1var columns = columnify(data, { 2 optionName: optionValue, 3 config: { 4 columnName: {optionName: optionValue}, 5 columnName: {optionName: optionValue}, 6 } 7})
Maximum and Minimum Column Widths
As with all options, you can define the maxWidth
and minWidth
globally, or for specified columns. By default, wrapping will happen at word boundaries. Empty cells or those which do not fill the minWidth
will be padded with spaces.
1var columns = columnify([{ 2 name: 'mod1', 3 description: 'some description which happens to be far larger than the max', 4 version: '0.0.1', 5}, { 6 name: 'module-two', 7 description: 'another description larger than the max', 8 version: '0.2.0', 9}], { 10 minWidth: 20, 11 config: { 12 description: {maxWidth: 30} 13 } 14}) 15 16console.log(columns)
Output:
NAME DESCRIPTION VERSION
mod1 some description which happens 0.0.1
to be far larger than the max
module-two another description larger 0.2.0
than the max
Maximum Line Width
You can set a hard maximum line width using the maxLineWidth
option.
Beyond this value data is unceremoniously truncated with no truncation
marker.
This can either be a number or 'auto' to set the value to the width of stdout.
Setting this value to 'auto' prevent TTY-imposed line-wrapping when lines exceed the screen width.
Truncating Column Cells Instead of Wrapping
You can disable wrapping and instead truncate content at the maximum
column width by using the truncate
option. Truncation respects word boundaries. A truncation marker, …
, will appear next to the last word in any truncated line.
1var columns = columnify(data, { 2 truncate: true, 3 config: { 4 description: { 5 maxWidth: 20 6 } 7 } 8}) 9 10console.log(columns)
Output:
NAME DESCRIPTION VERSION
mod1 some description… 0.0.1
module-two another description… 0.2.0
Align Right/Center
You can set the alignment of the column data by using the align
option.
1var data = { 2 "mocha@1.18.2": 1, 3 "commander@2.0.0": 1, 4 "debug@0.8.1": 1 5} 6 7columnify(data, {config: {value: {align: 'right'}}})
Output:
KEY VALUE
mocha@1.18.2 1
commander@2.0.0 1
debug@0.8.1 1
align: 'center'
works in a similar way.
Padding Character
Set a character to fill whitespace within columns with the paddingChr
option.
1var data = { 2 "shortKey": "veryVeryVeryVeryVeryLongVal", 3 "veryVeryVeryVeryVeryLongKey": "shortVal" 4} 5 6columnify(data, { paddingChr: '.'})
Output:
KEY........................ VALUE......................
shortKey................... veryVeryVeryVeryVeryLongVal
veryVeryVeryVeryVeryLongKey shortVal...................
Preserve Existing Newlines
By default, columnify
sanitises text by replacing any occurance of 1 or more whitespace characters with a single space.
columnify
can be configured to respect existing new line characters using the preserveNewLines
option. Note this will still collapse all other whitespace.
1var data = [{ 2 name: "glob@3.2.9", 3 paths: [ 4 "node_modules/tap/node_modules/glob", 5 "node_modules/tape/node_modules/glob" 6 ].join('\n') 7}, { 8 name: "nopt@2.2.1", 9 paths: [ 10 "node_modules/tap/node_modules/nopt" 11 ] 12}, { 13 name: "runforcover@0.0.2", 14 paths: "node_modules/tap/node_modules/runforcover" 15}] 16 17console.log(columnify(data, {preserveNewLines: true}))
Output:
NAME PATHS
glob@3.2.9 node_modules/tap/node_modules/glob
node_modules/tape/node_modules/glob
nopt@2.2.1 node_modules/tap/node_modules/nopt
runforcover@0.0.2 node_modules/tap/node_modules/runforcover
Compare this with output without preserveNewLines
:
1console.log(columnify(data, {preserveNewLines: false})) 2// or just 3console.log(columnify(data))
NAME PATHS
glob@3.2.9 node_modules/tap/node_modules/glob node_modules/tape/node_modules/glob
nopt@2.2.1 node_modules/tap/node_modules/nopt
runforcover@0.0.2 node_modules/tap/node_modules/runforcover
Custom Truncation Marker
You can change the truncation marker to something other than the default
…
by using the truncateMarker
option.
1var columns = columnify(data, { 2 truncate: true, 3 truncateMarker: '>', 4 widths: { 5 description: { 6 maxWidth: 20 7 } 8 } 9}) 10 11console.log(columns)
Output:
NAME DESCRIPTION VERSION
mod1 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 custom
characters by using the columnSplitter
option.
1var columns = columnify(data, { 2 columnSplitter: ' | ' 3}) 4 5console.log(columns)
Output:
NAME | DESCRIPTION | VERSION
mod1 | some description which happens to be far larger than the max | 0.0.1
module-two | another description larger than the max | 0.2.0
Control Header Display
Control whether column headers are displayed by using the showHeaders
option.
1var columns = columnify(data, { 2 showHeaders: false 3})
This also works well for hiding a single column header, like an id
column:
1var columns = columnify(data, { 2 config: { 3 id: { showHeaders: false } 4 } 5})
Transforming Column Data and Headers
If you need to modify the presentation of column content or heading content there are two useful options for doing that: dataTransform
and headingTransform
. Both of these take a function and need to return a valid string.
1var columns = columnify([{ 2 name: 'mod1', 3 description: 'SOME DESCRIPTION TEXT.' 4}, { 5 name: 'module-two', 6 description: 'SOME SLIGHTLY LONGER DESCRIPTION TEXT.' 7}], { 8 dataTransform: function(data) { 9 return data.toLowerCase() 10 }, 11 headingTransform: function(heading) { 12 return heading.toLowerCase() 13 }, 14 config: { 15 name: { 16 headingTransform: function(heading) { 17 heading = "module " + heading 18 return "*" + heading.toUpperCase() + "*" 19 } 20 } 21 } 22})
Output:
*MODULE NAME* description
mod1 some description text.
module-two some slightly longer description text.
Multibyte Character Support
columnify
uses mycoboco/wcwidth.js to calculate length of multibyte characters:
1var data = [{ 2 name: 'module-one', 3 description: 'some description', 4 version: '0.0.1', 5}, { 6 name: '这是一个很长的名字的模块', 7 description: '这真的是一个描述的内容这个描述很长', 8 version: "0.3.3" 9}] 10 11console.log(columnify(data))
Without multibyte handling:
i.e. before columnify added this feature
NAME DESCRIPTION VERSION
module-one some description 0.0.1
这是一个很长的名字的模块 这真的是一个描述的内容这个描述很长 0.3.3
With multibyte handling:
NAME DESCRIPTION VERSION
module-one some description 0.0.1
这是一个很长的名字的模块 这真的是一个描述的内容这个描述很长 0.3.3
Contributions
project : columnify
repo age : 8 years
active : 47 days
commits : 180
files : 57
authors :
123 Tim Oxley 68.3%
11 Nicholas Hoffman 6.1%
8 Tim 4.4%
7 Arjun Mehta 3.9%
6 Dany 3.3%
5 Tim Kevin Oxley 2.8%
5 Wei Gao 2.8%
4 Matias Singers 2.2%
3 Michael Kriese 1.7%
2 sreekanth370 1.1%
2 Dany Shaanan 1.1%
1 Tim Malone 0.6%
1 Seth Miller 0.6%
1 andyfusniak 0.6%
1 Isaac Z. Schlueter 0.6%
License
MIT
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
Found 4/13 approved changesets -- score normalized to 3
Reason
dependency not pinned by hash detected -- score normalized to 3
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/test.yml:21: update your workflow using https://app.stepsecurity.io/secureworkflow/timoxley/columnify/test.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/test.yml:25: update your workflow using https://app.stepsecurity.io/secureworkflow/timoxley/columnify/test.yml/master?enable=pin
- Info: 0 out of 2 GitHub-owned GitHubAction dependencies pinned
- Info: 1 out of 1 npmCommand dependencies pinned
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: no topLevel permission defined: .github/workflows/test.yml:1
- Info: no jobLevel write permissions found
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 21 are checked with a SAST tool
Reason
10 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92
- Warn: Project is vulnerable to: GHSA-cwfw-4gq5-mrqx
- Warn: Project is vulnerable to: GHSA-g95f-p29q-9xw4
- Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg
- Warn: Project is vulnerable to: GHSA-w573-4hg7-7wgq
- Warn: Project is vulnerable to: GHSA-9c47-m6qq-7p4h
- Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv
- Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3
- Warn: Project is vulnerable to: GHSA-xvch-5gv4-984h
- Warn: Project is vulnerable to: GHSA-w5p7-h5w8-2hfq
Score
3
/10
Last Scanned on 2024-12-30
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More