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

cli-autocomplete-prompt

v1.0.0

Published

A primitive autocomplete prompt that provides full control over its UI and behaviors

Downloads

3

Readme

cli-autocomplete-prompt

npm

A primitive autocomplete prompt that provides full control over its UI and behaviors.

jest style autocomplete prompt in action

Motivation

In one of my projects, I was trying to create the jest-watch-typeahead style autocomplete prompt. My initial attempt was to find a library to implement it. I found several good CLI prompt libraries, and most of them offered UI, behavior customization to some extent. However, those customizations were not enough to build the needed prompt. Therefore, I created this autocomplete prompt that extendable to control its UI and behaviors.

Install

npm install --save cli-autocomplete-prompt

Usage

The autocomplete prompt can be created using the autoComplete factory function. See the default-autocomplete directory for reference.

const { autoComplete } = require('cli-autocomplete-prompt');

const list = [
  { label: 'lib/cli/index.js', value: 'lib/cli/index.js' },
  { label: 'lib/cli/print.js', value: 'lib/cli/print.js' },
  { label: 'lib/mocha/run.js', value: 'lib/mocha/run.js' },
  { ... },
];

(async () => {
    const options = { list };
    const results = await autoComplete(options);

    console.log(results);
})();

Use ↑ up / ↓ down arrow keys to navigate. Use ↵ enter key to get the matched item[s].

autocomplete prompt in action

Default behaviors:

  • If the input is empty, it matches all items when the prompt is submitted.
  • The suggestion logic uses the String.includes method on items' label property to update the list while the user types.
  • It prevents prompt submission when there is no match found.

API

autoComplete(options?)

Type: Function Returns: Promise

It takes an options (optional) object and returns the matched items when the prompt is submitted.

Options

| Property     | Type     | Default     | Description | | :--- | :--- | :--- | :--- | | promptLabel | string | '' | Prompt label to display | | limit | number | 10 | Max number of results to show | | list | array | [] | An array of list items. A list item should be an object with the label, value property. The label should be a type string, and the value can be anything. | | onSubmit | function | undefined | A hook to transform the matched items before they get submitted. It receives the matched items (array) as an argument. |

Customization

In addition to the factory function, the package exports a class and a couple of utility functions to customize the prompt's default UI and behaviors. View CUSTOMIZATION.md to learn more about the customization.

Todo

  • [ ] Support wordwrap
  • [ ] Tests
  • [ ] CI Setup

Credits

Prompts - is a lightweight library to create beautiful and user-friendly interactive prompts. Some ideas have been taken from this project to build the autocomplete prompt.

License

MIT License © Sureshraj