Socket
Socket
Sign inDemoInstall

columnify

Package Overview
Dependencies
2
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.1.0 to 1.2.0-alpha

11

index.js

@@ -6,2 +6,3 @@ "use strict"

var padRight = utils.padRight
var padCenter = utils.padCenter
var padLeft = utils.padLeft

@@ -19,2 +20,3 @@ var splitIntoLines = utils.splitIntoLines

preserveNewLines: false,
paddingChr: ' ',
headingTransform: function(key) {

@@ -161,3 +163,3 @@ return key.toUpperCase()

var rows = createRows(items, columns, columnNames) // merge lines into rows
var rows = createRows(items, columns, columnNames, options.paddingChr) // merge lines into rows
// conceive output

@@ -182,3 +184,3 @@ return rows.reduce(function(output, row) {

function createRows(items, columns, columnNames) {
function createRows(items, columns, columnNames, paddingChr) {
return items.map(function(item) {

@@ -196,4 +198,5 @@ var row = []

var val = item[columnName][i] || '' // || '' ensures empty columns get padded
if (column.align == 'right') row[i].push(padLeft(val, column.width))
else row[i].push(padRight(val, column.width))
if (column.align == 'right') row[i].push(padLeft(val, column.width, paddingChr))
else if (column.align == 'center') row[i].push(padCenter(val, column.width, paddingChr))
else row[i].push(padRight(val, column.width, paddingChr))
})

@@ -200,0 +203,0 @@ }

{
"name": "columnify",
"version": "1.1.0",
"version": "1.2.0-alpha",
"description": "Render data in text columns, supports in-column text-wrap.",

@@ -34,3 +34,3 @@ "main": "index.js",

"dependencies": {
"strip-ansi": "^0.2.1",
"strip-ansi": "^1.0.0",
"wcwidth.js": "~0.0.4"

@@ -37,0 +37,0 @@ },

@@ -6,2 +6,13 @@ "use strict"

/**
* repeat string `str` up to total length of `len`
*
* @param String str string to repeat
* @param Number len total length of output string
*/
function repeatString(str, len) {
return Array.apply(null, {length: len + 1}).join(str).slice(0, len)
}
/**
* Pad `str` up to total length `max` with `chr`.

@@ -19,9 +30,28 @@ * If `str` is longer than `max`, padRight will return `str` unaltered.

str = String(str)
var length = 1 + max - wcwidth(str)
var length = max - wcwidth(str)
if (length <= 0) return str
return str + Array.apply(null, {length: length})
.join(chr || ' ')
return str + repeatString(chr || ' ', length)
}
/**
* Pad `str` up to total length `max` with `chr`.
* If `str` is longer than `max`, padCenter will return `str` unaltered.
*
* @param String str string to pad
* @param Number max total length of output string
* @param String chr optional. Character to pad with. default: ' '
* @return String padded str
*/
function padCenter(str, max, chr) {
str = str != null ? str : ''
str = String(str)
var length = max - wcwidth(str)
if (length <= 0) return str
var lengthLeft = Math.floor(length/2)
var lengthRight = length - lengthLeft
return repeatString(chr || ' ', lengthLeft) + str + repeatString(chr || ' ', lengthRight)
}
/**
* Pad `str` up to total length `max` with `chr`, on the left.

@@ -39,5 +69,5 @@ * If `str` is longer than `max`, padRight will return `str` unaltered.

str = String(str)
var length = 1 + max - wcwidth(str)
var length = max - wcwidth(str)
if (length <= 0) return str
return Array.apply(null, {length: length}).join(chr || ' ') + str
return repeatString(chr || ' ', length) + str
}

@@ -149,2 +179,3 @@

module.exports.padRight = padRight
module.exports.padCenter = padCenter
module.exports.padLeft = padLeft

@@ -154,2 +185,1 @@ module.exports.splitIntoLines = splitIntoLines

module.exports.truncateString = truncateString
SocketSocket SOC 2 Logo

Product

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc