Socket
Socket
Sign inDemoInstall

column-layout

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

column-layout - npm Package Compare versions

Comparing version 2.1.1 to 2.1.2

es5/no-species.js

8

es5/cell.js
'use strict';
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

@@ -12,3 +12,3 @@ var t = require('typical');

var Cell = (function () {
var Cell = function () {
function Cell(value, column) {

@@ -39,4 +39,4 @@ _classCallCheck(this, Cell);

return Cell;
})();
}();
module.exports = Cell;
'use strict';
var Table = require('./table');

@@ -3,0 +4,0 @@ var Columns = require('./columns');

'use strict';
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _get = function get(_x, _x2, _x3) { var _again = true; _function: while (_again) { var object = _x, property = _x2, receiver = _x3; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x = parent; _x2 = property; _x3 = receiver; _again = true; desc = parent = undefined; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } };
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var t = require('typical');

@@ -17,10 +13,8 @@ var Padding = require('./padding');

var Columns = (function (_Array) {
_inherits(Columns, _Array);
var Columns = function () {
function Columns(columns) {
_classCallCheck(this, Columns);
_get(Object.getPrototypeOf(Columns.prototype), 'constructor', this).call(this);
this.load(columns);
this.list = [];
arrayify(columns).forEach(this.add.bind(this));
}

@@ -31,3 +25,3 @@

value: function totalWidth() {
return this.length ? this.map(function (col) {
return this.list.length ? this.list.map(function (col) {
return col.generatedWidth;

@@ -50,3 +44,3 @@ }).reduce(function (a, b) {

value: function get(columnName) {
return this.find(function (column) {
return this.list.find(function (column) {
return column.name === columnName;

@@ -58,3 +52,3 @@ });

value: function getResizable() {
return this.filter(function (column) {
return this.list.filter(function (column) {
return column.isResizable();

@@ -66,3 +60,3 @@ });

value: function getFixed() {
return this.filter(function (column) {
return this.list.filter(function (column) {
return column.isFixed();

@@ -72,11 +66,6 @@ });

}, {
key: 'load',
value: function load(columns) {
arrayify(columns).forEach(this.add.bind(this));
}
}, {
key: 'add',
value: function add(column) {
var col = column instanceof Column ? column : new Column(column);
this.push(col);
this.list.push(col);
return col;

@@ -91,3 +80,3 @@ }

this.forEach(function (column) {
this.list.forEach(function (column) {
column.generateWidth();

@@ -97,3 +86,3 @@ column.generateMinWidth();

this.forEach(function (column) {
this.list.forEach(function (column) {
if (t.isDefined(column.maxWidth) && column.generatedWidth > column.maxWidth) {

@@ -127,6 +116,6 @@ column.generatedWidth = column.maxWidth;

grownColumns = _this.filter(function (column) {
grownColumns = _this.list.filter(function (column) {
return column.generatedWidth > column.contentWidth;
});
shrunkenColumns = _this.filter(function (column) {
shrunkenColumns = _this.list.filter(function (column) {
return column.generatedWidth < column.contentWidth;

@@ -157,7 +146,7 @@ });

return Columns;
})(Array);
}();
var _padding = new WeakMap();
var Column = (function () {
var Column = function () {
function Column(column) {

@@ -172,3 +161,3 @@ _classCallCheck(this, Column);

if (t.isDefined(column.nowrap)) this.nowrap = column.nowrap;
if (t.isDefined(column['break'])) this['break'] = column['break'];
if (t.isDefined(column.break)) this.break = column.break;
if (t.isDefined(column.contentWrappable)) this.contentWrappable = column.contentWrappable;

@@ -217,4 +206,4 @@ if (t.isDefined(column.contentWidth)) this.contentWidth = column.contentWidth;

return Column;
})();
}();
module.exports = Columns;
module.exports = require('./no-species')(Columns);
'use strict';
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var Padding = (function () {
var Padding = function () {
function Padding(padding) {

@@ -23,4 +23,4 @@ _classCallCheck(this, Padding);

return Padding;
})();
}();
module.exports = Padding;
'use strict';
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _get = function get(_x, _x2, _x3) { var _again = true; _function: while (_again) { var object = _x, property = _x2, receiver = _x3; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x = parent; _x2 = property; _x3 = receiver; _again = true; desc = parent = undefined; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } };
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var Columns = require('./columns');

@@ -18,9 +14,7 @@ var ansi = require('./ansi');

var Rows = (function (_Array) {
_inherits(Rows, _Array);
var Rows = function () {
function Rows(rows, columns) {
_classCallCheck(this, Rows);
_get(Object.getPrototypeOf(Rows.prototype), 'constructor', this).call(this);
this.list = [];
this.load(rows, columns);

@@ -35,3 +29,3 @@ }

arrayify(rows).forEach(function (row) {
return _this.push(new Map(objectToIterable(row, columns)));
return _this.list.push(new Map(objectToIterable(row, columns)));
});

@@ -94,3 +88,3 @@ }

return Rows;
})(Array);
}();

@@ -105,3 +99,3 @@ function getLongestWord(line) {

function objectToIterable(row, columns) {
return columns.map(function (column) {
return columns.list.map(function (column) {
return [column, new Cell(row[column.name], column)];

@@ -111,2 +105,2 @@ });

module.exports = Rows;
module.exports = require('./no-species')(Rows);
'use strict';
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

@@ -15,3 +15,3 @@ var wrap = require('wordwrapjs');

var Table = (function () {
var Table = function () {
function Table(data, options) {

@@ -52,7 +52,7 @@ _classCallCheck(this, Table);

this.columns.viewWidth = options.viewWidth;
this.columns.forEach(function (column) {
this.columns.list.forEach(function (column) {
if (options.padding) column.padding = options.padding;
if (options.nowrap) column.nowrap = options.nowrap;
if (options['break']) {
column['break'] = options['break'];
if (options.break) {
column.break = options.break;
column.contentWrappable = true;

@@ -73,4 +73,4 @@ }

if (optionColumn.nowrap) column.nowrap = optionColumn.nowrap;
if (optionColumn['break']) {
column['break'] = optionColumn['break'];
if (optionColumn.break) {
column.break = optionColumn.break;
column.contentWrappable = true;

@@ -88,3 +88,3 @@ }

this.columns.autoSize();
return this.rows.map(function (row) {
return this.rows.list.map(function (row) {
var line = [];

@@ -98,3 +98,3 @@ row.forEach(function (cell, column) {

ignore: ansi.regexp,
'break': column['break']
break: column.break
}));

@@ -114,3 +114,3 @@ }

var _loop = function (i) {
var _loop = function _loop(i) {
var line = [];

@@ -137,3 +137,3 @@ wrapped.forEach(function (cell) {

return line.reduce(function (prev, cell, index) {
var column = _this2.columns[index];
var column = _this2.columns.list[index];
return prev + padCell(cell, column.padding, column.generatedWidth);

@@ -151,3 +151,3 @@ }, '');

return Table;
})();
}();

@@ -154,0 +154,0 @@ function getLongestArray(arrays) {

@@ -8,6 +8,6 @@ 'use strict'

class Columns extends Array {
class Columns {
constructor (columns) {
super()
this.load(columns)
this.list = []
arrayify(columns).forEach(this.add.bind(this))
}

@@ -20,4 +20,4 @@

totalWidth () {
return this.length
? this.map(col => col.generatedWidth).reduce((a, b) => a + b)
return this.list.length
? this.list.map(col => col.generatedWidth).reduce((a, b) => a + b)
: 0

@@ -33,20 +33,16 @@ }

get (columnName) {
return this.find(column => column.name === columnName)
return this.list.find(column => column.name === columnName)
}
getResizable () {
return this.filter(column => column.isResizable())
return this.list.filter(column => column.isResizable())
}
getFixed () {
return this.filter(column => column.isFixed())
return this.list.filter(column => column.isFixed())
}
load (columns) {
arrayify(columns).forEach(this.add.bind(this))
}
add (column) {
var col = column instanceof Column ? column : new Column(column)
this.push(col)
this.list.push(col)
return col

@@ -67,3 +63,3 @@ }

/* size */
this.forEach(column => {
this.list.forEach(column => {
column.generateWidth()

@@ -74,3 +70,3 @@ column.generateMinWidth()

/* adjust if user set a min or maxWidth */
this.forEach(column => {
this.list.forEach(column => {
if (t.isDefined(column.maxWidth) && column.generatedWidth > column.maxWidth) {

@@ -102,4 +98,4 @@ column.generatedWidth = column.maxWidth

/* at this point, the generatedWidth should never end up bigger than the contentWidth */
var grownColumns = this.filter(column => column.generatedWidth > column.contentWidth)
var shrunkenColumns = this.filter(column => column.generatedWidth < column.contentWidth)
var grownColumns = this.list.filter(column => column.generatedWidth > column.contentWidth)
var shrunkenColumns = this.list.filter(column => column.generatedWidth < column.contentWidth)
var salvagedSpace = 0

@@ -115,3 +111,3 @@ grownColumns.forEach(column => {

/* if, after autosizing, we still don't fit within viewWidth then give up */
/* if, after autosizing, we still don't fit within viewWidth then give up */
}

@@ -182,2 +178,2 @@

*/
module.exports = Columns
module.exports = require('./no-species')(Columns)

@@ -11,7 +11,6 @@ 'use strict'

* @class Rows
* @extends Array
*/
class Rows extends Array {
class Rows {
constructor (rows, columns) {
super()
this.list = []
this.load(rows, columns)

@@ -21,3 +20,3 @@ }

load (rows, columns) {
arrayify(rows).forEach(row => this.push(new Map(objectToIterable(row, columns))))
arrayify(rows).forEach(row => this.list.push(new Map(objectToIterable(row, columns))))
}

@@ -87,3 +86,3 @@

function objectToIterable (row, columns) {
return columns.map(column => {
return columns.list.map(column => {
return [ column, new Cell(row[column.name], column) ]

@@ -96,2 +95,2 @@ })

*/
module.exports = Rows
module.exports = require('./no-species')(Rows)

@@ -50,3 +50,3 @@ 'use strict'

this.columns.viewWidth = options.viewWidth
this.columns.forEach(column => {
this.columns.list.forEach(column => {
if (options.padding) column.padding = options.padding

@@ -85,3 +85,3 @@ if (options.nowrap) column.nowrap = options.nowrap

this.columns.autoSize()
return this.rows.map(row => {
return this.rows.list.map(row => {
let line = []

@@ -123,3 +123,3 @@ row.forEach((cell, column) => {

return line.reduce((prev, cell, index) => {
let column = this.columns[index]
let column = this.columns.list[index]
return prev + padCell(cell, column.padding, column.generatedWidth)

@@ -148,4 +148,4 @@ }, '')

return (padding.left || '') +
cellValue.padEnd(width - padding.length() + ansiLength) +
(padding.right || '')
cellValue.padEnd(width - padding.length() + ansiLength) +
(padding.right || '')
}

@@ -152,0 +152,0 @@

{
"name": "column-layout",
"author": "Lloyd Brookes <75pound@gmail.com>",
"version": "2.1.1",
"version": "2.1.2",
"description": "Pretty-print JSON data in columns.",

@@ -25,3 +25,3 @@ "repository": "https://github.com/75lb/column-layout.git",

"docs": "jsdoc2md -t jsdoc2md/README.hbs lib/*.js -p list -c list > README.md; echo",
"es5": "babel --no-comments lib --out-dir es5",
"es5": "babel --presets babel-preset-es2015 --no-comments lib --out-dir es5",
"cover": "istanbul cover tape -- test/*.js && cat coverage/lcov.info | ./node_modules/.bin/coveralls && rm -rf coverage; echo"

@@ -31,17 +31,17 @@ },

"ansi-escape-sequences": "^2.2.2",
"array-back": "^1.0.2",
"collect-json": "^1.0.7",
"array-back": "^1.0.3",
"collect-json": "^1.0.8",
"command-line-args": "^2.1.6",
"core-js": "^2.1",
"core-js": "^2.4.0",
"deep-extend": "~0.4.1",
"feature-detect-es6": "^1.2.0",
"object-tools": "^2",
"object-tools": "^2.0.6",
"typical": "^2.4.2",
"wordwrapjs": "^1.1.1"
"wordwrapjs": "^1.2.0"
},
"devDependencies": {
"babel": "^5.8.35",
"coveralls": "^2.11.4",
"jsdoc-to-markdown": "^1.3.3",
"tape": "^4.4.0"
"babel-preset-es2015": "^6.6.0",
"coveralls": "^2.11.9",
"jsdoc-to-markdown": "^1.3.6",
"tape": "^4.5.1"
},

@@ -48,0 +48,0 @@ "standard": {

'use strict'
var test = require('tape')
var columnLayout = require('../')
var os = require('os')
test('columnLayout(data, options)', function (t) {
var fixture = require('./fixture/simple-viewWidth')
var result =
'<row 1 column one .. ><r1 c2 >\n\
<.. .. >< >\n\
<r2 c1 ><row two column 2>\n\
'
var result = [
'<row 1 column one .. ><r1 c2 >',
'<.. .. >< >',
'<r2 c1 ><row two column 2>'
].join(os.EOL) + os.EOL
t.strictEqual(columnLayout(fixture.data, fixture.options), result)

@@ -19,5 +21,5 @@ t.end()

var result = [
"<row 1 column one .. ><r1 c2 >",
"<.. .. >< >",
"<r2 c1 ><row two column 2>"
'<row 1 column one .. ><r1 c2 >',
'<.. .. >< >',
'<r2 c1 ><row two column 2>'
]

@@ -32,5 +34,5 @@

var result = [
"<row 1 column one .. .. ..><3000>",
"<true ><null>",
"<[object Object] >< >"
'<row 1 column one .. .. ..><3000>',
'<true ><null>',
'<[object Object] >< >'
]

@@ -37,0 +39,0 @@

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

columns.autoSize()
t.strictEqual(columns[0].generatedWidth, 12)
t.strictEqual(columns[1].generatedWidth, 18)
t.strictEqual(columns.list[0].generatedWidth, 12)
t.strictEqual(columns.list[1].generatedWidth, 18)
t.end()
})

@@ -5,12 +5,12 @@ 'use strict'

test('columnLayout.table()', function(t){
test('columnLayout.table()', function (t) {
var fixture = require('./fixture/simple-viewWidth')
var table = columnLayout.table(fixture.data, fixture.options)
t.strictEqual(table.rows.length, 2)
t.strictEqual(table.columns.length, 2)
t.strictEqual(table.rows.list.length, 2)
t.strictEqual(table.columns.list.length, 2)
t.end()
})
test('table.getWrapped()', function(t){
test('table.getWrapped()', function (t) {
var fixture = require('./fixture/simple-viewWidth')

@@ -26,3 +26,3 @@ var table = columnLayout.table(fixture.data, fixture.options)

test('table.getLines()', function(t){
test('table.getLines()', function (t) {
var fixture = require('./fixture/simple-viewWidth')

@@ -39,3 +39,3 @@ var table = columnLayout.table(fixture.data, fixture.options)

test('table.renderLines()', function(t){
test('table.renderLines()', function (t) {
var fixture = require('./fixture/simple-viewWidth')

@@ -42,0 +42,0 @@ var table = columnLayout.table(fixture.data, fixture.options)

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