let's add the "emit" method. it takes the bites as its ARGUMENT and it returns WHATEVER you want to pump out.
/**
* @typedef {object} Term
* ...
* @property {(bites: string[]) => string} emit
*/
first, make sure to use it within the translate method.
Term.Default = {
//...
translate(text) {
const bites = this.bite(text)
if (bites.length === 0) {
return this.throw(text)
}
return this.emit(bites)
}
}
by default, terms emit their bites.
Term.Default = {
//...
emit(bites) {
return bites.join("")
}
}
you can OVERRIDE it though, of course. here's a ping term that emits "pong".
Term.Pong = {
...Term.string("pong"),
emit() {
return "ping"
}
}
try it out.
back to the dream