create read–eval–print-loop (repl) programs
want to create a repl? with creply you create easily
you can use it with TypeScript too!
const creply = require("creply");
const repl = new creply({
name: "app",
description: "simple node.js repl app",
version: "v1.0.0",
history: "app.history",
prompt: "app> ",
prefix: "!"
});
{
"name": "app",
"description": "simple node.js repl app",
"version": "v1.0.0",
"history": "app.history",
"prompt": "app> ",
"prefix": "!"
}
repl.start();
app>
repl.addCommand()
methodrepl.commands
objectrepl.addCommand("hello",{
description: "hello world",
exec: (args) => {
console.log("hello world")
},
usage: () => "hello [name]"
})
{
"description": "say hello",
"exec": "[Function: exec]",
"usage": "[Function: usage]"
}
repl.removeCommand()
methodrepl.removeCommand("hello");
hello
repl.commands
objectrepl.set()
methodrepl.options
objectrepl.set({
prompt: "cli> "
});
cli>
cli>
repl.get()
methodconsole.log(repl.get("prompt"));
cli>
events are listen with the repl.on()
method
when you listen an event the repl will not prints the data except the event uncaught-error
example listening to the line
event
the event will be called when the user types a line
repl.on("line", (line) => {
console.log("line: " + line);
});
uncaught-error
eventrepl.on("uncaught-error", (err) => {
console.log("uncaught-error: " + err);
});
keypress
eventrepl.on("keypress", (char, key) => {
console.log("keypress: " + key);
});
exit
eventrepl.on("exit", () => {
console.log("exit");
});
cursor-move
eventrepl.on("cursor-move", (cursor) => {
console.log("cursor-move: " + cursor);
});
command
eventrepl.on("command", (command, args) => {
console.log("command: " + command);
});
command-not-found
eventrepl.on("command-not-found", (command) => {
console.log("command-not-found: " + command);
});
did-you-mean
eventrepl.on("did-you-mean", (command, didYouMean) => {
console.log("did-you-mean: " + didYouMean);
});
command-not-specified
eventrepl.on("command-not-specified", () => {
console.log("command-not-specified");
});
start
eventrepl.start()
callrepl.on("start", () => {
console.log("started!");
});
repl.readline
repl.rl
but you need to start the repl first by using repl.start()
repl.usage()
method will print the usage of the commandrepl.usage("hello"); // hello [name]
help [command]
to see the usage of the command on the replapp> help hello
hello [name]
console.log
prints out of the repl, you can use the repl.log()
methodrepl.log()
method will print out the data to the replrepl.log("hello");
cli>
hello
cli>
Generated using TypeDoc