Socket
Socket
Sign inDemoInstall

table

Package Overview
Dependencies
Maintainers
1
Versions
86
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

table - npm Package Compare versions

Comparing version 3.6.2 to 3.7.0

dist/wrapWord.js

2

.README/usage/streaming.md

@@ -35,3 +35,3 @@ ### Streaming

Streaming supports all of the configuration properties and functionality of a static table, e.g.
Streaming supports all of the configuration properties and functionality of a static table (such as auto text wrapping, alignment and padding), e.g.

@@ -38,0 +38,0 @@ ```js

@@ -39,1 +39,41 @@ ### Text Wrapping

```
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. ║
╚══════════════════════╝
```

@@ -17,5 +17,10 @@ 'use strict';

var _wrapWord = require('./wrapWord');
var _wrapWord2 = _interopRequireDefault(_wrapWord);
/**
* @param {string} value
* @param {number} columnWidth
* @param {boolean} useWrapWord
* @returns {number}

@@ -25,2 +30,4 @@ */

exports['default'] = function (value, columnWidth) {
var useWrapWord = arguments.length <= 2 || arguments[2] === undefined ? false : arguments[2];
if (!_lodash2['default'].isString(value)) {

@@ -39,2 +46,6 @@ throw new Error('Value must be a string.');

if (useWrapWord) {
return (0, _wrapWord2['default'])(value, columnWidth).length;
}
return _lodash2['default'].ceil((0, _stringWidth2['default'])(value) / columnWidth);

@@ -41,0 +52,0 @@ };

@@ -13,6 +13,2 @@ 'use strict';

var _stringWidth = require('string-width');
var _stringWidth2 = _interopRequireDefault(_stringWidth);
var _calculateCellHeight = require('./calculateCellHeight');

@@ -44,3 +40,3 @@

_lodash2['default'].forEach(cells, function (value, index1) {
cellHeightIndex[index1] = (0, _calculateCellHeight2['default'])(value, config.columns[index1].width);
cellHeightIndex[index1] = (0, _calculateCellHeight2['default'])(value, config.columns[index1].width, config.columns[index1].wrapWord);
});

@@ -47,0 +43,0 @@

@@ -65,2 +65,3 @@ 'use strict';

width: maximumColumnWidthIndex[index],
wrapWord: false,
truncate: Infinity,

@@ -67,0 +68,0 @@ paddingLeft: 1,

@@ -57,2 +57,3 @@ 'use strict';

// width: columnDefault.width,
wrapWord: false,
truncate: Infinity,

@@ -59,0 +60,0 @@ paddingLeft: 1,

@@ -17,2 +17,6 @@ 'use strict';

var _wrapWord = require('./wrapWord');
var _wrapWord2 = _interopRequireDefault(_wrapWord);
/**

@@ -40,3 +44,3 @@ * @param {Array} unmappedRows

// console.log(`rowHeight`, rowHeight);
// console.log('rowHeight', rowHeight);

@@ -50,5 +54,13 @@ // rowHeight

chunkedValue = (0, _wrapString2['default'])(value, config.columns[index1].width);
if (config.columns[index1].wrapWord) {
chunkedValue = (0, _wrapWord2['default'])(value, config.columns[index1].width);
} else {
chunkedValue = (0, _wrapString2['default'])(value, config.columns[index1].width);
}
// console.log('chunkedValue', chunkedValue.length, 'rowHeight', rowHeight.length);
_lodash2['default'].forEach(chunkedValue, function (part, index2) {
// console.log(rowHeight[index2]);
rowHeight[index2][index1] = part;

@@ -55,0 +67,0 @@ });

@@ -42,2 +42,5 @@ {

},
"wrapWord": {
"type": "boolean"
},
"truncate": {

@@ -44,0 +47,0 @@ "type": "number"

@@ -42,2 +42,5 @@ {

},
"wrapWord": {
"type": "boolean"
},
"truncate": {

@@ -44,0 +47,0 @@ "type": "number"

@@ -30,2 +30,3 @@ 'use strict';

* @param {number} size
* @returns {Array}
*/

@@ -32,0 +33,0 @@

{
"name": "table",
"version": "3.6.2",
"version": "3.7.0",
"description": "Formats data into a string table.",

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

@@ -489,3 +489,3 @@ <h1 id="table">Table</h1>

Streaming supports all of the configuration properties and functionality of a static table, e.g.
Streaming supports all of the configuration properties and functionality of a static table (such as auto text wrapping, alignment and padding), e.g.

@@ -614,1 +614,41 @@ ```js

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. ║
╚══════════════════════╝
```
import _ from 'lodash';
import stringWidth from 'string-width';
import wrapWord from './wrapWord';

@@ -7,7 +8,8 @@ /**

* @param {number} columnWidth
* @param {boolean} useWrapWord
* @returns {number}
*/
export default (value, columnWidth) => {
export default (value, columnWidth, useWrapWord = false) => {
if (!_.isString(value)) {
throw new Error(`Value must be a string.`);
throw new Error('Value must be a string.');
}

@@ -17,10 +19,14 @@

if (!Number.isInteger(columnWidth)) {
throw new Error(`Column width must be an integer.`);
throw new Error('Column width must be an integer.');
}
if (columnWidth < 1) {
throw new Error(`Column width must be greater than 0.`);
throw new Error('Column width must be greater than 0.');
}
if (useWrapWord) {
return wrapWord(value, columnWidth).length;
}
return _.ceil(stringWidth(value) / columnWidth);
};
import _ from 'lodash';
import stringWidth from 'string-width';
import calculateCellHeight from './calculateCellHeight';

@@ -26,3 +25,3 @@

_.forEach(cells, (value, index1) => {
cellHeightIndex[index1] = calculateCellHeight(value, config.columns[index1].width);
cellHeightIndex[index1] = calculateCellHeight(value, config.columns[index1].width, config.columns[index1].wrapWord);
});

@@ -29,0 +28,0 @@

@@ -16,3 +16,3 @@ import _ from 'lodash';

makeBorder = (border = {}) => {
return _.assign({}, getBorderCharacters(`honeywell`), border);
return _.assign({}, getBorderCharacters('honeywell'), border);
};

@@ -40,4 +40,5 @@

columns[index] = _.assign({
alignment: `left`,
alignment: 'left',
width: maximumColumnWidthIndex[index],
wrapWord: false,
truncate: Infinity,

@@ -44,0 +45,0 @@ paddingLeft: 1,

@@ -15,3 +15,3 @@ import _ from 'lodash';

makeBorder = (border = {}) => {
return _.assign({}, getBorderCharacters(`honeywell`), border);
return _.assign({}, getBorderCharacters('honeywell'), border);
};

@@ -35,4 +35,5 @@

columns[index] = _.assign({
alignment: `left`,
alignment: 'left',
// width: columnDefault.width,
wrapWord: false,
truncate: Infinity,

@@ -79,7 +80,7 @@ paddingLeft: 1,

if (!config.columnDefault || !config.columnDefault.width) {
throw new Error(`Must provide config.columnDefault.width when creating a stream.`);
throw new Error('Must provide config.columnDefault.width when creating a stream.');
}
if (!config.columnCount) {
throw new Error(`Must provide config.columnCount.`);
throw new Error('Must provide config.columnCount.');
}

@@ -86,0 +87,0 @@

import _ from 'lodash';
import wrapString from './wrapString';
import wrapWord from './wrapWord';

@@ -25,3 +26,3 @@ /**

// console.log(`rowHeight`, rowHeight);
// console.log('rowHeight', rowHeight);

@@ -35,5 +36,13 @@ // rowHeight

chunkedValue = wrapString(value, config.columns[index1].width);
if (config.columns[index1].wrapWord) {
chunkedValue = wrapWord(value, config.columns[index1].width);
} else {
chunkedValue = wrapString(value, config.columns[index1].width);
}
// console.log('chunkedValue', chunkedValue.length, 'rowHeight', rowHeight.length);
_.forEach(chunkedValue, (part, index2) => {
// console.log(rowHeight[index2]);
rowHeight[index2][index1] = part;

@@ -40,0 +49,0 @@ });

@@ -42,2 +42,5 @@ {

},
"wrapWord": {
"type": "boolean"
},
"truncate": {

@@ -44,0 +47,0 @@ "type": "number"

@@ -42,2 +42,5 @@ {

},
"wrapWord": {
"type": "boolean"
},
"truncate": {

@@ -44,0 +47,0 @@ "type": "number"

@@ -14,2 +14,3 @@ import _ from 'lodash';

* @param {number} size
* @returns {Array}
*/

@@ -16,0 +17,0 @@ export default (subject, size) => {

@@ -11,3 +11,3 @@ import {

describe(`README.md usage/`, () => {
describe('README.md usage/', () => {
let expectTable;

@@ -21,3 +21,3 @@

it(`text_wrapping`, () => {
it(`text_wrapping (no wrap word)`, () => {
let config,

@@ -56,2 +56,40 @@ data,

});
it(`text_wrapping (wrap word)`, () => {
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);
expectTable(output, `
╔══════════════════════╗
║ Lorem ipsum dolor ║
║ sit amet, ║
║ consectetur ║
║ adipiscing elit. ║
║ Phasellus pulvinar ║
║ nibh sed mauris ║
║ convallis dapibus. ║
║ Nunc venenatis ║
║ tempus nulla sit ║
║ amet viverra. ║
╚══════════════════════╝
`);
});
});

@@ -9,33 +9,32 @@ import {

describe(`wrapString`, () => {
context(`subject is a plain text string`, () => {
context(`subject is lesser than the chunk size`, () => {
it(`returns subject in a single chunk`, () => {
expect(wrapString(`aaa`, 3)).to.deep.equal([`aaa`]);
describe('wrapString', () => {
context('subject is a plain text string', () => {
context('subject is lesser than the chunk size', () => {
it('returns subject in a single chunk', () => {
expect(wrapString('aaa', 3)).to.deep.equal(['aaa']);
});
});
context(`subject is larger than the chunk size`, () => {
it(`returns subject sliced into multiple chunks`, () => {
expect(wrapString(`aaabbbc`, 3)).to.deep.equal([`aaa`, `bbb`, `c`]);
context('subject is larger than the chunk size', () => {
it('returns subject sliced into multiple chunks', () => {
expect(wrapString('aaabbbc', 3)).to.deep.equal(['aaa', 'bbb', 'c']);
});
});
context(`a chunk starts with a space`, () => {
it(`adjusts chunks to offset the space`, () => {
expect(wrapString(`aaa bbb ccc`, 3)).to.deep.equal([`aaa`, `bbb`, `ccc`]);
context('a chunk starts with a space', () => {
it('adjusts chunks to offset the space', () => {
expect(wrapString('aaa bbb ccc', 3)).to.deep.equal(['aaa', 'bbb', 'ccc']);
});
});
});
// The reason these tests are being skipped is because `ansi-slice`
// The reason these tests are being skipped is because 'ansi-slice'
// pacakge suffixes string with all possible escape codes.
// Need to find a better way to test it.
xcontext(`subject string contains ANSI escape codes`, () => {
describe(`subject is lesser than the chunk size`, () => {
it(`returns subject in a single chunk`, () => {
expect(wrapString(chalk.red(`aaa`), 3)).to.deep.equal([chalk.red(`aaa`)]);
xcontext('subject string contains ANSI escape codes', () => {
describe('subject is lesser than the chunk size', () => {
it('returns subject in a single chunk', () => {
expect(wrapString(chalk.red('aaa'), 3)).to.deep.equal([chalk.red('aaa')]);
});
});
describe(`subject is larger than the chunk size`, () => {
it(`returns subject sliced into multiple chunks`, () => {
expect(wrapString(chalk.red(`aaabbbc`), 3)).to.deep.equal([chalk.red(`aaa`), chalk.red(`bbb`), chalk.red(`c`)]);
describe('subject is larger than the chunk size', () => {
it('returns subject sliced into multiple chunks', () => {
expect(wrapString(chalk.red('aaabbbc'), 3)).to.deep.equal([chalk.red('aaa'), chalk.red('bbb'), chalk.red('c')]);
});

@@ -42,0 +41,0 @@ });

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc