Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorisaacs <i@izs.me>2014-06-06 09:36:36 +0400
committerisaacs <i@izs.me>2014-06-06 09:36:36 +0400
commit6d6f094e7b773939cc2525baa9567b9c981485eb (patch)
tree054d6b19077ffbb576759f8f91119f0f1fe2b5c9 /node_modules/columnify/Readme.md
parentab8270d5d1c0dda55b71b073a93a7828074de0d8 (diff)
columnify@1.1.0
Diffstat (limited to 'node_modules/columnify/Readme.md')
-rw-r--r--node_modules/columnify/Readme.md229
1 files changed, 194 insertions, 35 deletions
diff --git a/node_modules/columnify/Readme.md b/node_modules/columnify/Readme.md
index 652037965..a20739b65 100644
--- a/node_modules/columnify/Readme.md
+++ b/node_modules/columnify/Readme.md
@@ -2,8 +2,12 @@
[![Build Status](https://travis-ci.org/timoxley/columnify.png?branch=master)](https://travis-ci.org/timoxley/columnify)
-Create text-based columns suitable for console output.
-Supports minimum and maximum column widths via truncation and text wrapping.
+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](https://github.com/isaacs/npm/pull/2328).
@@ -19,7 +23,7 @@ $ npm install --save columnify@latest
## Usage
-```js
+```javascript
var columnify = require('columnify')
var columns = columnify(data, options)
console.log(columns)
@@ -27,14 +31,56 @@ console.log(columns)
## Examples
-### Simple Columns
+### Columnify Objects
-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.
+Objects are converted to a list of key/value pairs:
-```js
+```javascript
+
+var data = {
+ "commander@0.6.1": 1,
+ "minimatch@0.2.14": 3,
+ "mkdirp@0.3.5": 2,
+ "sigmund@1.0.0": 3
+}
+
+console.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
+
+```javascript
+var data = {
+ "commander@0.6.1": 1,
+ "minimatch@0.2.14": 3,
+ "mkdirp@0.3.5": 2,
+ "sigmund@1.0.0": 3
+}
+
+console.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.
+
+```javascript
var columnify = require('columnify')
var columns = columnify([{
@@ -47,6 +93,7 @@ var columns = columnify([{
console.log(columns)
```
+#### Output:
```
NAME VERSION
mod1 0.0.1
@@ -60,8 +107,7 @@ 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.
-```js
-var columnify = require('columnify')
+```javascript
var columns = columnify([{
name: 'mod1',
@@ -75,6 +121,7 @@ var columns = columnify([{
console.log(columns)
```
+#### Output:
```
NAME DESCRIPTION VERSION
mod1 some description which happens 0.0.1
@@ -83,13 +130,13 @@ module-two another description larger 0.2.0
than the max
```
-### Truncated Columns
+### Truncating Column Cells
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.
-```js
+```javascript
var columns = columnify(data, {
truncate: true,
config: {
@@ -101,20 +148,124 @@ var columns = columnify(data, {
console.log(columns)
```
-
+#### Output:
```
NAME DESCRIPTION VERSION
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
+
+```js
+var data = {
+ "mocha@1.18.2": 1,
+ "commander@2.0.0": 1,
+ "debug@0.8.1": 1
+}
+
+columnify(data, {config: {value: {align: 'right'}}})
+```
+
+#### Output:
+```
+KEY VALUE
+mocha@1.18.2 1
+commander@2.0.0 1
+debug@0.8.1 1
+```
+
+### 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.
+
+```javascript
+var data = [{
+ name: "glob@3.2.9",
+ paths: [
+ "node_modules/tap/node_modules/glob",
+ "node_modules/tape/node_modules/glob"
+ ].join('\n')
+}, {
+ name: "nopt@2.2.1",
+ paths: [
+ "node_modules/tap/node_modules/nopt"
+ ]
+}, {
+ name: "runforcover@0.0.2",
+ paths: "node_modules/tap/node_modules/runforcover"
+}]
+
+console.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`:
+
+```javascript
+console.log(columnify(data, {preserveNewLines: false}))
+// or just
+console.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
`…`.
-```js
+```javascript
var columns = columnify(data, {
truncate: true,
truncateMarker: '>',
@@ -127,7 +278,7 @@ var columns = columnify(data, {
console.log(columns)
```
-
+#### Output:
```
NAME DESCRIPTION VERSION
mod1 some description> 0.0.1
@@ -139,7 +290,7 @@ module-two another description> 0.2.0
If your columns need some bling, you can split columns with custom
characters.
-```js
+```javascript
var columns = columnify(data, {
columnSplitter: ' | '
@@ -147,43 +298,51 @@ var columns = columnify(data, {
console.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
```
-### Filtering & Ordering Columns
+## Multibyte Character Support
-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 an "include" array:
+`columnify` uses [mycoboco/wcwidth.js](https://github.com/mycoboco/wcwidth.js) to calculate length of multibyte characters:
-```js
+```javascript
var data = [{
- name: 'module1',
+ name: 'module-one',
description: 'some description',
version: '0.0.1',
}, {
- name: 'module2',
- description: 'another description',
- version: '0.2.0',
+ name: '这是一个很长的名字的模块',
+ description: '这真的是一个描述的内容这个描述很长',
+ version: "0.3.3"
}]
-var columns = columnify(data, {
- include: ['name', 'version'] // note description not included
-})
+console.log(columnify(data))
+```
-console.log(columns)
+#### 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 VERSION
-module1 0.0.1
-module2 0.2.0
+NAME DESCRIPTION VERSION
+module-one some description 0.0.1
+这是一个很长的名字的模块 这真的是一个描述的内容这个描述很长 0.3.3
```
+
## License
MIT
+
+