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

press-any-key

v1.1.0

Published

Press any key to continue...

Downloads

62,573

Readme

press-any-key

A utility to launch the simplest confirmation dialog.

npx -q press-any-key
Press any key to continue...

If user presses any key it will exit with code 0. In the case of pressing CTRL+C it will exit with code 1.

Install

If you wish to use the utility from a npm scripts, you can install it into your project as a usual npm dependency.

npm install press-any-key --save-dev

But you can also use npx to invoke the command without install.

npx -q press-any-key

Arguments

press-any-key <message> [...options]

By the default, the message is "Press any key to continue...", but if you would like you can specify your own message as the first argument.

press-any-key "Press any key to run the application"

Options:

--ctrlc <code> Exit code on pressing CTRL-C. --preserve-log Do not clean the message, after resolve --hide-message Do not show the massage

How to route

You can use standard bash logical operators && and || to perform branching.

npx -q press-any-key && echo "A good choice!" || echo "Bye bye :("

Or you can rely on the fact that CTRL + C, by default, exits the process.

For example, you have a script that performs irreversible actions, and to avoid accidental execution of the script, you can add additional confirmation.

echo 'You are about to delete all files in current directory'
npx -q press-any-key
rm -rf *
You are about to delete all files in the current directory
Press any key to continue...

Programmatic usage

You can use the package press-any-key API in your node.js script.

const pressAnyKey = require('press-any-key');

pressAnyKey()
  .then(() => {
    // ... User presses a key
  })

API

pressAnyKey(message, options)

The message is a string that will be displayed in the standard output before it starts to listen for key presses. Pass null if you'd like to use the default message.

Options:

  • ctrlC The exit code, or "reject" (do reject the promise), or false to perceive as pressing any key.
  • preserveLog Preserve the message in the log
  • hideMessage Do not show the message

By default, when the user presses CTRL+C, the function will exit the process. However, you can change the standard behavior of CTRL+C by passing the option ctrlC with the value "reject". In this case, pressing CTRL+C will not exit the process but will instead reject the promise.

const pressAnyKey = require('press-any-key');

pressAnyKey("Press any key to resolve, or CTRL+C to reject", {
  ctrlC: "reject"
})
  .then(() => {
    console.log('You pressed any key')
  })
  .catch(() => {
    console.log('You pressed CTRL+C')
  })

Author

Vladimir Kalmykov [email protected]

License

MIT