diff options
-rw-r--r-- | node_modules/columnify/Makefile | 9 | ||||
-rw-r--r-- | node_modules/columnify/Readme.md | 201 | ||||
-rw-r--r-- | node_modules/columnify/columnify.js | 301 | ||||
-rw-r--r-- | node_modules/columnify/index.js | 213 | ||||
-rwxr-xr-x | node_modules/columnify/node_modules/strip-ansi/cli.js | 10 | ||||
-rw-r--r-- | node_modules/columnify/node_modules/strip-ansi/package.json | 19 | ||||
-rw-r--r-- | node_modules/columnify/node_modules/strip-ansi/readme.md | 12 | ||||
-rw-r--r-- | node_modules/columnify/node_modules/wcwidth/package.json | 3 | ||||
-rw-r--r-- | node_modules/columnify/package.json | 28 | ||||
-rw-r--r-- | package.json | 2 |
10 files changed, 612 insertions, 186 deletions
diff --git a/node_modules/columnify/Makefile b/node_modules/columnify/Makefile new file mode 100644 index 000000000..3ae543a94 --- /dev/null +++ b/node_modules/columnify/Makefile @@ -0,0 +1,9 @@ + +all: columnify.js + +prepublish: all + +columnify.js: index.js package.json + 6to5 index.js > columnify.js + +.PHONY: all prepublish diff --git a/node_modules/columnify/Readme.md b/node_modules/columnify/Readme.md index 43ae36c2c..b2b846f36 100644 --- a/node_modules/columnify/Readme.md +++ b/node_modules/columnify/Readme.md @@ -1,6 +1,10 @@ # columnify [![Build Status](https://travis-ci.org/timoxley/columnify.png?branch=master)](https://travis-ci.org/timoxley/columnify) +[![NPM Version](https://img.shields.io/npm/v/columnify.svg?style=flat)](https://npmjs.org/package/columnify) +[![License](http://img.shields.io/npm/l/columnify.svg?style=flat)](LICENSE) +[![Dependency Status](https://david-dm.org/timoxley/columnify.svg)](https://david-dm.org/timoxley/columnify) +[![devDependency Status](https://david-dm.org/timoxley/columnify/dev-status.svg)](https://david-dm.org/timoxley/columnify#info=devDependencies) Create text-based columns suitable for console output from objects or arrays of objects. @@ -36,7 +40,6 @@ console.log(columns) Objects are converted to a list of key/value pairs: ```javascript - var data = { "commander@0.6.1": 1, "minimatch@0.2.14": 3, @@ -100,15 +103,58 @@ mod1 0.0.1 module2 0.2.0 ``` -### Wrapping Column Cells +### Filtering & Ordering Columns -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. +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). ```javascript +var data = [{ + name: 'module1', + description: 'some description', + version: '0.0.1', +}, { + name: 'module2', + description: 'another description', + version: '0.2.0', +}] +var columns = columnify(data, { + columns: ['name', 'version'] +}) + +console.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: + +```javascript +var columns = columnify(data, { + optionName: optionValue, + config: { + columnName: {optionName: optionValue}, + columnName: {optionName: optionValue}, + } +}) +``` + +### 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. + +```javascript var columns = columnify([{ name: 'mod1', description: 'some description which happens to be far larger than the max', @@ -117,24 +163,41 @@ var columns = columnify([{ name: 'module-two', description: 'another description larger than the max', version: '0.2.0', +}], { + minWidth: 20, + config: { + description: {maxWidth: 30} + } }) console.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 +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 ``` -### Truncating Column Cells +#### 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. Truncation respects word boundaries. A truncation marker, -`…` will appear next to the last word in any truncated line. +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. ```javascript var columns = columnify(data, { @@ -155,43 +218,9 @@ mod1 some description… 0.0.1 module-two another description… 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). - -```javascript -var data = [{ - name: 'module1', - description: 'some description', - version: '0.0.1', -}, { - name: 'module2', - description: 'another description', - version: '0.2.0', -}] - -var columns = columnify(data, { - columns: ['name', 'version'] // note description not included -}) - -console.log(columns) -``` - -#### Output: -``` -NAME VERSION -module1 0.0.1 -module2 0.2.0 -``` - - -## Other Configuration Options ### Align Right/Center +You can set the alignment of the column data by using the `align` option. ```js var data = { @@ -211,10 +240,12 @@ commander@2.0.0 1 debug@0.8.1 1 ``` -Align Center works in a similar way. +`align: 'center'` works in a similar way. + +### Padding Character -### Padding +Set a character to fill whitespace within columns with the `paddingChr` option. ```js var data = { @@ -232,7 +263,7 @@ shortKey................... veryVeryVeryVeryVeryLongVal veryVeryVeryVeryVeryLongKey shortVal................... ``` -### Preserve existing newlines +### Preserve Existing Newlines By default, `columnify` sanitises text by replacing any occurance of 1 or more whitespace characters with a single space. @@ -284,7 +315,7 @@ 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. ```javascript var columns = columnify(data, { @@ -309,10 +340,9 @@ module-two another description> 0.2.0 ### Custom Column Splitter If your columns need some bling, you can split columns with custom -characters. +characters by using the `columnSplitter` option. ```javascript - var columns = columnify(data, { columnSplitter: ' | ' }) @@ -326,6 +356,48 @@ mod1 | some description which happens to be far larger than the max | 0.0. 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. + +```javascript +var columns = columnify(data, { + showHeaders: false +}) +``` + +### 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 `headerTransform`. Both of these take a function and need to return a valid string. + +```javascript +var columns = columnify([{ + name: 'mod1', + description: 'SOME DESCRIPTION TEXT.' +}, { + name: 'module-two', + description: 'SOME SLIGHTLY LONGER DESCRIPTION TEXT.' +}], { + dataTransform: function(data) { + return data.toLowerCase() + }, + config: { + name: { + headingTransform: function(heading) { + heading = "module " + heading + return "*" + heading.toUpperCase() + "*" + } + } + } +}) +``` +#### Output: +``` +*MODULE NAME* DESCRIPTION +mod1 some description text. +module-two some slightly longer description text. +``` + + ## Multibyte Character Support `columnify` uses [mycoboco/wcwidth.js](https://github.com/mycoboco/wcwidth.js) to calculate length of multibyte characters: @@ -362,6 +434,25 @@ module-one some description 0.0.1 这是一个很长的名字的模块 这真的是一个描述的内容这个描述很长 0.3.3 ``` +## Contributions + +``` + project : columnify + repo age : 1 year, 2 months + active : 32 days + commits : 120 + files : 54 + authors : + 90 Tim Oxley 75.0% + 8 Tim 6.7% + 7 Arjun Mehta 5.8% + 6 Dany 5.0% + 5 Wei Gao 4.2% + 2 Dany Shaanan 1.7% + 1 Seth Miller 0.8% + 1 Isaac Z. Schlueter 0.8% +``` + ## License MIT diff --git a/node_modules/columnify/columnify.js b/node_modules/columnify/columnify.js new file mode 100644 index 000000000..548efc679 --- /dev/null +++ b/node_modules/columnify/columnify.js @@ -0,0 +1,301 @@ +"use strict"; + +var _toArray = function (arr) { return Array.isArray(arr) ? arr : Array.from(arr); }; + +var wcwidth = require("./width"); +var _require = require("./utils"); + +var padRight = _require.padRight; +var padCenter = _require.padCenter; +var padLeft = _require.padLeft; +var splitIntoLines = _require.splitIntoLines; +var splitLongWords = _require.splitLongWords; +var truncateString = _require.truncateString; + + +var DEFAULT_HEADING_TRANSFORM = function (key) { + return key.toUpperCase(); +}; + +var DEFAULT_DATA_TRANSFORM = function (cell, column, index) { + return cell; +}; + +var DEFAULTS = Object.freeze({ + maxWidth: Infinity, + minWidth: 0, + columnSplitter: " ", + truncate: false, + truncateMarker: "…", + preserveNewLines: false, + paddingChr: " ", + showHeaders: true, + headingTransform: DEFAULT_HEADING_TRANSFORM, + dataTransform: DEFAULT_DATA_TRANSFORM +}); + +module.exports = function (items) { + var options = arguments[1] === undefined ? {} : arguments[1]; + + + var columnConfigs = options.config || {}; + delete options.config; // remove config so doesn't appear on every column. + + var maxLineWidth = options.maxLineWidth || Infinity; + if (maxLineWidth === "auto") maxLineWidth = process.stdout.columns || Infinity; + delete options.maxLineWidth; // this is a line control option, don't pass it to column + + // Option defaults inheritance: + // options.config[columnName] => options => DEFAULTS + options = mixin({}, DEFAULTS, options); + + options.config = options.config || Object.create(null); + + options.spacing = options.spacing || "\n"; // probably useless + options.preserveNewLines = !!options.preserveNewLines; + options.showHeaders = !!options.showHeaders; + options.columns = options.columns || options.include; // alias include/columns, prefer columns if supplied + var columnNames = options.columns || []; // optional user-supplied columns to include + + items = toArray(items, columnNames); + + // if not suppled column names, automatically determine columns from data keys + if (!columnNames.length) { + items.forEach(function (item) { + for (var columnName in item) { + if (columnNames.indexOf(columnName) === -1) columnNames.push(columnName); + } + }); + } + + // initialize column defaults (each column inherits from options.config) + var columns = columnNames.reduce(function (columns, columnName) { + var column = Object.create(options); + columns[columnName] = mixin(column, columnConfigs[columnName]); + return columns; + }, Object.create(null)); + + // sanitize column settings + columnNames.forEach(function (columnName) { + var column = columns[columnName]; + column.name = columnName; + column.maxWidth = Math.ceil(column.maxWidth); + column.minWidth = Math.ceil(column.minWidth); + column.truncate = !!column.truncate; + column.align = column.align || "left"; + }); + + // sanitize data + items = items.map(function (item) { + var result = Object.create(null); + columnNames.forEach(function (columnName) { + // null/undefined -> '' + result[columnName] = item[columnName] != null ? item[columnName] : ""; + // toString everything + result[columnName] = "" + result[columnName]; + if (columns[columnName].preserveNewLines) { + // merge non-newline whitespace chars + result[columnName] = result[columnName].replace(/[^\S\n]/gmi, " "); + } else { + // merge all whitespace chars + result[columnName] = result[columnName].replace(/\s/gmi, " "); + } + }); + return result; + }); + + // transform data cells + columnNames.forEach(function (columnName) { + var column = columns[columnName]; + items = items.map(function (item, index) { + var col = Object.create(column); + item[columnName] = column.dataTransform(item[columnName], col, index); + + var changedKeys = Object.keys(col); + // disable default heading transform if we wrote to column.name + if (changedKeys.indexOf("name") !== -1) { + if (column.headingTransform !== DEFAULT_HEADING_TRANSFORM) return; + column.headingTransform = function (heading) { + return heading; + }; + } + changedKeys.forEach(function (key) { + return column[key] = col[key]; + }); + return item; + }); + }); + + // add headers + var headers = {}; + if (options.showHeaders) { + columnNames.forEach(function (columnName) { + var column = columns[columnName]; + headers[columnName] = column.headingTransform(column.name); + }); + items.unshift(headers); + } + // get actual max-width between min & max + // based on length of data in columns + 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, wcwidth(cur)))); + }, 0); + }); + + // split long words so they can break onto multiple lines + columnNames.forEach(function (columnName) { + var column = columns[columnName]; + items = items.map(function (item) { + item[columnName] = splitLongWords(item[columnName], column.width, column.truncateMarker); + return item; + }); + }); + + // wrap long lines. each item is now an array of lines. + columnNames.forEach(function (columnName) { + var column = columns[columnName]; + items = items.map(function (item, index) { + var cell = item[columnName]; + item[columnName] = splitIntoLines(cell, column.width); + + // if truncating required, only include first line + add truncation char + if (column.truncate && item[columnName].length > 1) { + item[columnName] = splitIntoLines(cell, column.width - wcwidth(column.truncateMarker)); + var firstLine = item[columnName][0]; + if (!endsWith(firstLine, column.truncateMarker)) item[columnName][0] += column.truncateMarker; + item[columnName] = item[columnName].slice(0, 1); + } + return item; + }); + }); + + // recalculate column widths from truncated output/lines + 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, wcwidth(cur)))); + }, 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, options.paddingChr); // merge lines into rows + // conceive output + return rows.reduce(function (output, row) { + return output.concat(row.reduce(function (rowOut, line) { + return rowOut.concat(line.join(options.columnSplitter)); + }, [])); + }, []).map(function (line) { + return truncateString(line, maxLineWidth); + }).join(options.spacing); +}; + +/** + * Convert wrapped lines into rows with padded values. + * + * @param Array items data to process + * @param Array columns column width settings for wrapping + * @param Array columnNames column ordering + * @return Array items wrapped in arrays, corresponding to lines + */ + +function createRows(items, columns, columnNames, paddingChr) { + return items.map(function (item) { + var row = []; + var numLines = 0; + columnNames.forEach(function (columnName) { + numLines = Math.max(numLines, item[columnName].length); + }); + // combine matching lines of each rows + for (var i = 0; i < numLines; i++) { + (function (i) { + row[i] = row[i] || []; + columnNames.forEach(function (columnName) { + var column = columns[columnName]; + var val = item[columnName][i] || ""; // || '' ensures empty columns get padded + if (column.align === "right") row[i].push(padLeft(val, column.width, paddingChr));else if (column.align === "center" || column.align === "centre") row[i].push(padCenter(val, column.width, paddingChr));else row[i].push(padRight(val, column.width, paddingChr)); + }); + })(i); + } + return row; + }); +} + +/** + * Object.assign + * + * @return Object Object with properties mixed in. + */ + +function mixin() { + for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { + args[_key] = arguments[_key]; + } + + if (Object.assign) return Object.assign.apply(Object, _toArray(args)); + return ObjectAssign.apply(undefined, _toArray(args)); +} + +function ObjectAssign(target, firstSource) { + "use strict"; + if (target === undefined || target === null) throw new TypeError("Cannot convert first argument to object"); + + var to = Object(target); + + var hasPendingException = false; + var pendingException; + + for (var i = 1; i < arguments.length; i++) { + var nextSource = arguments[i]; + if (nextSource === undefined || nextSource === null) continue; + + var keysArray = Object.keys(Object(nextSource)); + for (var nextIndex = 0, len = keysArray.length; nextIndex < len; nextIndex++) { + var nextKey = keysArray[nextIndex]; + try { + var desc = Object.getOwnPropertyDescriptor(nextSource, nextKey); + if (desc !== undefined && desc.enumerable) to[nextKey] = nextSource[nextKey]; + } catch (e) { + if (!hasPendingException) { + hasPendingException = true; + pendingException = e; + } + } + } + + if (hasPendingException) throw pendingException; + } + return to; +} + +/** + * Adapted from String.prototype.endsWith polyfill. + */ + +function endsWith(target, searchString, position) { + position = position || target.length; + position = position - searchString.length; + var lastIndex = target.lastIndexOf(searchString); + return lastIndex !== -1 && lastIndex === position; +} + + +function toArray(items, columnNames) { + if (Array.isArray(items)) return items; + var rows = []; + for (var key in items) { + var item = {}; + item[columnNames[0] || "key"] = key; + item[columnNames[1] || "value"] = items[key]; + rows.push(item); + } + return rows; +} + diff --git a/node_modules/columnify/index.js b/node_modules/columnify/index.js index 8c15c993e..781e683aa 100644 --- a/node_modules/columnify/index.js +++ b/node_modules/columnify/index.js @@ -1,23 +1,20 @@ "use strict" -var wcwidth = require('./width') -var utils = require('./utils') -var padRight = utils.padRight -var padCenter = utils.padCenter -var padLeft = utils.padLeft -var splitIntoLines = utils.splitIntoLines -var splitLongWords = utils.splitLongWords -var truncateString = utils.truncateString - -var DEFAULT_HEADING_TRANSFORM = function(key) { - return key.toUpperCase() -} +const wcwidth = require('./width') +const { + padRight, + padCenter, + padLeft, + splitIntoLines, + splitLongWords, + truncateString +} = require('./utils') -var DEFAULT_DATA_TRANSFORM = function(cell, column, index) { - return cell -} +const DEFAULT_HEADING_TRANSFORM = key => key.toUpperCase() + +const DEFAULT_DATA_TRANSFORM = (cell, column, index) => cell -var DEFAULTS = { +const DEFAULTS = Object.freeze({ maxWidth: Infinity, minWidth: 0, columnSplitter: ' ', @@ -28,50 +25,50 @@ var DEFAULTS = { showHeaders: true, headingTransform: DEFAULT_HEADING_TRANSFORM, dataTransform: DEFAULT_DATA_TRANSFORM -} - -module.exports = function(items, options) { +}) - options = options || {} +module.exports = function(items, options = {}) { - var columnConfigs = options.config || {} + let columnConfigs = options.config || {} delete options.config // remove config so doesn't appear on every column. - var maxLineWidth = options.maxLineWidth || Infinity + let maxLineWidth = options.maxLineWidth || Infinity + if (maxLineWidth === 'auto') maxLineWidth = process.stdout.columns || Infinity delete options.maxLineWidth // this is a line control option, don't pass it to column // Option defaults inheritance: // options.config[columnName] => options => DEFAULTS - options = mixin(options, DEFAULTS) + options = mixin({}, DEFAULTS, options) + options.config = options.config || Object.create(null) options.spacing = options.spacing || '\n' // probably useless options.preserveNewLines = !!options.preserveNewLines options.showHeaders = !!options.showHeaders; options.columns = options.columns || options.include // alias include/columns, prefer columns if supplied - var columnNames = options.columns || [] // optional user-supplied columns to include + let columnNames = options.columns || [] // optional user-supplied columns to include items = toArray(items, columnNames) // if not suppled column names, automatically determine columns from data keys if (!columnNames.length) { items.forEach(function(item) { - for (var columnName in item) { + for (let columnName in item) { if (columnNames.indexOf(columnName) === -1) columnNames.push(columnName) } }) } // initialize column defaults (each column inherits from options.config) - var columns = columnNames.reduce(function(columns, columnName) { - var column = Object.create(options) + let columns = columnNames.reduce((columns, columnName) => { + let column = Object.create(options) columns[columnName] = mixin(column, columnConfigs[columnName]) return columns }, Object.create(null)) // sanitize column settings - columnNames.forEach(function(columnName) { - var column = columns[columnName] + columnNames.forEach(columnName => { + let column = columns[columnName] column.name = columnName column.maxWidth = Math.ceil(column.maxWidth) column.minWidth = Math.ceil(column.minWidth) @@ -80,9 +77,9 @@ module.exports = function(items, options) { }) // sanitize data - items = items.map(function(item) { - var result = Object.create(null) - columnNames.forEach(function(columnName) { + items = items.map(item => { + let result = Object.create(null) + columnNames.forEach(columnName => { // null/undefined -> '' result[columnName] = item[columnName] != null ? item[columnName] : '' // toString everything @@ -99,94 +96,92 @@ module.exports = function(items, options) { }) // transform data cells - columnNames.forEach(function(columnName) { - var column = columns[columnName] - items = items.map(function(item, index) { - var col = Object.create(column) + columnNames.forEach(columnName => { + let column = columns[columnName] + items = items.map((item, index) => { + let col = Object.create(column) item[columnName] = column.dataTransform(item[columnName], col, index) - var changedKeys = Object.keys(col) + let changedKeys = Object.keys(col) // disable default heading transform if we wrote to column.name if (changedKeys.indexOf('name') !== -1) { if (column.headingTransform !== DEFAULT_HEADING_TRANSFORM) return - column.headingTransform = function(heading) {return heading} + column.headingTransform = heading => heading } - changedKeys.forEach(function(key) { - column[key] = col[key] - }) + changedKeys.forEach(key => column[key] = col[key]) return item }) }) // add headers - var headers = {} + let headers = {} if(options.showHeaders) { - columnNames.forEach(function(columnName) { - var column = columns[columnName] + columnNames.forEach(columnName => { + let column = columns[columnName] headers[columnName] = column.headingTransform(column.name) }) items.unshift(headers) } // get actual max-width between min & max // based on length of data in columns - columnNames.forEach(function(columnName) { - var column = columns[columnName] - column.width = items.map(function(item) { - return item[columnName] - }).reduce(function(min, cur) { + columnNames.forEach(columnName => { + let column = columns[columnName] + column.width = items + .map(item => item[columnName]) + .reduce((min, cur) => { return Math.max(min, Math.min(column.maxWidth, Math.max(column.minWidth, wcwidth(cur)))) }, 0) }) // split long words so they can break onto multiple lines - columnNames.forEach(function(columnName) { - var column = columns[columnName] - items = items.map(function(item) { + columnNames.forEach(columnName => { + let column = columns[columnName] + items = items.map(item => { item[columnName] = splitLongWords(item[columnName], column.width, column.truncateMarker) return item }) }) // wrap long lines. each item is now an array of lines. - columnNames.forEach(function(columnName) { - var column = columns[columnName] - items = items.map(function(item, index) { - var cell = item[columnName] + columnNames.forEach(columnName => { + let column = columns[columnName] + items = items.map((item, index) => { + let cell = item[columnName] item[columnName] = splitIntoLines(cell, column.width) // if truncating required, only include first line + add truncation char if (column.truncate && item[columnName].length > 1) { - item[columnName] = splitIntoLines(cell, column.width - wcwidth(column.truncateMarker)) - var firstLine = item[columnName][0] - if (!endsWith(firstLine, column.truncateMarker)) item[columnName][0] += column.truncateMarker - item[columnName] = item[columnName].slice(0, 1) + item[columnName] = splitIntoLines(cell, column.width - wcwidth(column.truncateMarker)) + let firstLine = item[columnName][0] + if (!endsWith(firstLine, column.truncateMarker)) item[columnName][0] += column.truncateMarker + item[columnName] = item[columnName].slice(0, 1) } return item }) }) // recalculate column widths from truncated output/lines - columnNames.forEach(function(columnName) { - var column = columns[columnName] - column.width = items.map(function(item) { - return item[columnName].reduce(function(min, cur) { + columnNames.forEach(columnName => { + let column = columns[columnName] + column.width = items.map(item => { + return item[columnName].reduce((min, cur) => { return Math.max(min, Math.min(column.maxWidth, Math.max(column.minWidth, wcwidth(cur)))) }, 0) - }).reduce(function(min, cur) { + }).reduce((min, cur) => { return Math.max(min, Math.min(column.maxWidth, Math.max(column.minWidth, cur))) }, 0) }) - var rows = createRows(items, columns, columnNames, options.paddingChr) // merge lines into rows + let rows = createRows(items, columns, columnNames, options.paddingChr) // merge lines into rows // conceive output - return rows.reduce(function(output, row) { - return output.concat(row.reduce(function(rowOut, line) { + return rows.reduce((output, row) => { + return output.concat(row.reduce((rowOut, line) => { return rowOut.concat(line.join(options.columnSplitter)) }, [])) - }, []).map(function(line) { - return truncateString(line, maxLineWidth) - }).join(options.spacing) + }, []) + .map(line => truncateString(line, maxLineWidth)) + .join(options.spacing) } /** @@ -199,18 +194,18 @@ module.exports = function(items, options) { */ function createRows(items, columns, columnNames, paddingChr) { - return items.map(function(item) { - var row = [] - var numLines = 0 - columnNames.forEach(function(columnName) { + return items.map(item => { + let row = [] + let numLines = 0 + columnNames.forEach(columnName => { numLines = Math.max(numLines, item[columnName].length) }) // combine matching lines of each rows - for (var i = 0; i < numLines; i++) { + for (let i = 0; i < numLines; i++) { row[i] = row[i] || [] - columnNames.forEach(function(columnName) { - var column = columns[columnName] - var val = item[columnName][i] || '' // || '' ensures empty columns get padded + columnNames.forEach(columnName => { + let column = columns[columnName] + let val = item[columnName][i] || '' // || '' ensures empty columns get padded if (column.align === 'right') row[i].push(padLeft(val, column.width, paddingChr)) else if (column.align === 'center' || column.align === 'centre') row[i].push(padCenter(val, column.width, paddingChr)) else row[i].push(padRight(val, column.width, paddingChr)) @@ -221,22 +216,50 @@ function createRows(items, columns, columnNames, paddingChr) { } /** - * Generic source->target mixin. - * Copy properties from `source` into `target` if target doesn't have them. - * Destructive. Modifies `target`. + * Object.assign * - * @param target Object target for mixin properties. - * @param source Object source of mixin properties. - * @return Object `target` after mixin applied. + * @return Object Object with properties mixed in. */ -function mixin(target, source) { - source = source || {} - for (var key in source) { - if (target.hasOwnProperty(key)) continue - target[key] = source[key] +function mixin(...args) { + if (Object.assign) return Object.assign(...args) + return ObjectAssign(...args) +} + +function ObjectAssign(target, firstSource) { + "use strict"; + if (target === undefined || target === null) + throw new TypeError("Cannot convert first argument to object"); + + var to = Object(target); + + var hasPendingException = false; + var pendingException; + + for (var i = 1; i < arguments.length; i++) { + var nextSource = arguments[i]; + if (nextSource === undefined || nextSource === null) + continue; + + var keysArray = Object.keys(Object(nextSource)); + for (var nextIndex = 0, len = keysArray.length; nextIndex < len; nextIndex++) { + var nextKey = keysArray[nextIndex]; + try { + var desc = Object.getOwnPropertyDescriptor(nextSource, nextKey); + if (desc !== undefined && desc.enumerable) + to[nextKey] = nextSource[nextKey]; + } catch (e) { + if (!hasPendingException) { + hasPendingException = true; + pendingException = e; + } + } + } + + if (hasPendingException) + throw pendingException; } - return target + return to; } /** @@ -246,16 +269,16 @@ function mixin(target, source) { function endsWith(target, searchString, position) { position = position || target.length; position = position - searchString.length; - var lastIndex = target.lastIndexOf(searchString); + let lastIndex = target.lastIndexOf(searchString); return lastIndex !== -1 && lastIndex === position; } function toArray(items, columnNames) { if (Array.isArray(items)) return items - var rows = [] - for (var key in items) { - var item = {} + let rows = [] + for (let key in items) { + let item = {} item[columnNames[0] || 'key'] = key item[columnNames[1] || 'value'] = items[key] rows.push(item) diff --git a/node_modules/columnify/node_modules/strip-ansi/cli.js b/node_modules/columnify/node_modules/strip-ansi/cli.js index 5b9546aab..b83f63b90 100755 --- a/node_modules/columnify/node_modules/strip-ansi/cli.js +++ b/node_modules/columnify/node_modules/strip-ansi/cli.js @@ -34,12 +34,12 @@ if (argv.indexOf('--version') !== -1) { return; } -if (process.stdin.isTTY) { - if (!input) { - help(); - return; - } +if (!input && process.stdin.isTTY) { + help(); + return; +} +if (input) { init(fs.readFileSync(input, 'utf8')); } else { process.stdin.setEncoding('utf8'); diff --git a/node_modules/columnify/node_modules/strip-ansi/package.json b/node_modules/columnify/node_modules/strip-ansi/package.json index 89d1041bd..f04f66f75 100644 --- a/node_modules/columnify/node_modules/strip-ansi/package.json +++ b/node_modules/columnify/node_modules/strip-ansi/package.json @@ -1,11 +1,11 @@ { "name": "strip-ansi", - "version": "2.0.0", + "version": "2.0.1", "description": "Strip ANSI escape codes", "license": "MIT", "repository": { "type": "git", - "url": "git://github.com/sindresorhus/strip-ansi" + "url": "https://github.com/sindresorhus/strip-ansi" }, "author": { "name": "Sindre Sorhus", @@ -56,15 +56,15 @@ "devDependencies": { "mocha": "*" }, - "gitHead": "c5e780acc07532f5d651cfb6ea035198095c6c74", + "gitHead": "1eff0936c01f89efa312d9d51deed137259871a1", "bugs": { "url": "https://github.com/sindresorhus/strip-ansi/issues" }, "homepage": "https://github.com/sindresorhus/strip-ansi", - "_id": "strip-ansi@2.0.0", - "_shasum": "fa8d69432e97674746f55f51d076ae78b18df13f", + "_id": "strip-ansi@2.0.1", + "_shasum": "df62c1aa94ed2f114e1d0f21fd1d50482b79a60e", "_from": "strip-ansi@>=2.0.0 <3.0.0", - "_npmVersion": "1.4.14", + "_npmVersion": "1.4.28", "_npmUser": { "name": "sindresorhus", "email": "sindresorhus@gmail.com" @@ -80,10 +80,9 @@ } ], "dist": { - "shasum": "fa8d69432e97674746f55f51d076ae78b18df13f", - "tarball": "http://registry.npmjs.org/strip-ansi/-/strip-ansi-2.0.0.tgz" + "shasum": "df62c1aa94ed2f114e1d0f21fd1d50482b79a60e", + "tarball": "http://registry.npmjs.org/strip-ansi/-/strip-ansi-2.0.1.tgz" }, "directories": {}, - "_resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-2.0.0.tgz", - "readme": "ERROR: No README data found!" + "_resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-2.0.1.tgz" } diff --git a/node_modules/columnify/node_modules/strip-ansi/readme.md b/node_modules/columnify/node_modules/strip-ansi/readme.md index 5477079d0..53ec26436 100644 --- a/node_modules/columnify/node_modules/strip-ansi/readme.md +++ b/node_modules/columnify/node_modules/strip-ansi/readme.md @@ -15,7 +15,7 @@ $ npm install --save strip-ansi ```js var stripAnsi = require('strip-ansi'); -stripAnsi('\x1b[4mcake\x1b[0m'); +stripAnsi('\u001b[4mcake\u001b[0m'); //=> 'cake' ``` @@ -29,12 +29,12 @@ $ npm install --global strip-ansi ```sh $ strip-ansi --help -Usage - $ strip-ansi <input-file> > <output-file> - $ cat <input-file> | strip-ansi > <output-file> + Usage + strip-ansi <input-file> > <output-file> + cat <input-file> | strip-ansi > <output-file> -Example - $ strip-ansi unicorn.txt > unicorn-stripped.txt + Example + strip-ansi unicorn.txt > unicorn-stripped.txt ``` diff --git a/node_modules/columnify/node_modules/wcwidth/package.json b/node_modules/columnify/node_modules/wcwidth/package.json index 4744d9dc3..49fc6f040 100644 --- a/node_modules/columnify/node_modules/wcwidth/package.json +++ b/node_modules/columnify/node_modules/wcwidth/package.json @@ -56,5 +56,6 @@ "shasum": "02d059ff7a8fc741e0f6b5da1e69b2b40daeca6f", "tarball": "http://registry.npmjs.org/wcwidth/-/wcwidth-1.0.0.tgz" }, - "_resolved": "https://registry.npmjs.org/wcwidth/-/wcwidth-1.0.0.tgz" + "_resolved": "https://registry.npmjs.org/wcwidth/-/wcwidth-1.0.0.tgz", + "readme": "ERROR: No README data found!" } diff --git a/node_modules/columnify/package.json b/node_modules/columnify/package.json index c60e1d9de..a27567234 100644 --- a/node_modules/columnify/package.json +++ b/node_modules/columnify/package.json @@ -1,18 +1,20 @@ { "name": "columnify", - "version": "1.3.2", + "version": "1.4.1", "description": "Render data in text columns. supports in-column text-wrap.", - "main": "index.js", + "main": "columnify.js", "scripts": { "pretest": "npm prune", - "test": "tape test/*.js | tap-spec", - "bench": "npm test && node bench" + "test": "make prepublish && tape test/*.js | tap-spec", + "bench": "npm test && node bench", + "prepublish": "make prepublish" }, "author": { "name": "Tim Oxley" }, "license": "MIT", "devDependencies": { + "6to5": "^3.0.9", "chalk": "^0.5.1", "tap-spec": "^2.1.1", "tape": "^3.0.3" @@ -41,12 +43,12 @@ "directories": { "test": "test" }, - "gitHead": "5c7d4363a8d6178f0d415e8bdaf692281fe71975", - "_id": "columnify@1.3.2", - "_shasum": "61bd578a9269ae6fd949ce36fff589f3702c7867", - "_from": "columnify@>=1.3.2 <1.4.0", - "_npmVersion": "2.1.10", - "_nodeVersion": "0.10.33", + "gitHead": "24371e9c12287ce4d28f19d704a28059f3acd42b", + "_id": "columnify@1.4.1", + "_shasum": "30555796379865b016189c228cb0061764270ed0", + "_from": "columnify@>=1.4.1 <1.5.0", + "_npmVersion": "2.3.0", + "_nodeVersion": "0.10.35", "_npmUser": { "name": "timoxley", "email": "secoif@gmail.com" @@ -58,8 +60,8 @@ } ], "dist": { - "shasum": "61bd578a9269ae6fd949ce36fff589f3702c7867", - "tarball": "http://registry.npmjs.org/columnify/-/columnify-1.3.2.tgz" + "shasum": "30555796379865b016189c228cb0061764270ed0", + "tarball": "http://registry.npmjs.org/columnify/-/columnify-1.4.1.tgz" }, - "_resolved": "https://registry.npmjs.org/columnify/-/columnify-1.3.2.tgz" + "_resolved": "https://registry.npmjs.org/columnify/-/columnify-1.4.1.tgz" } diff --git a/package.json b/package.json index 969fab32f..8bf1a0838 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "chmodr": "~0.1.0", "chownr": "0", "cmd-shim": "~2.0.1", - "columnify": "~1.3.2", + "columnify": "~1.4.1", "config-chain": "~1.1.8", "dezalgo": "~1.0.1", "editor": "~0.1.0", |