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

@fnet/prompt

v0.2.14

Published

The `@fnet/prompt` project offers a straightforward way to gather user input through command-line prompts. Built on top of the Enquirer library, it simplifies the process of defining and collecting responses, making it useful for developers who need a qui

Downloads

345

Readme

@fnet/prompt

The @fnet/prompt project offers a straightforward way to gather user input through command-line prompts. Built on top of the Enquirer library, it simplifies the process of defining and collecting responses, making it useful for developers who need a quick and easy solution for interactive command-line applications.

How It Works

This project leverages the Enquirer library to present prompts to users in the command line. By defining the prompts in an array or object, users can specify the type and name of each prompt. If not provided, default values are assigned. Once configured, the prompts are displayed, and the user's input is collected for further processing.

Key Features

  • Type Flexibility: Automatically assigns a default type of 'input' if not specified, ensuring a smoother user experience.
  • Dynamic Prompt Naming: Generates default names for prompts, allowing for consistent identification of responses.
  • Enquirer Integration: Utilizes the Enquirer library to manage and display prompts, offering reliability and ease of use.

Conclusion

The @fnet/prompt project serves as a helpful tool for developers when user input is needed in command-line applications. Its integration with Enquirer provides a simple and reliable interface, handling user prompts effectively with minimal setup.

Developer Guide for @fnet/prompt

Overview

The @fnet/prompt library is designed to simplify the process of gathering user input in Node.js applications. By leveraging the enquirer module, it allows developers to easily create interactive command-line prompts. The library automates setting up default configurations for user prompts, making it easier to gather input with minimal setup.

Installation

To install the library, use either npm or yarn:

npm install @fnet/prompt

or

yarn add @fnet/prompt

Usage

The primary functionality of @fnet/prompt is encapsulated in a default exported function. This function takes an argument or an array of arguments to specify the prompts you wish to display. Let's dive into how you can use it in your projects.

Basic Usage

Here is a basic example of how to use the library:

import prompt from '@fnet/prompt';

async function gatherInput() {
    // Define the prompt questions
    const questions = [
        {
            type: 'input',
            name: 'username',
            message: 'What is your username?'
        },
        {
            type: 'password',
            name: 'password',
            message: 'Enter your password'
        }
    ];

    // Execute the prompt
    const responses = await prompt(questions);

    console.log('User Responses:', responses);
}

gatherInput();

Single Prompt

For a single prompt, you can pass an object directly:

import prompt from '@fnet/prompt';

async function singlePrompt() {
    const response = await prompt({
        type: 'input',
        message: 'Please enter your email:',
        name: 'email'
    });

    console.log('Email:', response.email);
}

singlePrompt();

Examples

Below are some example scenarios showcasing how to use @fnet/prompt for typical use cases:

Multiple Choice

To gather input for a multiple-choice question:

import prompt from '@fnet/prompt';

async function multipleChoicePrompt() {
    const response = await prompt({
        type: 'select',
        name: 'favoriteColor',
        message: 'What is your favorite color?',
        choices: ['Red', 'Green', 'Blue']
    });

    console.log('Selected Color:', response.favoriteColor);
}

multipleChoicePrompt();

Confirm Prompt

Prompting the user for a yes/no confirmation:

import prompt from '@fnet/prompt';

async function confirmAction() {
    const response = await prompt({
        type: 'confirm',
        name: 'confirm',
        message: 'Do you want to proceed?'
    });

    console.log('Confirmed:', response.confirm);
}

confirmAction();

Acknowledgement

This library utilizes the enquirer library, ensuring a robust and flexible way to create prompts for user input in command-line applications.

Input Schema

$schema: https://json-schema.org/draft/2020-12/schema
title: PromptArguments
type:
  - array
  - object
description: Schema for prompt arguments used in Enquirer prompts.
anyOf:
  - type: array
    items:
      $ref: "#/$defs/promptItem"
  - $ref: "#/$defs/promptItem"
$defs:
  promptItem:
    type: object
    properties:
      type:
        type: string
        default: input
        description: Type of the prompt (e.g., input, checkbox).
      name:
        type: string
        default: user_input
        description: Name identifier for the prompt input.