npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

creply

v1.1.2

Published

creply create read–eval–print-loop (repl) programs

Downloads

11

Readme

creply

create read–eval–print-loop (repl) programs want to create a repl? with creply you create easily you can use it with TypeScript too!

  • also see the documetation generated by typedoc

creating the repl

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: "!"
});
  • this will create a repl with the following options:
{
  "name": "app",
  "description": "simple node.js repl app",
  "version": "v1.0.0",
  "history": "app.history",
  "prompt": "app> ",
  "prefix": "!"
}

starting the repl

repl.start();
  • this will start the repl and output the following:
app>

adding commands

  • commands are added with the repl.addCommand() method
  • commands are saved in the repl.commands object
repl.addCommand("hello",{ 
  description: "hello world", 
  exec: (args) => { 
   console.log("hello world")
  },
  usage: () => "hello [name]"
  })
  • this will add a command with the following options:
{
  "description": "say hello",
  "exec": "[Function: exec]",
  "usage": "[Function: usage]"
}

removing commands

  • commands are removed with the repl.removeCommand() method
repl.removeCommand("hello");
  • this will remove the command with the name hello
  • the command will be removed from the repl.commands object

updating options

  • options are updated with the repl.set() method
  • options are saved in the repl.options object
  • example updating the prompt
repl.set({
  prompt: "cli> "
});
  • this will update the prompt to cli>
  • output will be:
cli>

getting options

  • options are retrieved with the repl.get() method
console.log(repl.get("prompt"));
  • this will output the prompt
  • output will be:
cli>

listening to events

  • 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);
});
  • example listening to the uncaught-error event
  • the event will be called when the repl throws an error
repl.on("uncaught-error", (err) => {
  console.log("uncaught-error: " + err);
});
  • example listening the keypress event
  • the event will be called when the user press a key
repl.on("keypress", (char, key) => {
  console.log("keypress: " + key);
});
  • example listening to the exit event
  • this event will be called when the repl is closed
repl.on("exit", () => {
  console.log("exit");
});
  • example listening to the cursor-move event
  • this event will be called when the cursor moves
repl.on("cursor-move", (cursor) => {
  console.log("cursor-move: " + cursor);
});
  • example listening to the command event
  • this event will be called when the repl executes a command
repl.on("command", (command, args) => {
  console.log("command: " + command);
});
  • example listening to the command-not-found event
  • this event will be called when the repl executes a command that doesn't exist
repl.on("command-not-found", (command) => {
  console.log("command-not-found: " + command);
});
  • example listening to the did-you-mean event
  • this event will be called when repl try to mean the command
repl.on("did-you-mean", (command, didYouMean) => {
  console.log("did-you-mean: " + didYouMean);
});
  • example listening to the command-not-specified event
  • this event will be called when the repl executes a command that doesn't have a name
repl.on("command-not-specified", () => {
  console.log("command-not-specified");
});
  • example listening to the start event
  • this event is triggered when the repl starts
  • the listener must be before the repl.start() call
repl.on("start", () => {
  console.log("started!");
});

readline and rl

  • the readline is the readline library used by the creply
  • the rl is the readline interface used by the creply
  • to get readline use repl.readline
  • to get rl use repl.rl but you need to start the repl first by using repl.start()

view command usage

  • the repl.usage() method will print the usage of the command
repl.usage("hello"); // hello [name]
  • you can type help [command] to see the usage of the command on the repl
app> help hello
  • output:
hello [name]

common problems

  • if console.log prints out of the repl, you can use the repl.log() method
  • the repl.log() method will print out the data to the repl
  • this methods clear prompt and move the cursor to the start of the line
repl.log("hello");
  • output:
cli>
hello
cli>