genepi
v2.1.0
Published
fast reading library
Downloads
8
Readme
genepi
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.
Install
$ npm install genepi
Usage
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'))
API
GenepiReader class
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 wordsread(delayMs = 200, position = 0, backward = false)
executes function of the outputter (header()
,inner(word, index)
andfooter()
)pause()
pause reading and returns current positionchangeDelay(delay)
which pause then play with given delayget length()
get number of wordsget isBackward()
return true if reader is reading backwardget 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 class
GenepiReaderEE is the same as GenepiReader but extending node's EventEmitter.
customize function
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)
SimpleEmitter
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.