A tiny fast reading library. It is not usable by itself but you can have a look at genepi-console to use it from your terminal.
$ npm install genepi
const { genepi } = require('genepi')
const DELAY = 180
const outputter = {
header: function header() { /* do stuff */ },
inner: function inner(word, index) { /* do stuff */ },
footer: function footer() { /* do stuff */ }
}
function genepize(text) {
return genepi(text, myOutputter, DELAY)
}
genepize('This is a text')
.then(() => console.log('end of treatment'))
GenepiReader class extends SimpleEmitter which is a minimalistic way to send event to a listener. It provides on
and emit
functions.
GenepiReader provides functions to change reading parameters
-
constructor(text, outputter)
take a text and an object (outputter) which handle words -
read(delayMs = 200, position = 0, backward = false)
executes function of the outputter (header()
,inner(word, index)
andfooter()
) -
pause()
pause reading and returns current position -
changeDelay(delay)
which pause then play with given delay -
get length()
get number of words -
get isBackward()
return true if reader is reading backward -
get delay()
return current delay { -
get position()
return current position { -
get status()
return current status { -
emitStatusChange(status)
emit a'StatusChange'
event with status as a string for payload. This is the function internally used by other functions that changes reading status. Possible statuses are:'init'
'reading'
'paused'
'end'
GenepiReaderEE is the same as GenepiReader but extending node's EventEmitter.
customize is a function allowing user to chose extended class as function parameter. It returns a class of readers. So, given a MyEventEmitter a reader can be instanciated as follow
const myCustomReader = new customize(MyEventEmitter)
The minimalistic event emitter used by GenepiReader is a class with two methods:
-
on(event, callback)
: to register a listener (callback
) -
emit(event, data)
: to send an event to listener with data as a payload
Only those two methods from EventEmitter are called by GenepiReader. As EventEmitter may not be available outside of NodeJS, SimpleEmitter is here to give a mean to call listeners in an internal use only. It is not exposed by the API.