mirror of
https://github.com/thelounge/thelounge
synced 2024-11-29 15:30:22 +00:00
dd05ee3a65
Co-authored-by: Eric Nemchik <eric@nemchik.com> Co-authored-by: Pavel Djundik <xPaw@users.noreply.github.com>
42 lines
861 B
TypeScript
42 lines
861 B
TypeScript
type PrefixSymbol = string;
|
|
|
|
type PrefixObject = {
|
|
symbol: PrefixSymbol;
|
|
mode: string;
|
|
};
|
|
|
|
class Prefix {
|
|
prefix: PrefixObject[];
|
|
modeToSymbol: {[mode: string]: string};
|
|
symbols: string[];
|
|
|
|
constructor(prefix: PrefixObject[]) {
|
|
this.prefix = prefix || []; // [{symbol: "@", mode: "o"}, ... ]
|
|
this.modeToSymbol = {};
|
|
this.symbols = [];
|
|
this._update_internals();
|
|
}
|
|
|
|
_update_internals() {
|
|
// clean out the old cruft
|
|
this.modeToSymbol = {};
|
|
this.symbols = [];
|
|
|
|
const that = this;
|
|
this.prefix.forEach(function (p) {
|
|
that.modeToSymbol[p.mode] = p.symbol;
|
|
that.symbols.push(p.symbol);
|
|
});
|
|
}
|
|
|
|
update(prefix: PrefixObject[]) {
|
|
this.prefix = prefix || [];
|
|
this._update_internals();
|
|
}
|
|
|
|
forEach(f: (value: PrefixObject, index: number, array: PrefixObject[]) => void) {
|
|
return this.prefix.forEach(f);
|
|
}
|
|
}
|
|
|
|
export default Prefix;
|