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

inquirer-path

v1.0.0-beta5

Published

An Inquirer extension to support path questions

Downloads

16,435

Readme

Inpuirer Path

This project provides a path prompt for the Inquirer module. It allows the user to pick a path using a similar interface as zsh.

Usage

Install the module using npm install inquirer-path.

Create a question just as you would with any other Inquirer question types. Once included, the module registers itself with the resolved inquirer instance. If you want to register it under another question type or if you are using a different inquirer instance, you should include:

import { PathPrompt } from 'inquirer-path';
inquirer.prompt.registerPrompt('path', PathPrompt);

Multi Path

If the question's multi property is set to true, the prompt will indefinitely ask for more paths. In order to finalize the answer, the user must either send a SIGINT or hit the escape key. The last answer is discarded when the user exits the prompt

Config

The path question supports the following options:

  • type: (String) Type of the prompt. Should be set to path in order to use this module.
  • name: (String) The name to use when storing the answer in the answers hash.
  • cwd: (String) The current working directory for the path prompt. If the input path is relative, it is resolved from the provided cwd. It must be a path to an existing local folder. If none is provided, it defaults to the system's root directory.
  • default: (String) Save as the cwd option.
  • multi: (Boolean) Set to true if the prompt should ask for multiple paths. If multi is set to true, the path entry can be stopped by sending the SIGINT signal (ctrl+C)
  • directoryOnly: (Boolean) Set to true if the prompt should only autocomplete (or suggest) directories.
  • validate: (Function) Receive the user input and should return true if the value is valid, and an error message (String) otherwise. If false is returned, a default error message is provided. If multi is true, it is called for each path entered by the user as well as once the prompt finishes.
  • filter: (Function) Receive the user input and return the filtered value to be used inside the program. The value returned will be added to the Answers hash.
  • when: (Function, Boolean) Receive the current user answers hash and should return true or false depending on whether or not this question should be asked. The value can also be a simple boolean.

Example

import inquirer from ('inquirer');
import { PathPrompt } from 'inquirer-path';

const questions = [{
  type: 'path',
  name: 'path',
  message: 'Enter a path',
  default: process.cwd(),
}];

inquirer.registerPrompt('path', PathPrompt);
inquirer.prompt(questions)
  .then((result) => console.log(result.path));

You can see additional examples in the examples folder.

Development

The API documentation can be found here

This project defines the following npm scripts to help you during development:

  • compile - Compile the code in ./src and output it into ./lib
  • compile-watch - Watch the ./src folder. When a change occurs, the code is recompiled and the docs are regenerated.
  • lint - Run eslint to validate the code formatting
  • fix-lint - Fix the simple eslint error
  • docs - Generate the html documentation to ./docs
  • docs-watch - Create a documentation server at localhost:4001
  • docs-md - Generate the DOCUMENTATION.md file

Debugging

This project is a real pain to debug. Using console.log messes up the UI (and is often overriden by it) and the Webstorm debugger does not play nice with user input. The best way I have found so far is to use console.error and redirect the error stream to a file. I have one terminal in which I run node yourscript.js 2> debug.txt and another in which I observe the output using tail -f debug.txt. I'm definitely opened to better suggestions.