postel-ita
Version:
Library to create files compatible with italian Poste Postel system
87 lines • 2.44 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
class PostelTextBlock {
get text() {
return this._text;
}
get maxWidth() {
return this._maxWidth;
}
get alignRight() {
return this._alignRight;
}
get alignLeft() {
return this._alignLeft;
}
get bold() {
return this._bold;
}
constructor(parent, text, maxWidth, alignRight, alignLeft) {
this._row = parent;
this._text = text;
this._alignRight = alignRight;
this._maxWidth = maxWidth;
this._alignLeft = alignLeft;
this._bold = false;
}
result() {
let textTrunc = this._maxWidth === undefined
? this._text
: this._text.substring(0, this._maxWidth);
if (this._alignRight !== undefined && this._maxWidth !== undefined)
textTrunc = textTrunc.padStart(this._maxWidth, ' ');
else if (this._maxWidth !== undefined)
textTrunc = textTrunc.padEnd(this._maxWidth, ' ');
const textLen = textTrunc.length;
const text = textTrunc
.replace('€', '@L:')
.replace('à', '@LH')
.replace('è', '@LI')
.replace('é', '@LE')
.replace('ì', '@LY')
.replace('ò', '@LJ')
.replace('ù', '@LK');
let padding = 0;
if (this._alignRight !== undefined)
padding = this._alignRight - textLen;
if (this._alignLeft !== undefined)
padding = this._alignLeft;
let ret = '';
if (padding !== 0)
ret += '@?' + padding.toString().padStart(2, '0');
if (this._bold)
ret += '@O';
ret += text;
if (this._bold)
ret += '@o';
return ret;
}
back() {
return this._row;
}
setText(newText) {
this._text = newText;
return this;
}
setMaxWidth(width) {
this._maxWidth = width;
return this;
}
setAlignRight(paddingRight) {
this._alignRight = paddingRight;
return this;
}
setAlignLeft(paddingLeft) {
this._alignLeft = paddingLeft;
return this;
}
setBold(mustBeBold) {
this._bold = mustBeBold;
return this;
}
toString() {
return this.result();
}
}
exports.default = PostelTextBlock;
//# sourceMappingURL=PostelTextBlock.js.map