Added logging, changed some directory structure

This commit is contained in:
2018-01-13 21:33:40 -05:00
parent f079a5f067
commit 8e72ffb917
73656 changed files with 35284 additions and 53718 deletions

View File

@@ -0,0 +1,24 @@
Copyright (c) 2016, Gajus Kuizinas (http://gajus.com/)
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the Gajus Kuizinas (http://gajus.com/) nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL ANUARY BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

View File

@@ -0,0 +1,671 @@
<a name="table"></a>
# Table
[![Travis build status](http://img.shields.io/travis/gajus/table/master.svg?style=flat)](https://travis-ci.org/gajus/table)
[![NPM version](http://img.shields.io/npm/v/table.svg?style=flat)](https://www.npmjs.com/package/table)
[![js-canonical-style](https://img.shields.io/badge/code%20style-canonical-brightgreen.svg?style=flat)](https://github.com/gajus/canonical)
* [Table](#table)
* [Features](#table-features)
* [Usage](#table-usage)
* [Cell Content Alignment](#table-usage-cell-content-alignment)
* [Column Width](#table-usage-column-width)
* [Custom Border](#table-usage-custom-border)
* [Draw Horizontal Line](#table-usage-draw-horizontal-line)
* [Padding Cell Content](#table-usage-padding-cell-content)
* [Predefined Border Templates](#table-usage-predefined-border-templates)
* [Streaming](#table-usage-streaming)
* [Text Truncation](#table-usage-text-truncation)
* [Text Wrapping](#table-usage-text-wrapping)
Produces a string that represents array data in a text table.
![Demo of table displaying a list of missions to the Moon.](./.README/demo.png)
<a name="table-features"></a>
## Features
* Works with strings containing [fullwidth](https://en.wikipedia.org/wiki/Halfwidth_and_fullwidth_forms) characters.
* Works with strings containing [ANSI escape codes](https://en.wikipedia.org/wiki/ANSI_escape_code).
* Configurable border characters.
* Configurable content alignment per column.
* Configurable content padding per column.
* Configurable column width.
* Text wrapping.
<a name="table-usage"></a>
## Usage
Table data is described using an array (rows) of array (cells).
```js
import {
table
} from 'table';
// Using commonjs?
// const {table} = require('table');
let data,
output;
data = [
['0A', '0B', '0C'],
['1A', '1B', '1C'],
['2A', '2B', '2C']
];
/**
* @typedef {string} table~cell
*/
/**
* @typedef {table~cell[]} table~row
*/
/**
* @typedef {Object} table~columns
* @property {string} alignment Cell content alignment (enum: left, center, right) (default: left).
* @property {number} width Column width (default: auto).
* @property {number} truncate Number of characters are which the content will be truncated (default: Infinity).
* @property {number} paddingLeft Cell content padding width left (default: 1).
* @property {number} paddingRight Cell content padding width right (default: 1).
*/
/**
* @typedef {Object} table~border
* @property {string} topBody
* @property {string} topJoin
* @property {string} topLeft
* @property {string} topRight
* @property {string} bottomBody
* @property {string} bottomJoin
* @property {string} bottomLeft
* @property {string} bottomRight
* @property {string} bodyLeft
* @property {string} bodyRight
* @property {string} bodyJoin
* @property {string} joinBody
* @property {string} joinLeft
* @property {string} joinRight
* @property {string} joinJoin
*/
/**
* Used to dynamically tell table whether to draw a line separating rows or not.
* The default behavior is to always return true.
*
* @typedef {function} drawJoin
* @param {number} index
* @param {number} size
* @return {boolean}
*/
/**
* @typedef {Object} table~config
* @property {table~border} border
* @property {table~columns[]} columns Column specific configuration.
* @property {table~columns} columnDefault Default values for all columns. Column specific settings overwrite the default values.
* @property {table~drawJoin} drawHorizontalLine
*/
/**
* Generates a text table.
*
* @param {table~row[]} rows
* @param {table~config} config
* @return {String}
*/
output = table(data);
console.log(output);
```
```
╔════╤════╤════╗
║ 0A │ 0B │ 0C ║
╟────┼────┼────╢
║ 1A │ 1B │ 1C ║
╟────┼────┼────╢
║ 2A │ 2B │ 2C ║
╚════╧════╧════╝
```
<a name="table-usage-cell-content-alignment"></a>
### Cell Content Alignment
`{string} config.columns[{number}].alignment` property controls content horizontal alignment within a cell.
Valid values are: "left", "right" and "center".
```js
let config,
data,
output;
data = [
['0A', '0B', '0C'],
['1A', '1B', '1C'],
['2A', '2B', '2C']
];
config = {
columns: {
0: {
alignment: 'left',
minWidth: 10
},
1: {
alignment: 'center',
minWidth: 10
},
2: {
alignment: 'right',
minWidth: 10
}
}
};
output = table(data, config);
console.log(output);
```
```
╔════════════╤════════════╤════════════╗
║ 0A │ 0B │ 0C ║
╟────────────┼────────────┼────────────╢
║ 1A │ 1B │ 1C ║
╟────────────┼────────────┼────────────╢
║ 2A │ 2B │ 2C ║
╚════════════╧════════════╧════════════╝
```
<a name="table-usage-column-width"></a>
### Column Width
`{number} config.columns[{number}].width` property restricts column width to a fixed width.
```js
let data,
output,
options;
data = [
['0A', '0B', '0C'],
['1A', '1B', '1C'],
['2A', '2B', '2C']
];
options = {
columns: {
1: {
width: 10
}
}
};
output = table(data, options);
console.log(output);
```
```
╔════╤════════════╤════╗
║ 0A │ 0B │ 0C ║
╟────┼────────────┼────╢
║ 1A │ 1B │ 1C ║
╟────┼────────────┼────╢
║ 2A │ 2B │ 2C ║
╚════╧════════════╧════╝
```
<a name="table-usage-custom-border"></a>
### Custom Border
`{object} config.border` property describes characters used to draw the table border.
```js
let config,
data,
output;
data = [
['0A', '0B', '0C'],
['1A', '1B', '1C'],
['2A', '2B', '2C']
];
config = {
border: {
topBody: ``,
topJoin: ``,
topLeft: ``,
topRight: ``,
bottomBody: ``,
bottomJoin: ``,
bottomLeft: ``,
bottomRight: ``,
bodyLeft: ``,
bodyRight: ``,
bodyJoin: ``,
joinBody: ``,
joinLeft: ``,
joinRight: ``,
joinJoin: ``
}
};
output = table(data, config);
console.log(output);
```
```
┌────┬────┬────┐
│ 0A │ 0B │ 0C │
├────┼────┼────┤
│ 1A │ 1B │ 1C │
├────┼────┼────┤
│ 2A │ 2B │ 2C │
└────┴────┴────┘
```
<a name="table-usage-draw-horizontal-line"></a>
### Draw Horizontal Line
`{function} config.drawHorizontalLine` property is a function that is called for every non-content row in the table. The result of the function `{boolean}` determines whether a row is drawn.
```js
let data,
output,
options;
data = [
['0A', '0B', '0C'],
['1A', '1B', '1C'],
['2A', '2B', '2C'],
['3A', '3B', '3C'],
['4A', '4B', '4C']
];
options = {
/**
* @typedef {function} drawJoin
* @param {number} index
* @param {number} size
* @return {boolean}
*/
drawHorizontalLine: (index, size) => {
return index === 0 || index === 1 || index === size - 1 || index === size;
}
};
output = table(data, options);
console.log(output);
```
```
╔════╤════╤════╗
║ 0A │ 0B │ 0C ║
╟────┼────┼────╢
║ 1A │ 1B │ 1C ║
║ 2A │ 2B │ 2C ║
║ 3A │ 3B │ 3C ║
╟────┼────┼────╢
║ 4A │ 4B │ 4C ║
╚════╧════╧════╝
```
<a name="table-usage-padding-cell-content"></a>
### Padding Cell Content
`{number} config.columns[{number}].paddingLeft` and `{number} config.columns[{number}].paddingRight` properties control content padding within a cell. Property value represents a number of whitespaces used to pad the content.
```js
let config,
data,
output;
data = [
['0A', 'AABBCC', '0C'],
['1A', '1B', '1C'],
['2A', '2B', '2C']
];
config = {
columns: {
0: {
paddingLeft: 3
},
1: {
width: 2,
paddingRight: 3
}
}
};
output = table(data, config);
console.log(output);
```
```
╔══════╤══════╤════╗
║ 0A │ AA │ 0C ║
║ │ BB │ ║
║ │ CC │ ║
╟──────┼──────┼────╢
║ 1A │ 1B │ 1C ║
╟──────┼──────┼────╢
║ 2A │ 2B │ 2C ║
╚══════╧══════╧════╝
```
<a name="table-usage-predefined-border-templates"></a>
### Predefined Border Templates
You can load one of the predefined border templates using `getBorderCharacters` function.
```js
import {
table,
getBorderCharacters
} from 'table';
let config,
data;
data = [
['0A', '0B', '0C'],
['1A', '1B', '1C'],
['2A', '2B', '2C']
];
config = {
border: getBorderCharacters(`name of the template`)
};
table(data, config);
```
```
# honeywell
╔════╤════╤════╗
║ 0A │ 0B │ 0C ║
╟────┼────┼────╢
║ 1A │ 1B │ 1C ║
╟────┼────┼────╢
║ 2A │ 2B │ 2C ║
╚════╧════╧════╝
# norc
┌────┬────┬────┐
│ 0A │ 0B │ 0C │
├────┼────┼────┤
│ 1A │ 1B │ 1C │
├────┼────┼────┤
│ 2A │ 2B │ 2C │
└────┴────┴────┘
# ramac (ASCII; for use in terminals that do not support Unicode characters)
+----+----+----+
| 0A | 0B | 0C |
|----|----|----|
| 1A | 1B | 1C |
|----|----|----|
| 2A | 2B | 2C |
+----+----+----+
# void (no borders; see "bordless table" section of the documentation)
0A 0B 0C
1A 1B 1C
2A 2B 2C
```
Raise [an issue](https://github.com/gajus/table/issues) if you'd like to contribute a new border template.
<a name="table-usage-predefined-border-templates-borderless-table"></a>
#### Borderless Table
Simply using "void" border character template creates a table with a lot of unnecessary spacing.
To create a more plesant to the eye table, reset the padding and remove the joining rows, e.g.
```js
let output;
output = table(data, {
border: getBorderCharacters(`void`),
columnDefault: {
paddingLeft: 0,
paddingRight: 1
},
drawJoin: () => {
return false
}
});
console.log(output);
```
```
0A 0B 0C
1A 1B 1C
2A 2B 2C
```
<a name="table-usage-streaming"></a>
### Streaming
`table` package exports `createStream` function used to draw a table and append rows.
`createStream` requires `{number} columnDefault.width` and `{number} columnCount` configuration properties.
```js
import {
createStream
} from 'table';
let config,
stream;
config = {
columnDefault: {
width: 50
},
columnCount: 1
};
stream = createStream(config);
setInterval(() => {
stream.write([new Date()]);
}, 500);
```
![Streaming current date.](./.README/streaming.gif)
`table` package uses ANSI escape codes to overwrite the output of the last line when a new row is printed.
The underlying implementation is explained in this [Stack Overflow answer](http://stackoverflow.com/a/32938658/368691).
Streaming supports all of the configuration properties and functionality of a static table (such as auto text wrapping, alignment and padding), e.g.
```js
import {
createStream
} from 'table';
import _ from 'lodash';
let config,
stream,
i;
config = {
columnDefault: {
width: 50
},
columnCount: 3,
columns: {
0: {
width: 10,
alignment: 'right'
},
1: {
alignment: 'center',
},
2: {
width: 10
}
}
};
stream = createStream(config);
i = 0;
setInterval(() => {
let random;
random = _.sample('abcdefghijklmnopqrstuvwxyz', _.random(1, 30)).join('');
stream.write([i++, new Date(), random]);
}, 500);
```
![Streaming random data.](./.README/streaming-random.gif)
<a name="table-usage-text-truncation"></a>
### Text Truncation
To handle a content that overflows the container width, `table` package implements [text wrapping](#table-usage-text-wrapping). However, sometimes you may want to truncate content that is too long to be displayed in the table.
`{number} config.columns[{number}].truncate` property (default: `Infinity`) truncates the text at the specified length.
```js
let config,
data,
output;
data = [
['Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus pulvinar nibh sed mauris convallis dapibus. Nunc venenatis tempus nulla sit amet viverra.']
];
config = {
columns: {
0: {
width: 20,
truncate: 100
}
}
};
output = table(data, config);
console.log(output);
```
```
╔══════════════════════╗
║ Lorem ipsum dolor si ║
║ t amet, consectetur ║
║ adipiscing elit. Pha ║
║ sellus pulvinar nibh ║
║ sed mauris conva... ║
╚══════════════════════╝
```
<a name="table-usage-text-wrapping"></a>
### Text Wrapping
`table` package implements auto text wrapping, i.e. text that has width greater than the container width will be separated into multiple lines, e.g.
```js
let config,
data,
output;
data = [
['Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus pulvinar nibh sed mauris convallis dapibus. Nunc venenatis tempus nulla sit amet viverra.']
];
config = {
columns: {
0: {
width: 20
}
}
};
output = table(data, config);
console.log(output);
```
```
╔══════════════════════╗
║ Lorem ipsum dolor si ║
║ t amet, consectetur ║
║ adipiscing elit. Pha ║
║ sellus pulvinar nibh ║
║ sed mauris convallis ║
║ dapibus. Nunc venena ║
║ tis tempus nulla sit ║
║ amet viverra. ║
╚══════════════════════╝
```
When `wrapWord` is `true` the text is broken at the nearest space or one of the special characters ("-", "_", "\", "/", ".", ",", ";"), e.g.
```js
let config,
data,
output;
data = [
['Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus pulvinar nibh sed mauris convallis dapibus. Nunc venenatis tempus nulla sit amet viverra.']
];
config = {
columns: {
0: {
width: 20,
wrapWord: true
}
}
};
output = table(data, config);
console.log(output);
```
```
╔══════════════════════╗
║ Lorem ipsum dolor ║
║ sit amet, ║
║ consectetur ║
║ adipiscing elit. ║
║ Phasellus pulvinar ║
║ nibh sed mauris ║
║ convallis dapibus. ║
║ Nunc venenatis ║
║ tempus nulla sit ║
║ amet viverra. ║
╚══════════════════════╝
```

View File

@@ -0,0 +1,106 @@
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _lodash = require('lodash');
var _lodash2 = _interopRequireDefault(_lodash);
var _stringWidth = require('string-width');
var _stringWidth2 = _interopRequireDefault(_stringWidth);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const alignments = ['left', 'right', 'center'];
/**
* @param {string} subject
* @param {number} width
* @returns {string}
*/
const alignLeft = (subject, width) => {
return subject + _lodash2.default.repeat(' ', width);
};
/**
* @param {string} subject
* @param {number} width
* @returns {string}
*/
const alignRight = (subject, width) => {
return _lodash2.default.repeat(' ', width) + subject;
};
/**
* @param {string} subject
* @param {number} width
* @returns {string}
*/
const alignCenter = (subject, width) => {
let halfWidth;
halfWidth = width / 2;
if (halfWidth % 2 === 0) {
return _lodash2.default.repeat(' ', halfWidth) + subject + _lodash2.default.repeat(' ', halfWidth);
} else {
halfWidth = _lodash2.default.floor(halfWidth);
return _lodash2.default.repeat(' ', halfWidth) + subject + _lodash2.default.repeat(' ', halfWidth + 1);
}
};
/**
* Pads a string to the left and/or right to position the subject
* text in a desired alignment within a container.
*
* @param {string} subject
* @param {number} containerWidth
* @param {string} alignment One of the valid options (left, right, center).
* @returns {string}
*/
exports.default = (subject, containerWidth, alignment) => {
if (!_lodash2.default.isString(subject)) {
throw new TypeError('Subject parameter value must be a string.');
}
if (!_lodash2.default.isNumber(containerWidth)) {
throw new TypeError('Container width parameter value must be a number.');
}
const subjectWidth = (0, _stringWidth2.default)(subject);
if (subjectWidth > containerWidth) {
// console.log('subjectWidth', subjectWidth, 'containerWidth', containerWidth, 'subject', subject);
throw new Error('Subject parameter value width cannot be greater than the container width.');
}
if (!_lodash2.default.isString(alignment)) {
throw new TypeError('Alignment parameter value must be a string.');
}
if (alignments.indexOf(alignment) === -1) {
throw new Error('Alignment parameter value must be a known alignment parameter value (left, right, center).');
}
if (subjectWidth === 0) {
return _lodash2.default.repeat(' ', containerWidth);
}
const availableWidth = containerWidth - subjectWidth;
if (alignment === 'left') {
return alignLeft(subject, availableWidth);
}
if (alignment === 'right') {
return alignRight(subject, availableWidth);
}
return alignCenter(subject, availableWidth);
};

View File

@@ -0,0 +1,34 @@
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _stringWidth = require('string-width');
var _stringWidth2 = _interopRequireDefault(_stringWidth);
var _alignString = require('./alignString');
var _alignString2 = _interopRequireDefault(_alignString);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
* @param {table~row[]} rows
* @param {Object} config
* @returns {table~row[]}
*/
exports.default = (rows, config) => {
return rows.map(cells => {
return cells.map((value, index1) => {
const column = config.columns[index1];
if ((0, _stringWidth2.default)(value) === column.width) {
return value;
} else {
return (0, _alignString2.default)(value, column.width, column.alignment);
}
});
});
};

View File

@@ -0,0 +1,47 @@
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _lodash = require('lodash');
var _lodash2 = _interopRequireDefault(_lodash);
var _stringWidth = require('string-width');
var _stringWidth2 = _interopRequireDefault(_stringWidth);
var _wrapWord = require('./wrapWord');
var _wrapWord2 = _interopRequireDefault(_wrapWord);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
* @param {string} value
* @param {number} columnWidth
* @param {boolean} useWrapWord
* @returns {number}
*/
exports.default = function (value, columnWidth) {
let useWrapWord = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
if (!_lodash2.default.isString(value)) {
throw new TypeError('Value must be a string.');
}
if (!_lodash2.default.isInteger(columnWidth)) {
throw new TypeError('Column width must be an integer.');
}
if (columnWidth < 1) {
throw new Error('Column width must be greater than 0.');
}
if (useWrapWord) {
return (0, _wrapWord2.default)(value, columnWidth).length;
}
return _lodash2.default.ceil((0, _stringWidth2.default)(value) / columnWidth);
};

View File

@@ -0,0 +1,23 @@
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _stringWidth = require('string-width');
var _stringWidth2 = _interopRequireDefault(_stringWidth);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
* Calculates width of each cell contents.
*
* @param {string[]} cells
* @returns {number[]}
*/
exports.default = cells => {
return cells.map(value => {
return (0, _stringWidth2.default)(value);
});
};

View File

@@ -0,0 +1,41 @@
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _lodash = require('lodash');
var _lodash2 = _interopRequireDefault(_lodash);
var _calculateCellWidthIndex = require('./calculateCellWidthIndex');
var _calculateCellWidthIndex2 = _interopRequireDefault(_calculateCellWidthIndex);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
* Produces an array of values that describe the largest value length (width) in every column.
*
* @param {Array[]} rows
* @returns {number[]}
*/
exports.default = rows => {
if (!rows[0]) {
throw new Error('Dataset must have at least one row.');
}
const columns = _lodash2.default.fill(Array(rows[0].length), 0);
_lodash2.default.forEach(rows, row => {
const columnWidthIndex = (0, _calculateCellWidthIndex2.default)(row);
_lodash2.default.forEach(columnWidthIndex, (valueWidth, index0) => {
if (columns[index0] < valueWidth) {
columns[index0] = valueWidth;
}
});
});
return columns;
};

View File

@@ -0,0 +1,48 @@
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _lodash = require('lodash');
var _lodash2 = _interopRequireDefault(_lodash);
var _calculateCellHeight = require('./calculateCellHeight');
var _calculateCellHeight2 = _interopRequireDefault(_calculateCellHeight);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
* Calculates the vertical row span index.
*
* @param {Array[]} rows
* @param {Object} config
* @returns {number[]}
*/
exports.default = (rows, config) => {
const tableWidth = rows[0].length;
const rowSpanIndex = [];
_lodash2.default.forEach(rows, cells => {
const cellHeightIndex = _lodash2.default.fill(Array(tableWidth), 1);
_lodash2.default.forEach(cells, (value, index1) => {
if (!_lodash2.default.isNumber(config.columns[index1].width)) {
throw new TypeError('column[index].width must be a number.');
}
if (!_lodash2.default.isBoolean(config.columns[index1].wrapWord)) {
throw new TypeError('column[index].wrapWord must be a boolean.');
}
cellHeightIndex[index1] = (0, _calculateCellHeight2.default)(value, config.columns[index1].width, config.columns[index1].wrapWord);
});
rowSpanIndex.push(_lodash2.default.max(cellHeightIndex));
});
return rowSpanIndex;
};

View File

@@ -0,0 +1,157 @@
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _lodash = require('lodash');
var _lodash2 = _interopRequireDefault(_lodash);
var _makeStreamConfig = require('./makeStreamConfig');
var _makeStreamConfig2 = _interopRequireDefault(_makeStreamConfig);
var _drawRow = require('./drawRow');
var _drawRow2 = _interopRequireDefault(_drawRow);
var _drawBorder = require('./drawBorder');
var _stringifyTableData = require('./stringifyTableData');
var _stringifyTableData2 = _interopRequireDefault(_stringifyTableData);
var _truncateTableData = require('./truncateTableData');
var _truncateTableData2 = _interopRequireDefault(_truncateTableData);
var _mapDataUsingRowHeightIndex = require('./mapDataUsingRowHeightIndex');
var _mapDataUsingRowHeightIndex2 = _interopRequireDefault(_mapDataUsingRowHeightIndex);
var _alignTableData = require('./alignTableData');
var _alignTableData2 = _interopRequireDefault(_alignTableData);
var _padTableData = require('./padTableData');
var _padTableData2 = _interopRequireDefault(_padTableData);
var _calculateRowHeightIndex = require('./calculateRowHeightIndex');
var _calculateRowHeightIndex2 = _interopRequireDefault(_calculateRowHeightIndex);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
* @param {Array} data
* @param {Object} config
* @returns {Array}
*/
const prepareData = (data, config) => {
let rows;
rows = (0, _stringifyTableData2.default)(data);
rows = (0, _truncateTableData2.default)(data, config);
const rowHeightIndex = (0, _calculateRowHeightIndex2.default)(rows, config);
rows = (0, _mapDataUsingRowHeightIndex2.default)(rows, rowHeightIndex, config);
rows = (0, _alignTableData2.default)(rows, config);
rows = (0, _padTableData2.default)(rows, config);
return rows;
};
/**
* @param {string[]} row
* @param {number[]} columnWidthIndex
* @param {Object} config
* @returns {undefined}
*/
const create = (row, columnWidthIndex, config) => {
const rows = prepareData([row], config);
const body = _lodash2.default.map(rows, literalRow => {
return (0, _drawRow2.default)(literalRow, config.border);
}).join('');
let output;
output = '';
output += (0, _drawBorder.drawBorderTop)(columnWidthIndex, config.border);
output += body;
output += (0, _drawBorder.drawBorderBottom)(columnWidthIndex, config.border);
output = _lodash2.default.trimEnd(output);
process.stdout.write(output);
};
/**
* @param {string[]} row
* @param {number[]} columnWidthIndex
* @param {Object} config
* @returns {undefined}
*/
const append = (row, columnWidthIndex, config) => {
const rows = prepareData([row], config);
const body = _lodash2.default.map(rows, literalRow => {
return (0, _drawRow2.default)(literalRow, config.border);
}).join('');
let output;
output = '\r\u001B[K';
output += (0, _drawBorder.drawBorderJoin)(columnWidthIndex, config.border);
output += body;
output += (0, _drawBorder.drawBorderBottom)(columnWidthIndex, config.border);
output = _lodash2.default.trimEnd(output);
process.stdout.write(output);
};
/**
* @param {Object} userConfig
* @returns {Object}
*/
exports.default = function () {
let userConfig = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
const config = (0, _makeStreamConfig2.default)(userConfig);
const columnWidthIndex = _lodash2.default.mapValues(config.columns, column => {
return column.width + column.paddingLeft + column.paddingRight;
});
let empty;
empty = true;
return {
/**
* @param {string[]} row
* @returns {undefined}
*/
write: row => {
if (row.length !== config.columnCount) {
throw new Error('Row cell count does not match the config.columnCount.');
}
if (empty) {
empty = false;
return create(row, columnWidthIndex, config);
} else {
return append(row, columnWidthIndex, config);
}
}
};
};

View File

@@ -0,0 +1,104 @@
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.drawBorderTop = exports.drawBorderJoin = exports.drawBorderBottom = exports.drawBorder = undefined;
var _lodash = require('lodash');
var _lodash2 = _interopRequireDefault(_lodash);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
* @typedef drawBorder~parts
* @property {string} left
* @property {string} right
* @property {string} body
* @property {string} join
*/
/**
* @param {number[]} columnSizeIndex
* @param {drawBorder~parts} parts
* @returns {string}
*/
const drawBorder = (columnSizeIndex, parts) => {
const columns = _lodash2.default.map(columnSizeIndex, size => {
return _lodash2.default.repeat(parts.body, size);
}).join(parts.join);
return parts.left + columns + parts.right + '\n';
};
/**
* @typedef drawBorderTop~parts
* @property {string} topLeft
* @property {string} topRight
* @property {string} topBody
* @property {string} topJoin
*/
/**
* @param {number[]} columnSizeIndex
* @param {drawBorderTop~parts} parts
* @returns {string}
*/
const drawBorderTop = (columnSizeIndex, parts) => {
return drawBorder(columnSizeIndex, {
body: parts.topBody,
join: parts.topJoin,
left: parts.topLeft,
right: parts.topRight
});
};
/**
* @typedef drawBorderJoin~parts
* @property {string} joinLeft
* @property {string} joinRight
* @property {string} joinBody
* @property {string} joinJoin
*/
/**
* @param {number[]} columnSizeIndex
* @param {drawBorderJoin~parts} parts
* @returns {string}
*/
const drawBorderJoin = (columnSizeIndex, parts) => {
return drawBorder(columnSizeIndex, {
body: parts.joinBody,
join: parts.joinJoin,
left: parts.joinLeft,
right: parts.joinRight
});
};
/**
* @typedef drawBorderBottom~parts
* @property {string} topLeft
* @property {string} topRight
* @property {string} topBody
* @property {string} topJoin
*/
/**
* @param {number[]} columnSizeIndex
* @param {drawBorderBottom~parts} parts
* @returns {string}
*/
const drawBorderBottom = (columnSizeIndex, parts) => {
return drawBorder(columnSizeIndex, {
body: parts.bottomBody,
join: parts.bottomJoin,
left: parts.bottomLeft,
right: parts.bottomRight
});
};
exports.drawBorder = drawBorder;
exports.drawBorderBottom = drawBorderBottom;
exports.drawBorderJoin = drawBorderJoin;
exports.drawBorderTop = drawBorderTop;

View File

@@ -0,0 +1,21 @@
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
/**
* @typedef {Object} drawRow~border
* @property {string} bodyLeft
* @property {string} bodyRight
* @property {string} bodyJoin
*/
/**
* @param {number[]} columns
* @param {drawRow~border} border
* @returns {string}
*/
exports.default = (columns, border) => {
return border.bodyLeft + columns.join(border.bodyJoin) + border.bodyRight + '\n';
};

View File

@@ -0,0 +1,63 @@
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _lodash = require('lodash');
var _lodash2 = _interopRequireDefault(_lodash);
var _drawBorder = require('./drawBorder');
var _drawRow = require('./drawRow');
var _drawRow2 = _interopRequireDefault(_drawRow);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
* @param {Array} rows
* @param {Object} border
* @param {Array} columnSizeIndex
* @param {Array} rowSpanIndex
* @param {Function} drawHorizontalLine
* @returns {string}
*/
exports.default = (rows, border, columnSizeIndex, rowSpanIndex, drawHorizontalLine) => {
let output;
let realRowIndex;
let rowHeight;
const rowCount = rows.length;
realRowIndex = 0;
output = '';
if (drawHorizontalLine(realRowIndex, rowCount)) {
output += (0, _drawBorder.drawBorderTop)(columnSizeIndex, border);
}
_lodash2.default.forEach(rows, (row, index0) => {
output += (0, _drawRow2.default)(row, border);
if (!rowHeight) {
rowHeight = rowSpanIndex[realRowIndex];
realRowIndex++;
}
rowHeight--;
if (rowHeight === 0 && index0 !== rowCount - 1 && drawHorizontalLine(realRowIndex, rowCount)) {
output += (0, _drawBorder.drawBorderJoin)(columnSizeIndex, border);
}
});
if (drawHorizontalLine(realRowIndex, rowCount)) {
output += (0, _drawBorder.drawBorderBottom)(columnSizeIndex, border);
}
return output;
};

View File

@@ -0,0 +1,126 @@
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
/* eslint-disable sort-keys */
/**
* @typedef border
* @property {string} topBody
* @property {string} topJoin
* @property {string} topLeft
* @property {string} topRight
* @property {string} bottomBody
* @property {string} bottomJoin
* @property {string} bottomLeft
* @property {string} bottomRight
* @property {string} bodyLeft
* @property {string} bodyRight
* @property {string} bodyJoin
* @property {string} joinBody
* @property {string} joinLeft
* @property {string} joinRight
* @property {string} joinJoin
*/
/**
* @param {string} name
* @returns {border}
*/
exports.default = name => {
if (name === 'honeywell') {
return {
topBody: '═',
topJoin: '╤',
topLeft: '╔',
topRight: '╗',
bottomBody: '═',
bottomJoin: '╧',
bottomLeft: '╚',
bottomRight: '╝',
bodyLeft: '║',
bodyRight: '║',
bodyJoin: '│',
joinBody: '─',
joinLeft: '╟',
joinRight: '╢',
joinJoin: '┼'
};
}
if (name === 'norc') {
return {
topBody: '─',
topJoin: '┬',
topLeft: '┌',
topRight: '┐',
bottomBody: '─',
bottomJoin: '┴',
bottomLeft: '└',
bottomRight: '┘',
bodyLeft: '│',
bodyRight: '│',
bodyJoin: '│',
joinBody: '─',
joinLeft: '├',
joinRight: '┤',
joinJoin: '┼'
};
}
if (name === 'ramac') {
return {
topBody: '-',
topJoin: '+',
topLeft: '+',
topRight: '+',
bottomBody: '-',
bottomJoin: '+',
bottomLeft: '+',
bottomRight: '+',
bodyLeft: '|',
bodyRight: '|',
bodyJoin: '|',
joinBody: '-',
joinLeft: '|',
joinRight: '|',
joinJoin: '|'
};
}
if (name === 'void') {
return {
topBody: '',
topJoin: '',
topLeft: '',
topRight: '',
bottomBody: '',
bottomJoin: '',
bottomLeft: '',
bottomRight: '',
bodyLeft: '',
bodyRight: '',
bodyJoin: '',
joinBody: '',
joinLeft: '',
joinRight: '',
joinJoin: ''
};
}
throw new Error('Unknown border template "' + name + '".');
};

View File

@@ -0,0 +1,24 @@
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getBorderCharacters = exports.createStream = exports.table = undefined;
var _table = require('./table');
var _table2 = _interopRequireDefault(_table);
var _createStream = require('./createStream');
var _createStream2 = _interopRequireDefault(_createStream);
var _getBorderCharacters = require('./getBorderCharacters');
var _getBorderCharacters2 = _interopRequireDefault(_getBorderCharacters);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
exports.table = _table2.default;
exports.createStream = _createStream2.default;
exports.getBorderCharacters = _getBorderCharacters2.default;

View File

@@ -0,0 +1,99 @@
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _lodash = require('lodash');
var _lodash2 = _interopRequireDefault(_lodash);
var _getBorderCharacters = require('./getBorderCharacters');
var _getBorderCharacters2 = _interopRequireDefault(_getBorderCharacters);
var _validateConfig = require('./validateConfig');
var _validateConfig2 = _interopRequireDefault(_validateConfig);
var _calculateMaximumColumnWidthIndex = require('./calculateMaximumColumnWidthIndex');
var _calculateMaximumColumnWidthIndex2 = _interopRequireDefault(_calculateMaximumColumnWidthIndex);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
* Merges user provided border characters with the default border ("honeywell") characters.
*
* @param {Object} border
* @returns {Object}
*/
const makeBorder = function makeBorder() {
let border = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
return Object.assign({}, (0, _getBorderCharacters2.default)('honeywell'), border);
};
/**
* Creates a configuration for every column using default
* values for the missing configuration properties.
*
* @param {Array[]} rows
* @param {Object} columns
* @param {Object} columnDefault
* @returns {Object}
*/
const makeColumns = function makeColumns(rows) {
let columns = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
let columnDefault = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
const maximumColumnWidthIndex = (0, _calculateMaximumColumnWidthIndex2.default)(rows);
_lodash2.default.times(rows[0].length, index => {
if (_lodash2.default.isUndefined(columns[index])) {
columns[index] = {};
}
columns[index] = _lodash2.default.assign({
alignment: 'left',
paddingLeft: 1,
paddingRight: 1,
truncate: Infinity,
width: maximumColumnWidthIndex[index],
wrapWord: false
}, columnDefault, columns[index]);
});
return columns;
};
/**
* Makes a new configuration object out of the userConfig object
* using default values for the missing configuration properties.
*
* @param {Array[]} rows
* @param {Object} userConfig
* @returns {Object}
*/
exports.default = function (rows) {
let userConfig = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
(0, _validateConfig2.default)('config.json', userConfig);
const config = _lodash2.default.cloneDeep(userConfig);
config.border = makeBorder(config.border);
config.columns = makeColumns(rows, config.columns, config.columnDefault);
if (!config.drawHorizontalLine) {
/**
* @returns {boolean}
*/
config.drawHorizontalLine = () => {
return true;
};
}
return config;
};

View File

@@ -0,0 +1,107 @@
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _lodash = require('lodash');
var _lodash2 = _interopRequireDefault(_lodash);
var _getBorderCharacters = require('./getBorderCharacters');
var _getBorderCharacters2 = _interopRequireDefault(_getBorderCharacters);
var _validateConfig = require('./validateConfig');
var _validateConfig2 = _interopRequireDefault(_validateConfig);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
* Merges user provided border characters with the default border ("honeywell") characters.
*
* @param {Object} border
* @returns {Object}
*/
const makeBorder = function makeBorder() {
let border = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
return Object.assign({}, (0, _getBorderCharacters2.default)('honeywell'), border);
};
/**
* Creates a configuration for every column using default
* values for the missing configuration properties.
*
* @param {number} columnCount
* @param {Object} columns
* @param {Object} columnDefault
* @returns {Object}
*/
const makeColumns = function makeColumns(columnCount) {
let columns = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
let columnDefault = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
_lodash2.default.times(columnCount, index => {
if (_lodash2.default.isUndefined(columns[index])) {
columns[index] = {};
}
columns[index] = Object.assign({
alignment: 'left',
paddingLeft: 1,
paddingRight: 1,
truncate: Infinity,
wrapWord: false
}, columnDefault, columns[index]);
});
return columns;
};
/**
* @typedef {Object} columnConfig
* @property {string} alignment
* @property {number} width
* @property {number} truncate
* @property {number} paddingLeft
* @property {number} paddingRight
*/
/**
* @typedef {Object} streamConfig
* @property {columnConfig} columnDefault
* @property {Object} border
* @property {columnConfig[]}
* @property {number} columnCount Number of columns in the table (required).
*/
/**
* Makes a new configuration object out of the userConfig object
* using default values for the missing configuration properties.
*
* @param {streamConfig} userConfig
* @returns {Object}
*/
exports.default = function () {
let userConfig = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
(0, _validateConfig2.default)('streamConfig.json', userConfig);
const config = _lodash2.default.cloneDeep(userConfig);
if (!config.columnDefault || !config.columnDefault.width) {
throw new Error('Must provide config.columnDefault.width when creating a stream.');
}
if (!config.columnCount) {
throw new Error('Must provide config.columnCount.');
}
config.border = makeBorder(config.border);
config.columns = makeColumns(config.columnCount, config.columns, config.columnDefault);
return config;
};

View File

@@ -0,0 +1,57 @@
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _lodash = require('lodash');
var _lodash2 = _interopRequireDefault(_lodash);
var _wrapString = require('./wrapString');
var _wrapString2 = _interopRequireDefault(_wrapString);
var _wrapWord = require('./wrapWord');
var _wrapWord2 = _interopRequireDefault(_wrapWord);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
* @param {Array} unmappedRows
* @param {number[]} rowHeightIndex
* @param {Object} config
* @returns {Array}
*/
exports.default = (unmappedRows, rowHeightIndex, config) => {
const tableWidth = unmappedRows[0].length;
const mappedRows = unmappedRows.map((cells, index0) => {
const rowHeight = _lodash2.default.times(rowHeightIndex[index0], () => {
return _lodash2.default.fill(Array(tableWidth), '');
});
// rowHeight
// [{row index within rowSaw; index2}]
// [{cell index within a virtual row; index1}]
_lodash2.default.forEach(cells, (value, index1) => {
let chunkedValue;
if (config.columns[index1].wrapWord) {
chunkedValue = (0, _wrapWord2.default)(value, config.columns[index1].width);
} else {
chunkedValue = (0, _wrapString2.default)(value, config.columns[index1].width);
}
_lodash2.default.forEach(chunkedValue, (part, index2) => {
rowHeight[index2][index1] = part;
});
});
return rowHeight;
});
return _lodash2.default.flatten(mappedRows);
};

View File

@@ -0,0 +1,26 @@
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _lodash = require('lodash');
var _lodash2 = _interopRequireDefault(_lodash);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
* @param {table~row[]} rows
* @param {Object} config
* @returns {table~row[]}
*/
exports.default = (rows, config) => {
return _lodash2.default.map(rows, cells => {
return _lodash2.default.map(cells, (value, index1) => {
const column = config.columns[index1];
return _lodash2.default.repeat(' ', column.paddingLeft) + value + _lodash2.default.repeat(' ', column.paddingRight);
});
});
};

View File

@@ -0,0 +1,114 @@
{
"$id": "config.json",
"$schema": "http://json-schema.org/draft-06/schema#",
"type": "object",
"properties": {
"border": {
"$ref": "#/definitions/borders"
},
"columns": {
"$ref": "#/definitions/columns"
},
"columnDefault": {
"$ref": "#/definitions/column"
},
"drawHorizontalLine": {
"typeof": "function"
}
},
"additionalProperties": false,
"definitions": {
"columns": {
"type": "object",
"patternProperties": {
"^[0-9]+$": {
"$ref": "#/definitions/column"
}
},
"additionalProperties": false
},
"column": {
"type": "object",
"properties": {
"alignment": {
"type": "string",
"enum": [
"left",
"right",
"center"
]
},
"width": {
"type": "number"
},
"wrapWord": {
"type": "boolean"
},
"truncate": {
"type": "number"
},
"paddingLeft": {
"type": "number"
},
"paddingRight": {
"type": "number"
}
},
"additionalProperties": false
},
"borders": {
"type": "object",
"properties": {
"topBody": {
"$ref": "#/definitions/border"
},
"topJoin": {
"$ref": "#/definitions/border"
},
"topLeft": {
"$ref": "#/definitions/border"
},
"topRight": {
"$ref": "#/definitions/border"
},
"bottomBody": {
"$ref": "#/definitions/border"
},
"bottomJoin": {
"$ref": "#/definitions/border"
},
"bottomLeft": {
"$ref": "#/definitions/border"
},
"bottomRight": {
"$ref": "#/definitions/border"
},
"bodyLeft": {
"$ref": "#/definitions/border"
},
"bodyRight": {
"$ref": "#/definitions/border"
},
"bodyJoin": {
"$ref": "#/definitions/border"
},
"joinBody": {
"$ref": "#/definitions/border"
},
"joinLeft": {
"$ref": "#/definitions/border"
},
"joinRight": {
"$ref": "#/definitions/border"
},
"joinJoin": {
"$ref": "#/definitions/border"
}
},
"additionalProperties": false
},
"border": {
"type": "string"
}
}
}

View File

@@ -0,0 +1,114 @@
{
"$id": "streamConfig.json",
"$schema": "http://json-schema.org/draft-06/schema#",
"type": "object",
"properties": {
"border": {
"$ref": "#/definitions/borders"
},
"columns": {
"$ref": "#/definitions/columns"
},
"columnDefault": {
"$ref": "#/definitions/column"
},
"columnCount": {
"type": "number"
}
},
"additionalProperties": false,
"definitions": {
"columns": {
"type": "object",
"patternProperties": {
"^[0-9]+$": {
"$ref": "#/definitions/column"
}
},
"additionalProperties": false
},
"column": {
"type": "object",
"properties": {
"alignment": {
"type": "string",
"enum": [
"left",
"right",
"center"
]
},
"width": {
"type": "number"
},
"wrapWord": {
"type": "boolean"
},
"truncate": {
"type": "number"
},
"paddingLeft": {
"type": "number"
},
"paddingRight": {
"type": "number"
}
},
"additionalProperties": false
},
"borders": {
"type": "object",
"properties": {
"topBody": {
"$ref": "#/definitions/border"
},
"topJoin": {
"$ref": "#/definitions/border"
},
"topLeft": {
"$ref": "#/definitions/border"
},
"topRight": {
"$ref": "#/definitions/border"
},
"bottomBody": {
"$ref": "#/definitions/border"
},
"bottomJoin": {
"$ref": "#/definitions/border"
},
"bottomLeft": {
"$ref": "#/definitions/border"
},
"bottomRight": {
"$ref": "#/definitions/border"
},
"bodyLeft": {
"$ref": "#/definitions/border"
},
"bodyRight": {
"$ref": "#/definitions/border"
},
"bodyJoin": {
"$ref": "#/definitions/border"
},
"joinBody": {
"$ref": "#/definitions/border"
},
"joinLeft": {
"$ref": "#/definitions/border"
},
"joinRight": {
"$ref": "#/definitions/border"
},
"joinJoin": {
"$ref": "#/definitions/border"
}
},
"additionalProperties": false
},
"border": {
"type": "string"
}
}
}

View File

@@ -0,0 +1,17 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
/**
* Casts all cell values to a string.
*
* @param {table~row[]} rows
* @returns {table~row[]}
*/
exports.default = rows => {
return rows.map(cells => {
return cells.map(String);
});
};

View File

@@ -0,0 +1,133 @@
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _drawTable = require('./drawTable');
var _drawTable2 = _interopRequireDefault(_drawTable);
var _calculateCellWidthIndex = require('./calculateCellWidthIndex');
var _calculateCellWidthIndex2 = _interopRequireDefault(_calculateCellWidthIndex);
var _makeConfig = require('./makeConfig');
var _makeConfig2 = _interopRequireDefault(_makeConfig);
var _calculateRowHeightIndex = require('./calculateRowHeightIndex');
var _calculateRowHeightIndex2 = _interopRequireDefault(_calculateRowHeightIndex);
var _mapDataUsingRowHeightIndex = require('./mapDataUsingRowHeightIndex');
var _mapDataUsingRowHeightIndex2 = _interopRequireDefault(_mapDataUsingRowHeightIndex);
var _alignTableData = require('./alignTableData');
var _alignTableData2 = _interopRequireDefault(_alignTableData);
var _padTableData = require('./padTableData');
var _padTableData2 = _interopRequireDefault(_padTableData);
var _validateTableData = require('./validateTableData');
var _validateTableData2 = _interopRequireDefault(_validateTableData);
var _stringifyTableData = require('./stringifyTableData');
var _stringifyTableData2 = _interopRequireDefault(_stringifyTableData);
var _truncateTableData = require('./truncateTableData');
var _truncateTableData2 = _interopRequireDefault(_truncateTableData);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
* @typedef {string} table~cell
*/
/**
* @typedef {table~cell[]} table~row
*/
/**
* @typedef {Object} table~columns
* @property {string} alignment Cell content alignment (enum: left, center, right) (default: left).
* @property {number} width Column width (default: auto).
* @property {number} truncate Number of characters are which the content will be truncated (default: Infinity).
* @property {number} paddingLeft Cell content padding width left (default: 1).
* @property {number} paddingRight Cell content padding width right (default: 1).
*/
/**
* @typedef {Object} table~border
* @property {string} topBody
* @property {string} topJoin
* @property {string} topLeft
* @property {string} topRight
* @property {string} bottomBody
* @property {string} bottomJoin
* @property {string} bottomLeft
* @property {string} bottomRight
* @property {string} bodyLeft
* @property {string} bodyRight
* @property {string} bodyJoin
* @property {string} joinBody
* @property {string} joinLeft
* @property {string} joinRight
* @property {string} joinJoin
*/
/**
* Used to tell whether to draw a horizontal line.
* This callback is called for each non-content line of the table.
* The default behavior is to always return true.
*
* @typedef {Function} drawHorizontalLine
* @param {number} index
* @param {number} size
* @returns {boolean}
*/
/**
* @typedef {Object} table~config
* @property {table~border} border
* @property {table~columns[]} columns Column specific configuration.
* @property {table~columns} columnDefault Default values for all columns. Column specific settings overwrite the default values.
* @property {table~drawHorizontalLine} drawHorizontalLine
*/
/**
* Generates a text table.
*
* @param {table~row[]} data
* @param {table~config} userConfig
* @returns {string}
*/
exports.default = function (data) {
let userConfig = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
let rows;
(0, _validateTableData2.default)(data);
rows = (0, _stringifyTableData2.default)(data);
const config = (0, _makeConfig2.default)(rows, userConfig);
rows = (0, _truncateTableData2.default)(data, config);
const rowHeightIndex = (0, _calculateRowHeightIndex2.default)(rows, config);
rows = (0, _mapDataUsingRowHeightIndex2.default)(rows, rowHeightIndex, config);
rows = (0, _alignTableData2.default)(rows, config);
rows = (0, _padTableData2.default)(rows, config);
const cellWidthIndex = (0, _calculateCellWidthIndex2.default)(rows[0]);
return (0, _drawTable2.default)(rows, config.border, cellWidthIndex, rowHeightIndex, config.drawHorizontalLine);
};

View File

@@ -0,0 +1,27 @@
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _lodash = require('lodash');
var _lodash2 = _interopRequireDefault(_lodash);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
* @todo Make it work with ASCII content.
* @param {table~row[]} rows
* @param {Object} config
* @returns {table~row[]}
*/
exports.default = (rows, config) => {
return _lodash2.default.map(rows, cells => {
return _lodash2.default.map(cells, (content, index) => {
return _lodash2.default.truncate(content, {
length: config.columns[index].truncate
});
});
});
};

View File

@@ -0,0 +1,753 @@
'use strict';
var equal = require('ajv/lib/compile/equal');
var validate = (function() {
var pattern0 = new RegExp('^[0-9]+$');
var refVal = [];
var refVal1 = (function() {
var pattern0 = new RegExp('^[0-9]+$');
return function validate(data, dataPath, parentData, parentDataProperty, rootData) {
'use strict';
var vErrors = null;
var errors = 0;
if (rootData === undefined) rootData = data;
if ((data && typeof data === "object" && !Array.isArray(data))) {
var errs__0 = errors;
var valid1 = true;
for (var key0 in data) {
var isAdditional0 = !(false || validate.schema.properties[key0]);
if (isAdditional0) {
valid1 = false;
var err = {
keyword: 'additionalProperties',
dataPath: (dataPath || '') + "",
schemaPath: '#/additionalProperties',
params: {
additionalProperty: '' + key0 + ''
},
message: 'should NOT have additional properties'
};
if (vErrors === null) vErrors = [err];
else vErrors.push(err);
errors++;
}
}
if (data.topBody !== undefined) {
var errs_1 = errors;
if (!refVal2(data.topBody, (dataPath || '') + '.topBody', data, 'topBody', rootData)) {
if (vErrors === null) vErrors = refVal2.errors;
else vErrors = vErrors.concat(refVal2.errors);
errors = vErrors.length;
}
var valid1 = errors === errs_1;
}
if (data.topJoin !== undefined) {
var errs_1 = errors;
if (!refVal[2](data.topJoin, (dataPath || '') + '.topJoin', data, 'topJoin', rootData)) {
if (vErrors === null) vErrors = refVal[2].errors;
else vErrors = vErrors.concat(refVal[2].errors);
errors = vErrors.length;
}
var valid1 = errors === errs_1;
}
if (data.topLeft !== undefined) {
var errs_1 = errors;
if (!refVal[2](data.topLeft, (dataPath || '') + '.topLeft', data, 'topLeft', rootData)) {
if (vErrors === null) vErrors = refVal[2].errors;
else vErrors = vErrors.concat(refVal[2].errors);
errors = vErrors.length;
}
var valid1 = errors === errs_1;
}
if (data.topRight !== undefined) {
var errs_1 = errors;
if (!refVal[2](data.topRight, (dataPath || '') + '.topRight', data, 'topRight', rootData)) {
if (vErrors === null) vErrors = refVal[2].errors;
else vErrors = vErrors.concat(refVal[2].errors);
errors = vErrors.length;
}
var valid1 = errors === errs_1;
}
if (data.bottomBody !== undefined) {
var errs_1 = errors;
if (!refVal[2](data.bottomBody, (dataPath || '') + '.bottomBody', data, 'bottomBody', rootData)) {
if (vErrors === null) vErrors = refVal[2].errors;
else vErrors = vErrors.concat(refVal[2].errors);
errors = vErrors.length;
}
var valid1 = errors === errs_1;
}
if (data.bottomJoin !== undefined) {
var errs_1 = errors;
if (!refVal[2](data.bottomJoin, (dataPath || '') + '.bottomJoin', data, 'bottomJoin', rootData)) {
if (vErrors === null) vErrors = refVal[2].errors;
else vErrors = vErrors.concat(refVal[2].errors);
errors = vErrors.length;
}
var valid1 = errors === errs_1;
}
if (data.bottomLeft !== undefined) {
var errs_1 = errors;
if (!refVal[2](data.bottomLeft, (dataPath || '') + '.bottomLeft', data, 'bottomLeft', rootData)) {
if (vErrors === null) vErrors = refVal[2].errors;
else vErrors = vErrors.concat(refVal[2].errors);
errors = vErrors.length;
}
var valid1 = errors === errs_1;
}
if (data.bottomRight !== undefined) {
var errs_1 = errors;
if (!refVal[2](data.bottomRight, (dataPath || '') + '.bottomRight', data, 'bottomRight', rootData)) {
if (vErrors === null) vErrors = refVal[2].errors;
else vErrors = vErrors.concat(refVal[2].errors);
errors = vErrors.length;
}
var valid1 = errors === errs_1;
}
if (data.bodyLeft !== undefined) {
var errs_1 = errors;
if (!refVal[2](data.bodyLeft, (dataPath || '') + '.bodyLeft', data, 'bodyLeft', rootData)) {
if (vErrors === null) vErrors = refVal[2].errors;
else vErrors = vErrors.concat(refVal[2].errors);
errors = vErrors.length;
}
var valid1 = errors === errs_1;
}
if (data.bodyRight !== undefined) {
var errs_1 = errors;
if (!refVal[2](data.bodyRight, (dataPath || '') + '.bodyRight', data, 'bodyRight', rootData)) {
if (vErrors === null) vErrors = refVal[2].errors;
else vErrors = vErrors.concat(refVal[2].errors);
errors = vErrors.length;
}
var valid1 = errors === errs_1;
}
if (data.bodyJoin !== undefined) {
var errs_1 = errors;
if (!refVal[2](data.bodyJoin, (dataPath || '') + '.bodyJoin', data, 'bodyJoin', rootData)) {
if (vErrors === null) vErrors = refVal[2].errors;
else vErrors = vErrors.concat(refVal[2].errors);
errors = vErrors.length;
}
var valid1 = errors === errs_1;
}
if (data.joinBody !== undefined) {
var errs_1 = errors;
if (!refVal[2](data.joinBody, (dataPath || '') + '.joinBody', data, 'joinBody', rootData)) {
if (vErrors === null) vErrors = refVal[2].errors;
else vErrors = vErrors.concat(refVal[2].errors);
errors = vErrors.length;
}
var valid1 = errors === errs_1;
}
if (data.joinLeft !== undefined) {
var errs_1 = errors;
if (!refVal[2](data.joinLeft, (dataPath || '') + '.joinLeft', data, 'joinLeft', rootData)) {
if (vErrors === null) vErrors = refVal[2].errors;
else vErrors = vErrors.concat(refVal[2].errors);
errors = vErrors.length;
}
var valid1 = errors === errs_1;
}
if (data.joinRight !== undefined) {
var errs_1 = errors;
if (!refVal[2](data.joinRight, (dataPath || '') + '.joinRight', data, 'joinRight', rootData)) {
if (vErrors === null) vErrors = refVal[2].errors;
else vErrors = vErrors.concat(refVal[2].errors);
errors = vErrors.length;
}
var valid1 = errors === errs_1;
}
if (data.joinJoin !== undefined) {
var errs_1 = errors;
if (!refVal[2](data.joinJoin, (dataPath || '') + '.joinJoin', data, 'joinJoin', rootData)) {
if (vErrors === null) vErrors = refVal[2].errors;
else vErrors = vErrors.concat(refVal[2].errors);
errors = vErrors.length;
}
var valid1 = errors === errs_1;
}
} else {
var err = {
keyword: 'type',
dataPath: (dataPath || '') + "",
schemaPath: '#/type',
params: {
type: 'object'
},
message: 'should be object'
};
if (vErrors === null) vErrors = [err];
else vErrors.push(err);
errors++;
}
validate.errors = vErrors;
return errors === 0;
};
})();
refVal1.schema = {
"type": "object",
"properties": {
"topBody": {
"$ref": "#/definitions/border"
},
"topJoin": {
"$ref": "#/definitions/border"
},
"topLeft": {
"$ref": "#/definitions/border"
},
"topRight": {
"$ref": "#/definitions/border"
},
"bottomBody": {
"$ref": "#/definitions/border"
},
"bottomJoin": {
"$ref": "#/definitions/border"
},
"bottomLeft": {
"$ref": "#/definitions/border"
},
"bottomRight": {
"$ref": "#/definitions/border"
},
"bodyLeft": {
"$ref": "#/definitions/border"
},
"bodyRight": {
"$ref": "#/definitions/border"
},
"bodyJoin": {
"$ref": "#/definitions/border"
},
"joinBody": {
"$ref": "#/definitions/border"
},
"joinLeft": {
"$ref": "#/definitions/border"
},
"joinRight": {
"$ref": "#/definitions/border"
},
"joinJoin": {
"$ref": "#/definitions/border"
}
},
"additionalProperties": false
};
refVal1.errors = null;
refVal[1] = refVal1;
var refVal2 = (function() {
var pattern0 = new RegExp('^[0-9]+$');
return function validate(data, dataPath, parentData, parentDataProperty, rootData) {
'use strict';
var vErrors = null;
var errors = 0;
if (typeof data !== "string") {
var err = {
keyword: 'type',
dataPath: (dataPath || '') + "",
schemaPath: '#/type',
params: {
type: 'string'
},
message: 'should be string'
};
if (vErrors === null) vErrors = [err];
else vErrors.push(err);
errors++;
}
validate.errors = vErrors;
return errors === 0;
};
})();
refVal2.schema = {
"type": "string"
};
refVal2.errors = null;
refVal[2] = refVal2;
var refVal3 = (function() {
var pattern0 = new RegExp('^[0-9]+$');
return function validate(data, dataPath, parentData, parentDataProperty, rootData) {
'use strict';
var vErrors = null;
var errors = 0;
if (rootData === undefined) rootData = data;
if ((data && typeof data === "object" && !Array.isArray(data))) {
var errs__0 = errors;
var valid1 = true;
for (var key0 in data) {
var isAdditional0 = !(false || pattern0.test(key0));
if (isAdditional0) {
valid1 = false;
var err = {
keyword: 'additionalProperties',
dataPath: (dataPath || '') + "",
schemaPath: '#/additionalProperties',
params: {
additionalProperty: '' + key0 + ''
},
message: 'should NOT have additional properties'
};
if (vErrors === null) vErrors = [err];
else vErrors.push(err);
errors++;
}
}
for (var key0 in data) {
if (pattern0.test(key0)) {
var errs_1 = errors;
if (!refVal4(data[key0], (dataPath || '') + '[\'' + key0 + '\']', data, key0, rootData)) {
if (vErrors === null) vErrors = refVal4.errors;
else vErrors = vErrors.concat(refVal4.errors);
errors = vErrors.length;
}
var valid1 = errors === errs_1;
}
}
} else {
var err = {
keyword: 'type',
dataPath: (dataPath || '') + "",
schemaPath: '#/type',
params: {
type: 'object'
},
message: 'should be object'
};
if (vErrors === null) vErrors = [err];
else vErrors.push(err);
errors++;
}
validate.errors = vErrors;
return errors === 0;
};
})();
refVal3.schema = {
"type": "object",
"patternProperties": {
"^[0-9]+$": {
"$ref": "#/definitions/column"
}
},
"additionalProperties": false
};
refVal3.errors = null;
refVal[3] = refVal3;
var refVal4 = (function() {
var pattern0 = new RegExp('^[0-9]+$');
return function validate(data, dataPath, parentData, parentDataProperty, rootData) {
'use strict';
var vErrors = null;
var errors = 0;
if ((data && typeof data === "object" && !Array.isArray(data))) {
var errs__0 = errors;
var valid1 = true;
for (var key0 in data) {
var isAdditional0 = !(false || validate.schema.properties[key0]);
if (isAdditional0) {
valid1 = false;
var err = {
keyword: 'additionalProperties',
dataPath: (dataPath || '') + "",
schemaPath: '#/additionalProperties',
params: {
additionalProperty: '' + key0 + ''
},
message: 'should NOT have additional properties'
};
if (vErrors === null) vErrors = [err];
else vErrors.push(err);
errors++;
}
}
var data1 = data.alignment;
if (data1 !== undefined) {
var errs_1 = errors;
if (typeof data1 !== "string") {
var err = {
keyword: 'type',
dataPath: (dataPath || '') + '.alignment',
schemaPath: '#/properties/alignment/type',
params: {
type: 'string'
},
message: 'should be string'
};
if (vErrors === null) vErrors = [err];
else vErrors.push(err);
errors++;
}
var schema1 = validate.schema.properties.alignment.enum;
var valid1;
valid1 = false;
for (var i1 = 0; i1 < schema1.length; i1++)
if (equal(data1, schema1[i1])) {
valid1 = true;
break;
}
if (!valid1) {
var err = {
keyword: 'enum',
dataPath: (dataPath || '') + '.alignment',
schemaPath: '#/properties/alignment/enum',
params: {
allowedValues: schema1
},
message: 'should be equal to one of the allowed values'
};
if (vErrors === null) vErrors = [err];
else vErrors.push(err);
errors++;
}
var valid1 = errors === errs_1;
}
if (data.width !== undefined) {
var errs_1 = errors;
if (typeof data.width !== "number") {
var err = {
keyword: 'type',
dataPath: (dataPath || '') + '.width',
schemaPath: '#/properties/width/type',
params: {
type: 'number'
},
message: 'should be number'
};
if (vErrors === null) vErrors = [err];
else vErrors.push(err);
errors++;
}
var valid1 = errors === errs_1;
}
if (data.wrapWord !== undefined) {
var errs_1 = errors;
if (typeof data.wrapWord !== "boolean") {
var err = {
keyword: 'type',
dataPath: (dataPath || '') + '.wrapWord',
schemaPath: '#/properties/wrapWord/type',
params: {
type: 'boolean'
},
message: 'should be boolean'
};
if (vErrors === null) vErrors = [err];
else vErrors.push(err);
errors++;
}
var valid1 = errors === errs_1;
}
if (data.truncate !== undefined) {
var errs_1 = errors;
if (typeof data.truncate !== "number") {
var err = {
keyword: 'type',
dataPath: (dataPath || '') + '.truncate',
schemaPath: '#/properties/truncate/type',
params: {
type: 'number'
},
message: 'should be number'
};
if (vErrors === null) vErrors = [err];
else vErrors.push(err);
errors++;
}
var valid1 = errors === errs_1;
}
if (data.paddingLeft !== undefined) {
var errs_1 = errors;
if (typeof data.paddingLeft !== "number") {
var err = {
keyword: 'type',
dataPath: (dataPath || '') + '.paddingLeft',
schemaPath: '#/properties/paddingLeft/type',
params: {
type: 'number'
},
message: 'should be number'
};
if (vErrors === null) vErrors = [err];
else vErrors.push(err);
errors++;
}
var valid1 = errors === errs_1;
}
if (data.paddingRight !== undefined) {
var errs_1 = errors;
if (typeof data.paddingRight !== "number") {
var err = {
keyword: 'type',
dataPath: (dataPath || '') + '.paddingRight',
schemaPath: '#/properties/paddingRight/type',
params: {
type: 'number'
},
message: 'should be number'
};
if (vErrors === null) vErrors = [err];
else vErrors.push(err);
errors++;
}
var valid1 = errors === errs_1;
}
} else {
var err = {
keyword: 'type',
dataPath: (dataPath || '') + "",
schemaPath: '#/type',
params: {
type: 'object'
},
message: 'should be object'
};
if (vErrors === null) vErrors = [err];
else vErrors.push(err);
errors++;
}
validate.errors = vErrors;
return errors === 0;
};
})();
refVal4.schema = {
"type": "object",
"properties": {
"alignment": {
"type": "string",
"enum": ["left", "right", "center"]
},
"width": {
"type": "number"
},
"wrapWord": {
"type": "boolean"
},
"truncate": {
"type": "number"
},
"paddingLeft": {
"type": "number"
},
"paddingRight": {
"type": "number"
}
},
"additionalProperties": false
};
refVal4.errors = null;
refVal[4] = refVal4;
return function validate(data, dataPath, parentData, parentDataProperty, rootData) {
'use strict'; /*# sourceURL=config.json */
var vErrors = null;
var errors = 0;
if (rootData === undefined) rootData = data;
if ((data && typeof data === "object" && !Array.isArray(data))) {
var errs__0 = errors;
var valid1 = true;
for (var key0 in data) {
var isAdditional0 = !(false || key0 == 'border' || key0 == 'columns' || key0 == 'columnDefault' || key0 == 'drawHorizontalLine');
if (isAdditional0) {
valid1 = false;
var err = {
keyword: 'additionalProperties',
dataPath: (dataPath || '') + "",
schemaPath: '#/additionalProperties',
params: {
additionalProperty: '' + key0 + ''
},
message: 'should NOT have additional properties'
};
if (vErrors === null) vErrors = [err];
else vErrors.push(err);
errors++;
}
}
if (data.border !== undefined) {
var errs_1 = errors;
if (!refVal1(data.border, (dataPath || '') + '.border', data, 'border', rootData)) {
if (vErrors === null) vErrors = refVal1.errors;
else vErrors = vErrors.concat(refVal1.errors);
errors = vErrors.length;
}
var valid1 = errors === errs_1;
}
if (data.columns !== undefined) {
var errs_1 = errors;
if (!refVal3(data.columns, (dataPath || '') + '.columns', data, 'columns', rootData)) {
if (vErrors === null) vErrors = refVal3.errors;
else vErrors = vErrors.concat(refVal3.errors);
errors = vErrors.length;
}
var valid1 = errors === errs_1;
}
if (data.columnDefault !== undefined) {
var errs_1 = errors;
if (!refVal[4](data.columnDefault, (dataPath || '') + '.columnDefault', data, 'columnDefault', rootData)) {
if (vErrors === null) vErrors = refVal[4].errors;
else vErrors = vErrors.concat(refVal[4].errors);
errors = vErrors.length;
}
var valid1 = errors === errs_1;
}
if (data.drawHorizontalLine !== undefined) {
var errs_1 = errors;
var errs__1 = errors;
var valid1;
valid1 = typeof data.drawHorizontalLine == "function";
if (!valid1) {
if (errs__1 == errors) {
var err = {
keyword: 'typeof',
dataPath: (dataPath || '') + '.drawHorizontalLine',
schemaPath: '#/properties/drawHorizontalLine/typeof',
params: {
keyword: 'typeof'
},
message: 'should pass "typeof" keyword validation'
};
if (vErrors === null) vErrors = [err];
else vErrors.push(err);
errors++;
} else {
for (var i1 = errs__1; i1 < errors; i1++) {
var ruleErr1 = vErrors[i1];
if (ruleErr1.dataPath === undefined) ruleErr1.dataPath = (dataPath || '') + '.drawHorizontalLine';
if (ruleErr1.schemaPath === undefined) {
ruleErr1.schemaPath = "#/properties/drawHorizontalLine/typeof";
}
}
}
}
var valid1 = errors === errs_1;
}
} else {
var err = {
keyword: 'type',
dataPath: (dataPath || '') + "",
schemaPath: '#/type',
params: {
type: 'object'
},
message: 'should be object'
};
if (vErrors === null) vErrors = [err];
else vErrors.push(err);
errors++;
}
validate.errors = vErrors;
return errors === 0;
};
})();
validate.schema = {
"$id": "config.json",
"$schema": "http://json-schema.org/draft-06/schema#",
"type": "object",
"properties": {
"border": {
"$ref": "#/definitions/borders"
},
"columns": {
"$ref": "#/definitions/columns"
},
"columnDefault": {
"$ref": "#/definitions/column"
},
"drawHorizontalLine": {
"typeof": "function"
}
},
"additionalProperties": false,
"definitions": {
"columns": {
"type": "object",
"patternProperties": {
"^[0-9]+$": {
"$ref": "#/definitions/column"
}
},
"additionalProperties": false
},
"column": {
"type": "object",
"properties": {
"alignment": {
"type": "string",
"enum": ["left", "right", "center"]
},
"width": {
"type": "number"
},
"wrapWord": {
"type": "boolean"
},
"truncate": {
"type": "number"
},
"paddingLeft": {
"type": "number"
},
"paddingRight": {
"type": "number"
}
},
"additionalProperties": false
},
"borders": {
"type": "object",
"properties": {
"topBody": {
"$ref": "#/definitions/border"
},
"topJoin": {
"$ref": "#/definitions/border"
},
"topLeft": {
"$ref": "#/definitions/border"
},
"topRight": {
"$ref": "#/definitions/border"
},
"bottomBody": {
"$ref": "#/definitions/border"
},
"bottomJoin": {
"$ref": "#/definitions/border"
},
"bottomLeft": {
"$ref": "#/definitions/border"
},
"bottomRight": {
"$ref": "#/definitions/border"
},
"bodyLeft": {
"$ref": "#/definitions/border"
},
"bodyRight": {
"$ref": "#/definitions/border"
},
"bodyJoin": {
"$ref": "#/definitions/border"
},
"joinBody": {
"$ref": "#/definitions/border"
},
"joinLeft": {
"$ref": "#/definitions/border"
},
"joinRight": {
"$ref": "#/definitions/border"
},
"joinJoin": {
"$ref": "#/definitions/border"
}
},
"additionalProperties": false
},
"border": {
"type": "string"
}
}
};
validate.errors = null;
module.exports = validate;

View File

@@ -0,0 +1,740 @@
'use strict';
var equal = require('ajv/lib/compile/equal');
var validate = (function() {
var pattern0 = new RegExp('^[0-9]+$');
var refVal = [];
var refVal1 = (function() {
var pattern0 = new RegExp('^[0-9]+$');
return function validate(data, dataPath, parentData, parentDataProperty, rootData) {
'use strict';
var vErrors = null;
var errors = 0;
if (rootData === undefined) rootData = data;
if ((data && typeof data === "object" && !Array.isArray(data))) {
var errs__0 = errors;
var valid1 = true;
for (var key0 in data) {
var isAdditional0 = !(false || validate.schema.properties[key0]);
if (isAdditional0) {
valid1 = false;
var err = {
keyword: 'additionalProperties',
dataPath: (dataPath || '') + "",
schemaPath: '#/additionalProperties',
params: {
additionalProperty: '' + key0 + ''
},
message: 'should NOT have additional properties'
};
if (vErrors === null) vErrors = [err];
else vErrors.push(err);
errors++;
}
}
if (data.topBody !== undefined) {
var errs_1 = errors;
if (!refVal2(data.topBody, (dataPath || '') + '.topBody', data, 'topBody', rootData)) {
if (vErrors === null) vErrors = refVal2.errors;
else vErrors = vErrors.concat(refVal2.errors);
errors = vErrors.length;
}
var valid1 = errors === errs_1;
}
if (data.topJoin !== undefined) {
var errs_1 = errors;
if (!refVal[2](data.topJoin, (dataPath || '') + '.topJoin', data, 'topJoin', rootData)) {
if (vErrors === null) vErrors = refVal[2].errors;
else vErrors = vErrors.concat(refVal[2].errors);
errors = vErrors.length;
}
var valid1 = errors === errs_1;
}
if (data.topLeft !== undefined) {
var errs_1 = errors;
if (!refVal[2](data.topLeft, (dataPath || '') + '.topLeft', data, 'topLeft', rootData)) {
if (vErrors === null) vErrors = refVal[2].errors;
else vErrors = vErrors.concat(refVal[2].errors);
errors = vErrors.length;
}
var valid1 = errors === errs_1;
}
if (data.topRight !== undefined) {
var errs_1 = errors;
if (!refVal[2](data.topRight, (dataPath || '') + '.topRight', data, 'topRight', rootData)) {
if (vErrors === null) vErrors = refVal[2].errors;
else vErrors = vErrors.concat(refVal[2].errors);
errors = vErrors.length;
}
var valid1 = errors === errs_1;
}
if (data.bottomBody !== undefined) {
var errs_1 = errors;
if (!refVal[2](data.bottomBody, (dataPath || '') + '.bottomBody', data, 'bottomBody', rootData)) {
if (vErrors === null) vErrors = refVal[2].errors;
else vErrors = vErrors.concat(refVal[2].errors);
errors = vErrors.length;
}
var valid1 = errors === errs_1;
}
if (data.bottomJoin !== undefined) {
var errs_1 = errors;
if (!refVal[2](data.bottomJoin, (dataPath || '') + '.bottomJoin', data, 'bottomJoin', rootData)) {
if (vErrors === null) vErrors = refVal[2].errors;
else vErrors = vErrors.concat(refVal[2].errors);
errors = vErrors.length;
}
var valid1 = errors === errs_1;
}
if (data.bottomLeft !== undefined) {
var errs_1 = errors;
if (!refVal[2](data.bottomLeft, (dataPath || '') + '.bottomLeft', data, 'bottomLeft', rootData)) {
if (vErrors === null) vErrors = refVal[2].errors;
else vErrors = vErrors.concat(refVal[2].errors);
errors = vErrors.length;
}
var valid1 = errors === errs_1;
}
if (data.bottomRight !== undefined) {
var errs_1 = errors;
if (!refVal[2](data.bottomRight, (dataPath || '') + '.bottomRight', data, 'bottomRight', rootData)) {
if (vErrors === null) vErrors = refVal[2].errors;
else vErrors = vErrors.concat(refVal[2].errors);
errors = vErrors.length;
}
var valid1 = errors === errs_1;
}
if (data.bodyLeft !== undefined) {
var errs_1 = errors;
if (!refVal[2](data.bodyLeft, (dataPath || '') + '.bodyLeft', data, 'bodyLeft', rootData)) {
if (vErrors === null) vErrors = refVal[2].errors;
else vErrors = vErrors.concat(refVal[2].errors);
errors = vErrors.length;
}
var valid1 = errors === errs_1;
}
if (data.bodyRight !== undefined) {
var errs_1 = errors;
if (!refVal[2](data.bodyRight, (dataPath || '') + '.bodyRight', data, 'bodyRight', rootData)) {
if (vErrors === null) vErrors = refVal[2].errors;
else vErrors = vErrors.concat(refVal[2].errors);
errors = vErrors.length;
}
var valid1 = errors === errs_1;
}
if (data.bodyJoin !== undefined) {
var errs_1 = errors;
if (!refVal[2](data.bodyJoin, (dataPath || '') + '.bodyJoin', data, 'bodyJoin', rootData)) {
if (vErrors === null) vErrors = refVal[2].errors;
else vErrors = vErrors.concat(refVal[2].errors);
errors = vErrors.length;
}
var valid1 = errors === errs_1;
}
if (data.joinBody !== undefined) {
var errs_1 = errors;
if (!refVal[2](data.joinBody, (dataPath || '') + '.joinBody', data, 'joinBody', rootData)) {
if (vErrors === null) vErrors = refVal[2].errors;
else vErrors = vErrors.concat(refVal[2].errors);
errors = vErrors.length;
}
var valid1 = errors === errs_1;
}
if (data.joinLeft !== undefined) {
var errs_1 = errors;
if (!refVal[2](data.joinLeft, (dataPath || '') + '.joinLeft', data, 'joinLeft', rootData)) {
if (vErrors === null) vErrors = refVal[2].errors;
else vErrors = vErrors.concat(refVal[2].errors);
errors = vErrors.length;
}
var valid1 = errors === errs_1;
}
if (data.joinRight !== undefined) {
var errs_1 = errors;
if (!refVal[2](data.joinRight, (dataPath || '') + '.joinRight', data, 'joinRight', rootData)) {
if (vErrors === null) vErrors = refVal[2].errors;
else vErrors = vErrors.concat(refVal[2].errors);
errors = vErrors.length;
}
var valid1 = errors === errs_1;
}
if (data.joinJoin !== undefined) {
var errs_1 = errors;
if (!refVal[2](data.joinJoin, (dataPath || '') + '.joinJoin', data, 'joinJoin', rootData)) {
if (vErrors === null) vErrors = refVal[2].errors;
else vErrors = vErrors.concat(refVal[2].errors);
errors = vErrors.length;
}
var valid1 = errors === errs_1;
}
} else {
var err = {
keyword: 'type',
dataPath: (dataPath || '') + "",
schemaPath: '#/type',
params: {
type: 'object'
},
message: 'should be object'
};
if (vErrors === null) vErrors = [err];
else vErrors.push(err);
errors++;
}
validate.errors = vErrors;
return errors === 0;
};
})();
refVal1.schema = {
"type": "object",
"properties": {
"topBody": {
"$ref": "#/definitions/border"
},
"topJoin": {
"$ref": "#/definitions/border"
},
"topLeft": {
"$ref": "#/definitions/border"
},
"topRight": {
"$ref": "#/definitions/border"
},
"bottomBody": {
"$ref": "#/definitions/border"
},
"bottomJoin": {
"$ref": "#/definitions/border"
},
"bottomLeft": {
"$ref": "#/definitions/border"
},
"bottomRight": {
"$ref": "#/definitions/border"
},
"bodyLeft": {
"$ref": "#/definitions/border"
},
"bodyRight": {
"$ref": "#/definitions/border"
},
"bodyJoin": {
"$ref": "#/definitions/border"
},
"joinBody": {
"$ref": "#/definitions/border"
},
"joinLeft": {
"$ref": "#/definitions/border"
},
"joinRight": {
"$ref": "#/definitions/border"
},
"joinJoin": {
"$ref": "#/definitions/border"
}
},
"additionalProperties": false
};
refVal1.errors = null;
refVal[1] = refVal1;
var refVal2 = (function() {
var pattern0 = new RegExp('^[0-9]+$');
return function validate(data, dataPath, parentData, parentDataProperty, rootData) {
'use strict';
var vErrors = null;
var errors = 0;
if (typeof data !== "string") {
var err = {
keyword: 'type',
dataPath: (dataPath || '') + "",
schemaPath: '#/type',
params: {
type: 'string'
},
message: 'should be string'
};
if (vErrors === null) vErrors = [err];
else vErrors.push(err);
errors++;
}
validate.errors = vErrors;
return errors === 0;
};
})();
refVal2.schema = {
"type": "string"
};
refVal2.errors = null;
refVal[2] = refVal2;
var refVal3 = (function() {
var pattern0 = new RegExp('^[0-9]+$');
return function validate(data, dataPath, parentData, parentDataProperty, rootData) {
'use strict';
var vErrors = null;
var errors = 0;
if (rootData === undefined) rootData = data;
if ((data && typeof data === "object" && !Array.isArray(data))) {
var errs__0 = errors;
var valid1 = true;
for (var key0 in data) {
var isAdditional0 = !(false || pattern0.test(key0));
if (isAdditional0) {
valid1 = false;
var err = {
keyword: 'additionalProperties',
dataPath: (dataPath || '') + "",
schemaPath: '#/additionalProperties',
params: {
additionalProperty: '' + key0 + ''
},
message: 'should NOT have additional properties'
};
if (vErrors === null) vErrors = [err];
else vErrors.push(err);
errors++;
}
}
for (var key0 in data) {
if (pattern0.test(key0)) {
var errs_1 = errors;
if (!refVal4(data[key0], (dataPath || '') + '[\'' + key0 + '\']', data, key0, rootData)) {
if (vErrors === null) vErrors = refVal4.errors;
else vErrors = vErrors.concat(refVal4.errors);
errors = vErrors.length;
}
var valid1 = errors === errs_1;
}
}
} else {
var err = {
keyword: 'type',
dataPath: (dataPath || '') + "",
schemaPath: '#/type',
params: {
type: 'object'
},
message: 'should be object'
};
if (vErrors === null) vErrors = [err];
else vErrors.push(err);
errors++;
}
validate.errors = vErrors;
return errors === 0;
};
})();
refVal3.schema = {
"type": "object",
"patternProperties": {
"^[0-9]+$": {
"$ref": "#/definitions/column"
}
},
"additionalProperties": false
};
refVal3.errors = null;
refVal[3] = refVal3;
var refVal4 = (function() {
var pattern0 = new RegExp('^[0-9]+$');
return function validate(data, dataPath, parentData, parentDataProperty, rootData) {
'use strict';
var vErrors = null;
var errors = 0;
if ((data && typeof data === "object" && !Array.isArray(data))) {
var errs__0 = errors;
var valid1 = true;
for (var key0 in data) {
var isAdditional0 = !(false || validate.schema.properties[key0]);
if (isAdditional0) {
valid1 = false;
var err = {
keyword: 'additionalProperties',
dataPath: (dataPath || '') + "",
schemaPath: '#/additionalProperties',
params: {
additionalProperty: '' + key0 + ''
},
message: 'should NOT have additional properties'
};
if (vErrors === null) vErrors = [err];
else vErrors.push(err);
errors++;
}
}
var data1 = data.alignment;
if (data1 !== undefined) {
var errs_1 = errors;
if (typeof data1 !== "string") {
var err = {
keyword: 'type',
dataPath: (dataPath || '') + '.alignment',
schemaPath: '#/properties/alignment/type',
params: {
type: 'string'
},
message: 'should be string'
};
if (vErrors === null) vErrors = [err];
else vErrors.push(err);
errors++;
}
var schema1 = validate.schema.properties.alignment.enum;
var valid1;
valid1 = false;
for (var i1 = 0; i1 < schema1.length; i1++)
if (equal(data1, schema1[i1])) {
valid1 = true;
break;
}
if (!valid1) {
var err = {
keyword: 'enum',
dataPath: (dataPath || '') + '.alignment',
schemaPath: '#/properties/alignment/enum',
params: {
allowedValues: schema1
},
message: 'should be equal to one of the allowed values'
};
if (vErrors === null) vErrors = [err];
else vErrors.push(err);
errors++;
}
var valid1 = errors === errs_1;
}
if (data.width !== undefined) {
var errs_1 = errors;
if (typeof data.width !== "number") {
var err = {
keyword: 'type',
dataPath: (dataPath || '') + '.width',
schemaPath: '#/properties/width/type',
params: {
type: 'number'
},
message: 'should be number'
};
if (vErrors === null) vErrors = [err];
else vErrors.push(err);
errors++;
}
var valid1 = errors === errs_1;
}
if (data.wrapWord !== undefined) {
var errs_1 = errors;
if (typeof data.wrapWord !== "boolean") {
var err = {
keyword: 'type',
dataPath: (dataPath || '') + '.wrapWord',
schemaPath: '#/properties/wrapWord/type',
params: {
type: 'boolean'
},
message: 'should be boolean'
};
if (vErrors === null) vErrors = [err];
else vErrors.push(err);
errors++;
}
var valid1 = errors === errs_1;
}
if (data.truncate !== undefined) {
var errs_1 = errors;
if (typeof data.truncate !== "number") {
var err = {
keyword: 'type',
dataPath: (dataPath || '') + '.truncate',
schemaPath: '#/properties/truncate/type',
params: {
type: 'number'
},
message: 'should be number'
};
if (vErrors === null) vErrors = [err];
else vErrors.push(err);
errors++;
}
var valid1 = errors === errs_1;
}
if (data.paddingLeft !== undefined) {
var errs_1 = errors;
if (typeof data.paddingLeft !== "number") {
var err = {
keyword: 'type',
dataPath: (dataPath || '') + '.paddingLeft',
schemaPath: '#/properties/paddingLeft/type',
params: {
type: 'number'
},
message: 'should be number'
};
if (vErrors === null) vErrors = [err];
else vErrors.push(err);
errors++;
}
var valid1 = errors === errs_1;
}
if (data.paddingRight !== undefined) {
var errs_1 = errors;
if (typeof data.paddingRight !== "number") {
var err = {
keyword: 'type',
dataPath: (dataPath || '') + '.paddingRight',
schemaPath: '#/properties/paddingRight/type',
params: {
type: 'number'
},
message: 'should be number'
};
if (vErrors === null) vErrors = [err];
else vErrors.push(err);
errors++;
}
var valid1 = errors === errs_1;
}
} else {
var err = {
keyword: 'type',
dataPath: (dataPath || '') + "",
schemaPath: '#/type',
params: {
type: 'object'
},
message: 'should be object'
};
if (vErrors === null) vErrors = [err];
else vErrors.push(err);
errors++;
}
validate.errors = vErrors;
return errors === 0;
};
})();
refVal4.schema = {
"type": "object",
"properties": {
"alignment": {
"type": "string",
"enum": ["left", "right", "center"]
},
"width": {
"type": "number"
},
"wrapWord": {
"type": "boolean"
},
"truncate": {
"type": "number"
},
"paddingLeft": {
"type": "number"
},
"paddingRight": {
"type": "number"
}
},
"additionalProperties": false
};
refVal4.errors = null;
refVal[4] = refVal4;
return function validate(data, dataPath, parentData, parentDataProperty, rootData) {
'use strict'; /*# sourceURL=streamConfig.json */
var vErrors = null;
var errors = 0;
if (rootData === undefined) rootData = data;
if ((data && typeof data === "object" && !Array.isArray(data))) {
var errs__0 = errors;
var valid1 = true;
for (var key0 in data) {
var isAdditional0 = !(false || key0 == 'border' || key0 == 'columns' || key0 == 'columnDefault' || key0 == 'columnCount');
if (isAdditional0) {
valid1 = false;
var err = {
keyword: 'additionalProperties',
dataPath: (dataPath || '') + "",
schemaPath: '#/additionalProperties',
params: {
additionalProperty: '' + key0 + ''
},
message: 'should NOT have additional properties'
};
if (vErrors === null) vErrors = [err];
else vErrors.push(err);
errors++;
}
}
if (data.border !== undefined) {
var errs_1 = errors;
if (!refVal1(data.border, (dataPath || '') + '.border', data, 'border', rootData)) {
if (vErrors === null) vErrors = refVal1.errors;
else vErrors = vErrors.concat(refVal1.errors);
errors = vErrors.length;
}
var valid1 = errors === errs_1;
}
if (data.columns !== undefined) {
var errs_1 = errors;
if (!refVal3(data.columns, (dataPath || '') + '.columns', data, 'columns', rootData)) {
if (vErrors === null) vErrors = refVal3.errors;
else vErrors = vErrors.concat(refVal3.errors);
errors = vErrors.length;
}
var valid1 = errors === errs_1;
}
if (data.columnDefault !== undefined) {
var errs_1 = errors;
if (!refVal[4](data.columnDefault, (dataPath || '') + '.columnDefault', data, 'columnDefault', rootData)) {
if (vErrors === null) vErrors = refVal[4].errors;
else vErrors = vErrors.concat(refVal[4].errors);
errors = vErrors.length;
}
var valid1 = errors === errs_1;
}
if (data.columnCount !== undefined) {
var errs_1 = errors;
if (typeof data.columnCount !== "number") {
var err = {
keyword: 'type',
dataPath: (dataPath || '') + '.columnCount',
schemaPath: '#/properties/columnCount/type',
params: {
type: 'number'
},
message: 'should be number'
};
if (vErrors === null) vErrors = [err];
else vErrors.push(err);
errors++;
}
var valid1 = errors === errs_1;
}
} else {
var err = {
keyword: 'type',
dataPath: (dataPath || '') + "",
schemaPath: '#/type',
params: {
type: 'object'
},
message: 'should be object'
};
if (vErrors === null) vErrors = [err];
else vErrors.push(err);
errors++;
}
validate.errors = vErrors;
return errors === 0;
};
})();
validate.schema = {
"$id": "streamConfig.json",
"$schema": "http://json-schema.org/draft-06/schema#",
"type": "object",
"properties": {
"border": {
"$ref": "#/definitions/borders"
},
"columns": {
"$ref": "#/definitions/columns"
},
"columnDefault": {
"$ref": "#/definitions/column"
},
"columnCount": {
"type": "number"
}
},
"additionalProperties": false,
"definitions": {
"columns": {
"type": "object",
"patternProperties": {
"^[0-9]+$": {
"$ref": "#/definitions/column"
}
},
"additionalProperties": false
},
"column": {
"type": "object",
"properties": {
"alignment": {
"type": "string",
"enum": ["left", "right", "center"]
},
"width": {
"type": "number"
},
"wrapWord": {
"type": "boolean"
},
"truncate": {
"type": "number"
},
"paddingLeft": {
"type": "number"
},
"paddingRight": {
"type": "number"
}
},
"additionalProperties": false
},
"borders": {
"type": "object",
"properties": {
"topBody": {
"$ref": "#/definitions/border"
},
"topJoin": {
"$ref": "#/definitions/border"
},
"topLeft": {
"$ref": "#/definitions/border"
},
"topRight": {
"$ref": "#/definitions/border"
},
"bottomBody": {
"$ref": "#/definitions/border"
},
"bottomJoin": {
"$ref": "#/definitions/border"
},
"bottomLeft": {
"$ref": "#/definitions/border"
},
"bottomRight": {
"$ref": "#/definitions/border"
},
"bodyLeft": {
"$ref": "#/definitions/border"
},
"bodyRight": {
"$ref": "#/definitions/border"
},
"bodyJoin": {
"$ref": "#/definitions/border"
},
"joinBody": {
"$ref": "#/definitions/border"
},
"joinLeft": {
"$ref": "#/definitions/border"
},
"joinRight": {
"$ref": "#/definitions/border"
},
"joinJoin": {
"$ref": "#/definitions/border"
}
},
"additionalProperties": false
},
"border": {
"type": "string"
}
}
};
validate.errors = null;
module.exports = validate;

View File

@@ -0,0 +1,51 @@
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
/**
* @typedef {string} cell
*/
/**
* @typedef {cell[]} validateData~column
*/
/**
* @param {column[]} rows
* @returns {undefined}
*/
exports.default = rows => {
if (!Array.isArray(rows)) {
throw new TypeError('Table data must be an array.');
}
if (rows.length === 0) {
throw new Error('Table must define at least one row.');
}
if (rows[0].length === 0) {
throw new Error('Table must define at least one column.');
}
const columnNumber = rows[0].length;
for (const cells of rows) {
if (!Array.isArray(cells)) {
throw new TypeError('Table row data must be an array.');
}
if (cells.length !== columnNumber) {
throw new Error('Table must have a consistent number of cells.');
}
// @todo Make an exception for newline characters.
// @see https://github.com/gajus/table/issues/9
for (const cell of cells) {
if (/[\u0001-\u001A]/.test(cell)) {
throw new Error('Table data must not contain control characters.');
}
}
}
};

View File

@@ -0,0 +1,46 @@
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _lodash = require('lodash');
var _lodash2 = _interopRequireDefault(_lodash);
var _sliceAnsi = require('slice-ansi');
var _sliceAnsi2 = _interopRequireDefault(_sliceAnsi);
var _stringWidth = require('string-width');
var _stringWidth2 = _interopRequireDefault(_stringWidth);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
* Creates an array of strings split into groups the length of size.
* This function works with strings that contain ASCII characters.
*
* wrapText is different from would-be "chunk" implementation
* in that whitespace characters that occur on a chunk size limit are trimmed.
*
* @param {string} subject
* @param {number} size
* @returns {Array}
*/
exports.default = (subject, size) => {
let subjectSlice;
subjectSlice = subject;
const chunks = [];
do {
chunks.push((0, _sliceAnsi2.default)(subjectSlice, 0, size));
subjectSlice = _lodash2.default.trim((0, _sliceAnsi2.default)(subjectSlice, size));
} while ((0, _stringWidth2.default)(subjectSlice));
return chunks;
};

View File

@@ -0,0 +1,56 @@
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _lodash = require('lodash');
var _lodash2 = _interopRequireDefault(_lodash);
var _sliceAnsi = require('slice-ansi');
var _sliceAnsi2 = _interopRequireDefault(_sliceAnsi);
var _stringWidth = require('string-width');
var _stringWidth2 = _interopRequireDefault(_stringWidth);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
* @param {string} input
* @param {number} size
* @returns {Array}
*/
exports.default = (input, size) => {
let subject;
subject = input;
const chunks = [];
// https://regex101.com/r/gY5kZ1/1
const re = new RegExp('(^.{1,' + size + '}(\\s+|$))|(^.{1,' + (size - 1) + '}(\\\\|/|_|\\.|,|;|-))');
do {
let chunk;
chunk = subject.match(re);
if (chunk) {
chunk = chunk[0];
subject = (0, _sliceAnsi2.default)(subject, (0, _stringWidth2.default)(chunk));
chunk = _lodash2.default.trim(chunk);
} else {
chunk = (0, _sliceAnsi2.default)(subject, 0, size);
subject = (0, _sliceAnsi2.default)(subject, size);
}
chunks.push(chunk);
} while ((0, _stringWidth2.default)(subject));
return chunks;
};

View File

@@ -0,0 +1,228 @@
'use strict';
const escapeStringRegexp = require('escape-string-regexp');
const ansiStyles = require('ansi-styles');
const supportsColor = require('supports-color');
const template = require('./templates.js');
const isSimpleWindowsTerm = process.platform === 'win32' && !(process.env.TERM || '').toLowerCase().startsWith('xterm');
// `supportsColor.level` → `ansiStyles.color[name]` mapping
const levelMapping = ['ansi', 'ansi', 'ansi256', 'ansi16m'];
// `color-convert` models to exclude from the Chalk API due to conflicts and such
const skipModels = new Set(['gray']);
const styles = Object.create(null);
function applyOptions(obj, options) {
options = options || {};
// Detect level if not set manually
const scLevel = supportsColor ? supportsColor.level : 0;
obj.level = options.level === undefined ? scLevel : options.level;
obj.enabled = 'enabled' in options ? options.enabled : obj.level > 0;
}
function Chalk(options) {
// We check for this.template here since calling `chalk.constructor()`
// by itself will have a `this` of a previously constructed chalk object
if (!this || !(this instanceof Chalk) || this.template) {
const chalk = {};
applyOptions(chalk, options);
chalk.template = function () {
const args = [].slice.call(arguments);
return chalkTag.apply(null, [chalk.template].concat(args));
};
Object.setPrototypeOf(chalk, Chalk.prototype);
Object.setPrototypeOf(chalk.template, chalk);
chalk.template.constructor = Chalk;
return chalk.template;
}
applyOptions(this, options);
}
// Use bright blue on Windows as the normal blue color is illegible
if (isSimpleWindowsTerm) {
ansiStyles.blue.open = '\u001B[94m';
}
for (const key of Object.keys(ansiStyles)) {
ansiStyles[key].closeRe = new RegExp(escapeStringRegexp(ansiStyles[key].close), 'g');
styles[key] = {
get() {
const codes = ansiStyles[key];
return build.call(this, this._styles ? this._styles.concat(codes) : [codes], this._empty, key);
}
};
}
styles.visible = {
get() {
return build.call(this, this._styles || [], true, 'visible');
}
};
ansiStyles.color.closeRe = new RegExp(escapeStringRegexp(ansiStyles.color.close), 'g');
for (const model of Object.keys(ansiStyles.color.ansi)) {
if (skipModels.has(model)) {
continue;
}
styles[model] = {
get() {
const level = this.level;
return function () {
const open = ansiStyles.color[levelMapping[level]][model].apply(null, arguments);
const codes = {
open,
close: ansiStyles.color.close,
closeRe: ansiStyles.color.closeRe
};
return build.call(this, this._styles ? this._styles.concat(codes) : [codes], this._empty, model);
};
}
};
}
ansiStyles.bgColor.closeRe = new RegExp(escapeStringRegexp(ansiStyles.bgColor.close), 'g');
for (const model of Object.keys(ansiStyles.bgColor.ansi)) {
if (skipModels.has(model)) {
continue;
}
const bgModel = 'bg' + model[0].toUpperCase() + model.slice(1);
styles[bgModel] = {
get() {
const level = this.level;
return function () {
const open = ansiStyles.bgColor[levelMapping[level]][model].apply(null, arguments);
const codes = {
open,
close: ansiStyles.bgColor.close,
closeRe: ansiStyles.bgColor.closeRe
};
return build.call(this, this._styles ? this._styles.concat(codes) : [codes], this._empty, model);
};
}
};
}
const proto = Object.defineProperties(() => {}, styles);
function build(_styles, _empty, key) {
const builder = function () {
return applyStyle.apply(builder, arguments);
};
builder._styles = _styles;
builder._empty = _empty;
const self = this;
Object.defineProperty(builder, 'level', {
enumerable: true,
get() {
return self.level;
},
set(level) {
self.level = level;
}
});
Object.defineProperty(builder, 'enabled', {
enumerable: true,
get() {
return self.enabled;
},
set(enabled) {
self.enabled = enabled;
}
});
// See below for fix regarding invisible grey/dim combination on Windows
builder.hasGrey = this.hasGrey || key === 'gray' || key === 'grey';
// `__proto__` is used because we must return a function, but there is
// no way to create a function with a different prototype
builder.__proto__ = proto; // eslint-disable-line no-proto
return builder;
}
function applyStyle() {
// Support varags, but simply cast to string in case there's only one arg
const args = arguments;
const argsLen = args.length;
let str = String(arguments[0]);
if (argsLen === 0) {
return '';
}
if (argsLen > 1) {
// Don't slice `arguments`, it prevents V8 optimizations
for (let a = 1; a < argsLen; a++) {
str += ' ' + args[a];
}
}
if (!this.enabled || this.level <= 0 || !str) {
return this._empty ? '' : str;
}
// Turns out that on Windows dimmed gray text becomes invisible in cmd.exe,
// see https://github.com/chalk/chalk/issues/58
// If we're on Windows and we're dealing with a gray color, temporarily make 'dim' a noop.
const originalDim = ansiStyles.dim.open;
if (isSimpleWindowsTerm && this.hasGrey) {
ansiStyles.dim.open = '';
}
for (const code of this._styles.slice().reverse()) {
// Replace any instances already present with a re-opening code
// otherwise only the part of the string until said closing code
// will be colored, and the rest will simply be 'plain'.
str = code.open + str.replace(code.closeRe, code.open) + code.close;
// Close the styling before a linebreak and reopen
// after next line to fix a bleed issue on macOS
// https://github.com/chalk/chalk/pull/92
str = str.replace(/\r?\n/g, `${code.close}$&${code.open}`);
}
// Reset the original `dim` if we changed it to work around the Windows dimmed gray issue
ansiStyles.dim.open = originalDim;
return str;
}
function chalkTag(chalk, strings) {
if (!Array.isArray(strings)) {
// If chalk() was called by itself or with a string,
// return the string itself as a string.
return [].slice.call(arguments, 1).join(' ');
}
const args = [].slice.call(arguments, 2);
const parts = [strings.raw[0]];
for (let i = 1; i < strings.length; i++) {
parts.push(String(args[i - 1]).replace(/[{}\\]/g, '\\$&'));
parts.push(String(strings.raw[i]));
}
return template(chalk, parts.join(''));
}
Object.defineProperties(Chalk.prototype, styles);
module.exports = Chalk(); // eslint-disable-line new-cap
module.exports.supportsColor = supportsColor;
module.exports.default = module.exports; // For TypeScript

View File

@@ -0,0 +1,9 @@
MIT License
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View File

@@ -0,0 +1,101 @@
{
"_args": [
[
"chalk@2.3.0",
"C:\\Users\\deranjer\\go\\src\\github.com\\deranjer\\goTorrent\\torrent-project"
]
],
"_from": "chalk@2.3.0",
"_id": "chalk@2.3.0",
"_inBundle": false,
"_integrity": "sha512-Az5zJR2CBujap2rqXGaJKaPHyJ0IrUimvYNX+ncCy8PJP4ltOGTrHUIo097ZaL2zMeKYpiCdqDvS6zdrTFok3Q==",
"_location": "/react-scripts/table/chalk",
"_phantomChildren": {},
"_requested": {
"type": "version",
"registry": true,
"raw": "chalk@2.3.0",
"name": "chalk",
"escapedName": "chalk",
"rawSpec": "2.3.0",
"saveSpec": null,
"fetchSpec": "2.3.0"
},
"_requiredBy": [
"/react-scripts/table"
],
"_resolved": "https://registry.npmjs.org/chalk/-/chalk-2.3.0.tgz",
"_spec": "2.3.0",
"_where": "C:\\Users\\deranjer\\go\\src\\github.com\\deranjer\\goTorrent\\torrent-project",
"bugs": {
"url": "https://github.com/chalk/chalk/issues"
},
"dependencies": {
"ansi-styles": "^3.1.0",
"escape-string-regexp": "^1.0.5",
"supports-color": "^4.0.0"
},
"description": "Terminal string styling done right",
"devDependencies": {
"ava": "*",
"coveralls": "^3.0.0",
"execa": "^0.8.0",
"import-fresh": "^2.0.0",
"matcha": "^0.7.0",
"nyc": "^11.0.2",
"resolve-from": "^4.0.0",
"typescript": "^2.5.3",
"xo": "*"
},
"engines": {
"node": ">=4"
},
"files": [
"index.js",
"templates.js",
"types/index.d.ts"
],
"homepage": "https://github.com/chalk/chalk#readme",
"keywords": [
"color",
"colour",
"colors",
"terminal",
"console",
"cli",
"string",
"str",
"ansi",
"style",
"styles",
"tty",
"formatting",
"rgb",
"256",
"shell",
"xterm",
"log",
"logging",
"command-line",
"text"
],
"license": "MIT",
"name": "chalk",
"repository": {
"type": "git",
"url": "git+https://github.com/chalk/chalk.git"
},
"scripts": {
"bench": "matcha benchmark.js",
"coveralls": "nyc report --reporter=text-lcov | coveralls",
"test": "xo && tsc --project types && nyc ava"
},
"types": "types/index.d.ts",
"version": "2.3.0",
"xo": {
"envs": [
"node",
"mocha"
]
}
}

View File

@@ -0,0 +1,309 @@
<h1 align="center">
<br>
<br>
<img width="320" src="https://cdn.rawgit.com/chalk/chalk/19935d6484811c5e468817f846b7b3d417d7bf4a/logo.svg" alt="chalk">
<br>
<br>
<br>
</h1>
> Terminal string styling done right
[![Build Status](https://travis-ci.org/chalk/chalk.svg?branch=master)](https://travis-ci.org/chalk/chalk) [![Coverage Status](https://coveralls.io/repos/github/chalk/chalk/badge.svg?branch=master)](https://coveralls.io/github/chalk/chalk?branch=master) [![](https://img.shields.io/badge/unicorn-approved-ff69b4.svg)](https://www.youtube.com/watch?v=9auOCbH5Ns4) [![XO code style](https://img.shields.io/badge/code_style-XO-5ed9c7.svg)](https://github.com/sindresorhus/xo) [![Mentioned in Awesome Node.js](https://awesome.re/mentioned-badge.svg)](https://github.com/sindresorhus/awesome-nodejs)
### [See what's new in Chalk 2](https://github.com/chalk/chalk/releases/tag/v2.0.0)
![](https://github.com/chalk/ansi-styles/raw/master/screenshot.png)
## Highlights
- Expressive API
- Highly performant
- Ability to nest styles
- [256/Truecolor color support](#256-and-truecolor-color-support)
- Auto-detects color support
- Doesn't extend `String.prototype`
- Clean and focused
- Actively maintained
- [Used by ~17,000 packages](https://www.npmjs.com/browse/depended/chalk) as of June 20th, 2017
## Install
```console
$ npm install chalk
```
## Usage
```js
const chalk = require('chalk');
console.log(chalk.blue('Hello world!'));
```
Chalk comes with an easy to use composable API where you just chain and nest the styles you want.
```js
const chalk = require('chalk');
const log = console.log;
// Combine styled and normal strings
log(chalk.blue('Hello') + 'World' + chalk.red('!'));
// Compose multiple styles using the chainable API
log(chalk.blue.bgRed.bold('Hello world!'));
// Pass in multiple arguments
log(chalk.blue('Hello', 'World!', 'Foo', 'bar', 'biz', 'baz'));
// Nest styles
log(chalk.red('Hello', chalk.underline.bgBlue('world') + '!'));
// Nest styles of the same type even (color, underline, background)
log(chalk.green(
'I am a green line ' +
chalk.blue.underline.bold('with a blue substring') +
' that becomes green again!'
));
// ES2015 template literal
log(`
CPU: ${chalk.red('90%')}
RAM: ${chalk.green('40%')}
DISK: ${chalk.yellow('70%')}
`);
// ES2015 tagged template literal
log(chalk`
CPU: {red ${cpu.totalPercent}%}
RAM: {green ${ram.used / ram.total * 100}%}
DISK: {rgb(255,131,0) ${disk.used / disk.total * 100}%}
`);
// Use RGB colors in terminal emulators that support it.
log(chalk.keyword('orange')('Yay for orange colored text!'));
log(chalk.rgb(123, 45, 67).underline('Underlined reddish color'));
log(chalk.hex('#DEADED').bold('Bold gray!'));
```
Easily define your own themes:
```js
const chalk = require('chalk');
const error = chalk.bold.red;
const warning = chalk.keyword('orange');
console.log(error('Error!'));
console.log(warning('Warning!'));
```
Take advantage of console.log [string substitution](https://nodejs.org/docs/latest/api/console.html#console_console_log_data_args):
```js
const name = 'Sindre';
console.log(chalk.green('Hello %s'), name);
//=> 'Hello Sindre'
```
## API
### chalk.`<style>[.<style>...](string, [string...])`
Example: `chalk.red.bold.underline('Hello', 'world');`
Chain [styles](#styles) and call the last one as a method with a string argument. Order doesn't matter, and later styles take precedent in case of a conflict. This simply means that `chalk.red.yellow.green` is equivalent to `chalk.green`.
Multiple arguments will be separated by space.
### chalk.enabled
Color support is automatically detected, as is the level (see `chalk.level`). However, if you'd like to simply enable/disable Chalk, you can do so via the `.enabled` property.
Chalk is enabled by default unless expicitly disabled via the constructor or `chalk.level` is `0`.
If you need to change this in a reusable module, create a new instance:
```js
const ctx = new chalk.constructor({enabled: false});
```
### chalk.level
Color support is automatically detected, but you can override it by setting the `level` property. You should however only do this in your own code as it applies globally to all Chalk consumers.
If you need to change this in a reusable module, create a new instance:
```js
const ctx = new chalk.constructor({level: 0});
```
Levels are as follows:
0. All colors disabled
1. Basic color support (16 colors)
2. 256 color support
3. Truecolor support (16 million colors)
### chalk.supportsColor
Detect whether the terminal [supports color](https://github.com/chalk/supports-color). Used internally and handled for you, but exposed for convenience.
Can be overridden by the user with the flags `--color` and `--no-color`. For situations where using `--color` is not possible, add the environment variable `FORCE_COLOR=1` to forcefully enable color or `FORCE_COLOR=0` to forcefully disable. The use of `FORCE_COLOR` overrides all other color support checks.
Explicit 256/Truecolor mode can be enabled using the `--color=256` and `--color=16m` flags, respectively.
## Styles
### Modifiers
- `reset`
- `bold`
- `dim`
- `italic` *(Not widely supported)*
- `underline`
- `inverse`
- `hidden`
- `strikethrough` *(Not widely supported)*
- `visible` (Text is emitted only if enabled)
### Colors
- `black`
- `red`
- `green`
- `yellow`
- `blue` *(On Windows the bright version is used since normal blue is illegible)*
- `magenta`
- `cyan`
- `white`
- `gray` ("bright black")
- `redBright`
- `greenBright`
- `yellowBright`
- `blueBright`
- `magentaBright`
- `cyanBright`
- `whiteBright`
### Background colors
- `bgBlack`
- `bgRed`
- `bgGreen`
- `bgYellow`
- `bgBlue`
- `bgMagenta`
- `bgCyan`
- `bgWhite`
- `bgBlackBright`
- `bgRedBright`
- `bgGreenBright`
- `bgYellowBright`
- `bgBlueBright`
- `bgMagentaBright`
- `bgCyanBright`
- `bgWhiteBright`
## Tagged template literal
Chalk can be used as a [tagged template literal](http://exploringjs.com/es6/ch_template-literals.html#_tagged-template-literals).
```js
const chalk = require('chalk');
const miles = 18;
const calculateFeet = miles => miles * 5280;
console.log(chalk`
There are {bold 5280 feet} in a mile.
In {bold ${miles} miles}, there are {green.bold ${calculateFeet(miles)} feet}.
`);
```
Blocks are delimited by an opening curly brace (`{`), a style, some content, and a closing curly brace (`}`).
Template styles are chained exactly like normal Chalk styles. The following two statements are equivalent:
```js
console.log(chalk.bold.rgb(10, 100, 200)('Hello!'));
console.log(chalk`{bold.rgb(10,100,200) Hello!}`);
```
Note that function styles (`rgb()`, `hsl()`, `keyword()`, etc.) may not contain spaces between parameters.
All interpolated values (`` chalk`${foo}` ``) are converted to strings via the `.toString()` method. All curly braces (`{` and `}`) in interpolated value strings are escaped.
## 256 and Truecolor color support
Chalk supports 256 colors and [Truecolor](https://gist.github.com/XVilka/8346728) (16 million colors) on supported terminal apps.
Colors are downsampled from 16 million RGB values to an ANSI color format that is supported by the terminal emulator (or by specifying `{level: n}` as a Chalk option). For example, Chalk configured to run at level 1 (basic color support) will downsample an RGB value of #FF0000 (red) to 31 (ANSI escape for red).
Examples:
- `chalk.hex('#DEADED').underline('Hello, world!')`
- `chalk.keyword('orange')('Some orange text')`
- `chalk.rgb(15, 100, 204).inverse('Hello!')`
Background versions of these models are prefixed with `bg` and the first level of the module capitalized (e.g. `keyword` for foreground colors and `bgKeyword` for background colors).
- `chalk.bgHex('#DEADED').underline('Hello, world!')`
- `chalk.bgKeyword('orange')('Some orange text')`
- `chalk.bgRgb(15, 100, 204).inverse('Hello!')`
The following color models can be used:
- [`rgb`](https://en.wikipedia.org/wiki/RGB_color_model) - Example: `chalk.rgb(255, 136, 0).bold('Orange!')`
- [`hex`](https://en.wikipedia.org/wiki/Web_colors#Hex_triplet) - Example: `chalk.hex('#FF8800').bold('Orange!')`
- [`keyword`](https://www.w3.org/wiki/CSS/Properties/color/keywords) (CSS keywords) - Example: `chalk.keyword('orange').bold('Orange!')`
- [`hsl`](https://en.wikipedia.org/wiki/HSL_and_HSV) - Example: `chalk.hsl(32, 100, 50).bold('Orange!')`
- [`hsv`](https://en.wikipedia.org/wiki/HSL_and_HSV) - Example: `chalk.hsl(32, 1, 1).bold('Orange!')`
- [`hwb`](https://en.wikipedia.org/wiki/HWB_color_model) - Example: `chalk.hsl(32, 0, 50).bold('Orange!')`
- `ansi16`
- `ansi256`
## Windows
If you're on Windows, do yourself a favor and use [`cmder`](http://cmder.net/) instead of `cmd.exe`.
## Origin story
[colors.js](https://github.com/Marak/colors.js) used to be the most popular string styling module, but it has serious deficiencies like extending `String.prototype` which causes all kinds of [problems](https://github.com/yeoman/yo/issues/68) and the package is unmaintained. Although there are other packages, they either do too much or not enough. Chalk is a clean and focused alternative.
## Related
- [chalk-cli](https://github.com/chalk/chalk-cli) - CLI for this module
- [ansi-styles](https://github.com/chalk/ansi-styles) - ANSI escape codes for styling strings in the terminal
- [supports-color](https://github.com/chalk/supports-color) - Detect whether a terminal supports color
- [strip-ansi](https://github.com/chalk/strip-ansi) - Strip ANSI escape codes
- [strip-ansi-stream](https://github.com/chalk/strip-ansi-stream) - Strip ANSI escape codes from a stream
- [has-ansi](https://github.com/chalk/has-ansi) - Check if a string has ANSI escape codes
- [ansi-regex](https://github.com/chalk/ansi-regex) - Regular expression for matching ANSI escape codes
- [wrap-ansi](https://github.com/chalk/wrap-ansi) - Wordwrap a string with ANSI escape codes
- [slice-ansi](https://github.com/chalk/slice-ansi) - Slice a string with ANSI escape codes
- [color-convert](https://github.com/qix-/color-convert) - Converts colors between different models
- [chalk-animation](https://github.com/bokub/chalk-animation) - Animate strings in the terminal
- [gradient-string](https://github.com/bokub/gradient-string) - Apply color gradients to strings
- [chalk-pipe](https://github.com/LitoMore/chalk-pipe) - Create chalk style schemes with simpler style strings
## Maintainers
- [Sindre Sorhus](https://github.com/sindresorhus)
- [Josh Junon](https://github.com/qix-)
## License
MIT

View File

@@ -0,0 +1,128 @@
'use strict';
const TEMPLATE_REGEX = /(?:\\(u[a-f\d]{4}|x[a-f\d]{2}|.))|(?:\{(~)?(\w+(?:\([^)]*\))?(?:\.\w+(?:\([^)]*\))?)*)(?:[ \t]|(?=\r?\n)))|(\})|((?:.|[\r\n\f])+?)/gi;
const STYLE_REGEX = /(?:^|\.)(\w+)(?:\(([^)]*)\))?/g;
const STRING_REGEX = /^(['"])((?:\\.|(?!\1)[^\\])*)\1$/;
const ESCAPE_REGEX = /\\(u[a-f\d]{4}|x[a-f\d]{2}|.)|([^\\])/gi;
const ESCAPES = new Map([
['n', '\n'],
['r', '\r'],
['t', '\t'],
['b', '\b'],
['f', '\f'],
['v', '\v'],
['0', '\0'],
['\\', '\\'],
['e', '\u001B'],
['a', '\u0007']
]);
function unescape(c) {
if ((c[0] === 'u' && c.length === 5) || (c[0] === 'x' && c.length === 3)) {
return String.fromCharCode(parseInt(c.slice(1), 16));
}
return ESCAPES.get(c) || c;
}
function parseArguments(name, args) {
const results = [];
const chunks = args.trim().split(/\s*,\s*/g);
let matches;
for (const chunk of chunks) {
if (!isNaN(chunk)) {
results.push(Number(chunk));
} else if ((matches = chunk.match(STRING_REGEX))) {
results.push(matches[2].replace(ESCAPE_REGEX, (m, escape, chr) => escape ? unescape(escape) : chr));
} else {
throw new Error(`Invalid Chalk template style argument: ${chunk} (in style '${name}')`);
}
}
return results;
}
function parseStyle(style) {
STYLE_REGEX.lastIndex = 0;
const results = [];
let matches;
while ((matches = STYLE_REGEX.exec(style)) !== null) {
const name = matches[1];
if (matches[2]) {
const args = parseArguments(name, matches[2]);
results.push([name].concat(args));
} else {
results.push([name]);
}
}
return results;
}
function buildStyle(chalk, styles) {
const enabled = {};
for (const layer of styles) {
for (const style of layer.styles) {
enabled[style[0]] = layer.inverse ? null : style.slice(1);
}
}
let current = chalk;
for (const styleName of Object.keys(enabled)) {
if (Array.isArray(enabled[styleName])) {
if (!(styleName in current)) {
throw new Error(`Unknown Chalk style: ${styleName}`);
}
if (enabled[styleName].length > 0) {
current = current[styleName].apply(current, enabled[styleName]);
} else {
current = current[styleName];
}
}
}
return current;
}
module.exports = (chalk, tmp) => {
const styles = [];
const chunks = [];
let chunk = [];
// eslint-disable-next-line max-params
tmp.replace(TEMPLATE_REGEX, (m, escapeChar, inverse, style, close, chr) => {
if (escapeChar) {
chunk.push(unescape(escapeChar));
} else if (style) {
const str = chunk.join('');
chunk = [];
chunks.push(styles.length === 0 ? str : buildStyle(chalk, styles)(str));
styles.push({inverse, styles: parseStyle(style)});
} else if (close) {
if (styles.length === 0) {
throw new Error('Found extraneous } in Chalk template literal');
}
chunks.push(buildStyle(chalk, styles)(chunk.join('')));
chunk = [];
styles.pop();
} else {
chunk.push(chr);
}
});
chunks.push(chunk.join(''));
if (styles.length > 0) {
const errMsg = `Chalk template literal is missing ${styles.length} closing bracket${styles.length === 1 ? '' : 's'} (\`}\`)`;
throw new Error(errMsg);
}
return chunks.join('');
};

View File

@@ -0,0 +1,97 @@
// Type definitions for Chalk
// Definitions by: Thomas Sauer <https://github.com/t-sauer>
export const enum Level {
None = 0,
Basic = 1,
Ansi256 = 2,
TrueColor = 3
}
export interface ChalkOptions {
enabled?: boolean;
level?: Level;
}
export interface ChalkConstructor {
new (options?: ChalkOptions): Chalk;
(options?: ChalkOptions): Chalk;
}
export interface ColorSupport {
level: Level;
hasBasic: boolean;
has256: boolean;
has16m: boolean;
}
export interface Chalk {
(...text: string[]): string;
(text: TemplateStringsArray, ...placeholders: string[]): string;
constructor: ChalkConstructor;
enabled: boolean;
level: Level;
rgb(r: number, g: number, b: number): this;
hsl(h: number, s: number, l: number): this;
hsv(h: number, s: number, v: number): this;
hwb(h: number, w: number, b: number): this;
bgHex(color: string): this;
bgKeyword(color: string): this;
bgRgb(r: number, g: number, b: number): this;
bgHsl(h: number, s: number, l: number): this;
bgHsv(h: number, s: number, v: number): this;
bgHwb(h: number, w: number, b: number): this;
hex(color: string): this;
keyword(color: string): this;
readonly reset: this;
readonly bold: this;
readonly dim: this;
readonly italic: this;
readonly underline: this;
readonly inverse: this;
readonly hidden: this;
readonly strikethrough: this;
readonly visible: this;
readonly black: this;
readonly red: this;
readonly green: this;
readonly yellow: this;
readonly blue: this;
readonly magenta: this;
readonly cyan: this;
readonly white: this;
readonly gray: this;
readonly grey: this;
readonly blackBright: this;
readonly redBright: this;
readonly greenBright: this;
readonly yellowBright: this;
readonly blueBright: this;
readonly magentaBright: this;
readonly cyanBright: this;
readonly whiteBright: this;
readonly bgBlack: this;
readonly bgRed: this;
readonly bgGreen: this;
readonly bgYellow: this;
readonly bgBlue: this;
readonly bgMagenta: this;
readonly bgCyan: this;
readonly bgWhite: this;
readonly bgBlackBright: this;
readonly bgRedBright: this;
readonly bgGreenBright: this;
readonly bgYellowBright: this;
readonly bgBlueBright: this;
readonly bgMagentaBright: this;
readonly bgCyanBright: this;
readonly bgWhiteBright: this;
}
declare const chalk: Chalk & { supportsColor: ColorSupport };
export default chalk

View File

@@ -0,0 +1,104 @@
{
"_args": [
[
"table@4.0.2",
"C:\\Users\\deranjer\\go\\src\\github.com\\deranjer\\goTorrent\\torrent-project"
]
],
"_from": "table@4.0.2",
"_id": "table@4.0.2",
"_inBundle": false,
"_integrity": "sha512-UUkEAPdSGxtRpiV9ozJ5cMTtYiqz7Ni1OGqLXRCynrvzdtR1p+cfOWe2RJLwvUG8hNanaSRjecIqwOjqeatDsA==",
"_location": "/react-scripts/table",
"_phantomChildren": {
"ansi-styles": "3.2.0",
"escape-string-regexp": "1.0.5",
"supports-color": "4.5.0"
},
"_requested": {
"type": "version",
"registry": true,
"raw": "table@4.0.2",
"name": "table",
"escapedName": "table",
"rawSpec": "4.0.2",
"saveSpec": null,
"fetchSpec": "4.0.2"
},
"_requiredBy": [
"/react-scripts/eslint"
],
"_resolved": "https://registry.npmjs.org/table/-/table-4.0.2.tgz",
"_spec": "4.0.2",
"_where": "C:\\Users\\deranjer\\go\\src\\github.com\\deranjer\\goTorrent\\torrent-project",
"author": {
"name": "Gajus Kuizinas",
"email": "gajus@gajus.com",
"url": "http://gajus.com"
},
"bugs": {
"url": "https://github.com/gajus/table/issues"
},
"dependencies": {
"ajv": "^5.2.3",
"ajv-keywords": "^2.1.0",
"chalk": "^2.1.0",
"lodash": "^4.17.4",
"slice-ansi": "1.0.0",
"string-width": "^2.1.1"
},
"description": "Formats data into a string table.",
"devDependencies": {
"ajv-cli": "^2.1.0",
"babel": "^6.23.0",
"babel-cli": "^6.26.0",
"babel-core": "^6.26.0",
"babel-plugin-istanbul": "^4.1.5",
"babel-preset-es2015-node4": "^2.1.1",
"babel-register": "^6.26.0",
"chai": "^4.1.2",
"eslint": "^4.7.2",
"eslint-config-canonical": "^9.3.1",
"gitdown": "^2.5.1",
"husky": "^0.14.3",
"mocha": "^3.5.3",
"nyc": "^11.2.1",
"sinon": "^4.0.0"
},
"homepage": "https://github.com/gajus/table#readme",
"keywords": [
"ascii",
"text",
"table",
"align",
"ansi"
],
"license": "BSD-3-Clause",
"main": "./dist/index.js",
"name": "table",
"nyc": {
"include": [
"src/*.js"
],
"instrument": false,
"lines": 70,
"require": [
"babel-register"
],
"sourceMap": false
},
"repository": {
"type": "git",
"url": "git+https://github.com/gajus/table.git"
},
"scripts": {
"build": "rm -fr ./dist && NODE_ENV=production babel --copy-files ./src --out-dir ./dist && npm run make-validators",
"lint": "npm run build && eslint ./src ./tests",
"make-readme": "gitdown ./.README/README.md --output-file ./README.md",
"make-validators": "ajv compile --all-errors --inline-refs=false -s src/schemas/config -c ajv-keywords/keywords/typeof -o dist/validateConfig.js && ajv compile --all-errors --inline-refs=false -s src/schemas/streamConfig -c ajv-keywords/keywords/typeof -o dist/validateStreamConfig.js",
"precommit": "npm run lint && npm run test",
"prepublish": "NODE_ENV=production npm run build",
"test": "npm run build && nyc --check-coverage mocha"
},
"version": "4.0.2"
}