Super basic repl (read, eval, print, loop) for creating CLIs
Usage
repl(prefix, handler)
Example
import repl from 'basic-repl'
repl('> ', code => {
//Eval input and log it
console.log(eval(code))
})
repl('[server] ', msg => {
//This repl is for our chat
//(Let's assume you already made a function chat(){...})
chat(msg)
console.log('✓ Chat message sent')
})
You can switch between multiple repls you have created with Tab
Commonjs
// For compatibility, commonjs works slightly differently
//1. a space is appended to the end of the prefix
//2. the value returned by the function is logged (in ES6 you must console.log() it yourself)
require('basic-repl')('$', code => eval(code))