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

reply

v0.5.0

Published

Create console-based wizards in a snap.

Downloads

129

Readme

Reply

Simple way of getting user input in Node.js. Prompt is really awesome but it ships with too much stuff I don't really need.

Features

  • Verifies type of response (string, number, boolean), and returns native value.
  • Can check response against regex or array of options.
  • Custom error message for each field, or fallback to 'Invalid value'.
  • Masks password fields with '*', with support for backspace keystrokes.
  • Fields can hold a default value, be marked as required or allow an empty response.

Install

npm install reply

Usage

var reply = require('reply');

var opts = {
  name: {
    message : 'Please type in your name.',
    allow_empty: false // will require an answer
  },
  username: {
    default : 'nobody' // if left empty, will fall back to this value
    type    : 'string'    // ensure value is not a number
  },
  gender: {
    options : ['Male', 'Female', 'Robot', 'Rather not say']
  },
  password: {
    message : 'Password, please.',
    type    : 'password',
    regex   : /(\w{6})/,
    error   : 'Six chars minimum. Try again.'
  },
  country: {
    message : 'Where are you now?',
    default : get_country // use the function below to provide a default/fallback answer
  },
  zip_code: {
    message : 'Please enter your ZIP code.',
    type    : 'number', // reply uses the JS primitives, as returned by `typeof var`
    depends_on: {
      country: 'US'
    }
  }
}

function get_country(answers) {
  // answers contains the values given up to this point.
  if (answers.username == 'billgates')
    return 'US';
  else // we'll simply guess it from the LANG variable
    return process.env.LANG.split(/_|\./)[1]; 
}

reply.get(opts, function(err, answers) {
  console.log(answers); 
  /* { name: 'Bill Gates', 
       username: 'billgates',
       gender: 'Robot', 
       password: '123456',
       country: 'US',
       zip_code: 12345 } */
});

Confirm (yes/no)

reply.confirm('Are you up for it?', function(err, yes) {
  var answer = (!err && yes) ? "That's crack-a-lackin!" : 'Bummer.';
  console.log(answer);
});

Options

  • message : What's displayed when requesting the user's input. Optional, though helpful.
  • default : Default value in case user just presses the enter key. Can be a value or a function that returns a value.
  • depends_on: Key/val object containing the previous answers from which a specific entry depends on. Check the depends-on.js example for a use case.
  • type : Determines the type of response that is expected to the valid. Possible values are: string, password, number, or boolean.
  • options : Array of elements from which the user is expected to give a valid answer from.
  • regex : Validates response against the given regex.
  • allow_empty: Disallows empty answers.

You can find a few more use cases in the examples directory.

Credits

Written by Tomás Pollak.

Copyright

(c) Fork Ltd. MIT license.