postel-ita
Version:
Library to create files compatible with italian Poste Postel system
76 lines • 2.52 kB
JavaScript
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const Lang_1 = __importDefault(require("../Lang"));
const PostelTextBlock_1 = __importDefault(require("./PostelTextBlock"));
class PostelRow {
constructor(opt) {
this._position = opt ?? { type: 'abs', value: 1 };
this._textBlocks = [];
this._prePostText = { pre: undefined, post: undefined };
this._shebang = true;
}
get position() {
return this._position;
}
set position(value) {
this._position = value;
}
shebang(newValue) {
this._shebang = newValue;
return this;
}
lineSpacing(spaceCount) {
this._lineSpacing = spaceCount;
return this;
}
font(index) {
this._font = index;
return this;
}
appendText(text) {
const newBlock = new PostelTextBlock_1.default(this, text);
this._textBlocks.push(newBlock);
return this._textBlocks.at(-1) || new PostelTextBlock_1.default(this, text);
}
prePostText(pre = undefined, post = undefined) {
this._prePostText = { pre: pre, post: post };
return this;
}
result() {
const rows = [];
const rowM = [];
// 1° ILN code
if (this._lineSpacing)
rowM.push('INL ' + this._lineSpacing);
// 2° TOP
if (this._position.type === 'abs')
rowM.push('TOP');
// 3° TEX code
if (this._font)
rowM.push('TEX ' + this._font);
// 4° BOT/SPA
if (this._position.type === 'bot')
rowM.push('BOT');
else if (this._position.value !== undefined &&
this._position.value !== 0)
rowM.push(Lang_1.default.newLine(this._position.value));
const shebang = () => (this._shebang ? '!' : '');
if (rowM.length > 0)
rows.push(shebang() + rowM.join(';'));
let row0 = this._textBlocks.join('');
if (this._prePostText.pre !== undefined)
row0 = this._prePostText.pre + row0;
if (this._prePostText.post !== undefined)
row0 += this._prePostText.post;
rows.push(row0);
return rows.length > 0 ? rows.join(Lang_1.default.EOL) : '';
}
toString() {
return this.result();
}
}
exports.default = PostelRow;
//# sourceMappingURL=PostelRow.js.map