Socket
Socket
Sign inDemoInstall

columnify

Package Overview
Dependencies
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

columnify - npm Package Compare versions

Comparing version 0.0.3 to 0.0.4

test/truncate-multichar-expected.txt

29

index.js

@@ -15,2 +15,7 @@ "use strict"

options.columnSplitter = options.columnSplitter || ' '
if (typeof options.truncate !== 'string') {
options.truncate = options.truncate ? '…' : false
}
options.spacing = options.spacing || '\n'

@@ -81,5 +86,11 @@

items = items.map(function(item) {
item[columnName] = splitIntoLines(item[columnName], column.width)
// only include first line if truncating
if (options.truncate) item[columnName] = item[columnName].slice(0, 1)
var cell = item[columnName]
item[columnName] = splitIntoLines(cell, column.width)
// if truncating required, only include first line + add truncation char
if (options.truncate && item[columnName].length > 1) {
item[columnName] = splitIntoLines(cell, column.width - options.truncate.length)
item[columnName][0] += options.truncate
item[columnName] = item[columnName].slice(0, 1)
}
return item

@@ -89,2 +100,14 @@ })

// recalculate column widths from truncated output
columnNames.forEach(function(columnName) {
var column = columns[columnName]
column.width = items.map(function(item) {
return item[columnName].reduce(function(min, cur) {
return Math.max(min, Math.min(column.maxWidth, Math.max(column.minWidth, cur.length)))
}, 0)
}).reduce(function(min, cur) {
return Math.max(min, Math.min(column.maxWidth, Math.max(column.minWidth, cur)))
}, 0)
})
var rows = createRows(items, columns, columnNames)

@@ -91,0 +114,0 @@

2

package.json
{
"name": "columnify",
"version": "0.0.3",
"version": "0.0.4",
"description": "Render data in text columns, with in-column text-wrap.",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -28,4 +28,6 @@ # columnify

Text is aligned under column headings. 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.
Text is aligned under column headings. 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.

@@ -53,3 +55,6 @@ ```js

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

@@ -81,3 +86,5 @@ ```js

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

@@ -89,3 +96,3 @@ ```js

description: {
maxWidth: 19
maxWidth: 20
}

@@ -99,10 +106,35 @@ }

```
NAME DESCRIPTION VERSION
mod1 some description 0.0.1
module-two another description 0.2.0
NAME DESCRIPTION VERSION
mod1 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
`…`.
```js
var columns = columnify(data, {
truncate: '>',
widths: {
description: {
maxWidth: 20
}
}
})
console.log(columns)
```
```
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.
If your columns need some bling, you can split columns with custom
characters.

@@ -125,5 +157,7 @@ ```js

By default, all properties are converted into columns, whether or not they exist on every object or not.
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" array:
To explicitly specify which columns to include, and in which order,
supply a "columns" array:

@@ -130,0 +164,0 @@ ```js

@@ -1,3 +0,3 @@

NAME DESCRIPTION VERSION
mod1 some description 0.0.1
module-two another description 0.2.0
NAME DESCRIPTION VERSION
mod1 some description… 0.0.1
module-two another description… 0.2.0

@@ -23,3 +23,3 @@ var test = require('tape')

description: {
maxWidth: 19
maxWidth: 20
}

@@ -26,0 +26,0 @@ }

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc