vodafone-station-cli
Version:
Access your Vodafone Station from the comfort of the command line.
81 lines (80 loc) • 2.74 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.TablePrinter = void 0;
class TablePrinter {
docsisStatus;
head = [
'ID',
'Ch. Type',
'Modulation',
'Power',
'Frequency',
' Lock status ',
'SNR ',
];
constructor(docsisStatus) {
this.docsisStatus = docsisStatus;
}
get lineSeparator() {
const dash = '-';
const plus = '+';
const dashes = this.spacedHead.map(word => dash.repeat(word.length));
return ['', ...dashes, ''].join(plus);
}
get spacedHead() {
return this.head.map(header => ` ${header} `);
}
docsis31StatusToRow(rowObjects) {
return rowObjects?.map(channelStatus => [
channelStatus.channelId,
channelStatus.channelType,
channelStatus.modulation,
channelStatus.powerLevel,
`${channelStatus.frequencyStart}-${channelStatus.frequencyEnd}`,
channelStatus.lockStatus,
channelStatus.snr,
])
.map(rowValues => this.tableRow(...rowValues))
.join('\n') ?? '';
}
docsisStatusToRow(rowObjects) {
return rowObjects?.map(channelStatus => [
channelStatus.channelId,
channelStatus.channelType,
channelStatus.modulation,
channelStatus.powerLevel,
channelStatus.frequency,
channelStatus.lockStatus,
channelStatus.snr,
])
.map(rowValues => this.tableRow(...rowValues))
.join('\n') ?? '';
}
lineText(...words) {
const paddedWords = words.map((word, index) => {
const headerWord = this.head[index];
return String(word).padEnd(headerWord.length, ' ');
});
return ['', ...paddedWords, ''].join(' | ').trim();
}
print() {
const header = this.tableHeader();
const downstream = this.docsisStatusToRow(this.docsisStatus.downstream);
const downstreamOfdm = this.docsis31StatusToRow(this.docsisStatus.downstreamOfdm);
const upstream = this.docsisStatusToRow(this.docsisStatus.upstream);
const upstreamOfdma = this.docsis31StatusToRow(this.docsisStatus.upstreamOfdma);
return `
Downstream\n${header}\n${downstream}\n
Downstream OFDM\n${header}\n${downstreamOfdm}\n
Upstream\n${header}\n${upstream}\n
Upstream OFDMA\n${header}\n${upstreamOfdma}
`;
}
tableHeader() {
return `${this.lineSeparator}\n${this.lineText(...this.head)}\n${this.lineSeparator}`;
}
tableRow(...words) {
return `${this.lineText(...words)}\n${this.lineSeparator}`;
}
}
exports.TablePrinter = TablePrinter;