symfony-style-console
Version:
Use the style and utilities of the Symfony Console in Node.js
219 lines (218 loc) • 6.41 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var Helper_1 = require("./Helper");
/**
* Defines the styles for a Table.
*
* @author Fabien Potencier <fabien@symfony.com>
*
* Original PHP class
*
* @author Саша Стаменковић <umpirsky@gmail.com>
*
* Original PHP class
*
* @author Florian Reuschel <florian@loilo.de>
*
* Port to TypeScript
*
*/
var TableStyle = /** @class */ (function () {
function TableStyle() {
/**
* The character that pads the end of cell contents.
*/
this.paddingChar = ' ';
/**
* The character horizontal borders are built from.
*/
this.horizontalBorderChar = '-';
/**
* The character vertical borders are built from.
*/
this.verticalBorderChar = '|';
/**
* The character horizontal + vertical intersections are built from
*/
this.crossingChar = '+';
/**
* A format for header cells.
*/
this.cellHeaderFormat = '<info>%s</info>';
/**
* A format for regular cells.
*/
this.cellRowFormat = '%s';
/**
* A format for regular cell's content.
*/
this.cellRowContentFormat = ' %s ';
/**
* A format for borders.
*/
this.borderFormat = '%s';
/**
* The direction cells should be padded at.
*/
this.padType = 'STR_PAD_RIGHT';
}
/**
* Clones the [[TableStyle]] instance.
*/
TableStyle.prototype.clone = function () {
var inst = new TableStyle();
inst.setPaddingChar(this.getPaddingChar());
inst.setHorizontalBorderChar(this.getHorizontalBorderChar());
inst.setVerticalBorderChar(this.getVerticalBorderChar());
inst.setCrossingChar(this.getCrossingChar());
inst.setCellHeaderFormat(this.getCellHeaderFormat());
inst.setCellRowFormat(this.getCellRowFormat());
inst.setCellRowContentFormat(this.getCellRowContentFormat());
inst.setBorderFormat(this.getBorderFormat());
inst.setPadType(this.getPadType());
return inst;
};
/**
* Sets padding character, used for cell padding.
*
* @param paddingChar The cell padding character to use
*/
TableStyle.prototype.setPaddingChar = function (paddingChar) {
if (!paddingChar) {
throw new Error('The padding char must not be empty');
}
this.paddingChar = paddingChar;
return this;
};
/**
* Gets padding character, used for cell padding.
*/
TableStyle.prototype.getPaddingChar = function () {
return this.paddingChar;
};
/**
* Sets horizontal border character.
*
* @param horizontalBorderChar The horizontal border character to use
*/
TableStyle.prototype.setHorizontalBorderChar = function (horizontalBorderChar) {
this.horizontalBorderChar = horizontalBorderChar;
return this;
};
/**
* Gets horizontal border character.
*/
TableStyle.prototype.getHorizontalBorderChar = function () {
return this.horizontalBorderChar;
};
/**
* Sets vertical border character.
*
* @param verticalBorderChar The vertical border character to use
*/
TableStyle.prototype.setVerticalBorderChar = function (verticalBorderChar) {
this.verticalBorderChar = verticalBorderChar;
return this;
};
/**
* Gets vertical border character.
*/
TableStyle.prototype.getVerticalBorderChar = function () {
return this.verticalBorderChar;
};
/**
* Sets crossing character.
*
* @param crossingChar The crossing character to use
*/
TableStyle.prototype.setCrossingChar = function (crossingChar) {
this.crossingChar = crossingChar;
return this;
};
/**
* Gets crossing character.
*/
TableStyle.prototype.getCrossingChar = function () {
return this.crossingChar;
};
/**
* Sets header cell format.
*
* @param cellHeaderFormat The header cell format to use
*/
TableStyle.prototype.setCellHeaderFormat = function (cellHeaderFormat) {
this.cellHeaderFormat = cellHeaderFormat;
return this;
};
/**
* Gets header cell format.
*/
TableStyle.prototype.getCellHeaderFormat = function () {
return this.cellHeaderFormat;
};
/**
* Sets row cell format.
*
* @param cellRowFormat The row cell format to use
*/
TableStyle.prototype.setCellRowFormat = function (cellRowFormat) {
this.cellRowFormat = cellRowFormat;
return this;
};
/**
* Gets row cell format.
*/
TableStyle.prototype.getCellRowFormat = function () {
return this.cellRowFormat;
};
/**
* Sets row cell content format.
*
* @param cellRowContentFormat The cell content format to use
*/
TableStyle.prototype.setCellRowContentFormat = function (cellRowContentFormat) {
this.cellRowContentFormat = cellRowContentFormat;
return this;
};
/**
* Gets row cell content format.
*/
TableStyle.prototype.getCellRowContentFormat = function () {
return this.cellRowContentFormat;
};
/**
* Sets table border format.
*
* @param borderFormat The border format to use
*/
TableStyle.prototype.setBorderFormat = function (borderFormat) {
this.borderFormat = borderFormat;
return this;
};
/**
* Gets table border format.
*/
TableStyle.prototype.getBorderFormat = function () {
return this.borderFormat;
};
/**
* Sets cell padding type.
*
* @param padType The padding type to use
*/
TableStyle.prototype.setPadType = function (padType) {
if (!Helper_1.arrContains(['STR_PAD_LEFT', 'STR_PAD_RIGHT', 'STR_PAD_BOTH'], padType)) {
throw new ReferenceError('Invalid padding type. Expected one of (STR_PAD_LEFT, STR_PAD_RIGHT, STR_PAD_BOTH).');
}
this.padType = padType;
return this;
};
/**
* Gets cell padding type.
*/
TableStyle.prototype.getPadType = function () {
return this.padType;
};
return TableStyle;
}());
exports.default = TableStyle;