GithubHelp home page GithubHelp logo

inquirer-fuzzy-select's Introduction

Inquirer Fuzzy Select

This package is based on @inquirer/select, but adds the ability to filter the select list.

Note: Since the input is used for filtering, some interactions that were included in @inquirer/select do not work here:

  • Cycling through the list via number keys
  • Cycling through the list via Vim keys
  • Cycling through the list via Emacs keys

Installation

npm install inquirer-fuzzy-select

Basic Usage

import { fuzzySelect } from 'inquirer-fuzzy-select';

const answer = await select({
  message: 'Select a number',
  choices: [
    { value: 1, name: "One" },
    { value: 2, name: "Two" },
    { value: 3, name: "Three" },
  ],
});

Advanced items

import { fuzzySelect, Separator } from 'inquirer-fuzzy-select';

const answer = await select({
  message: 'Select a package manager',
  choices: [
    {
      name: 'npm',
      value: 'npm',
      description: 'npm is the most popular package manager',
    },
    {
      name: 'yarn',
      value: 'yarn',
      description: 'yarn is an awesome package manager',
    },
    new Separator(),
    {
      name: 'jspm',
      value: 'jspm',
      disabled: true,
    },
    {
      name: 'pnpm',
      value: 'pnpm',
      disabled: '(pnpm is not available)',
    },
  ],
});

Advanced filtering

If you want to

import { fuzzySelect } from 'inquirer-fuzzy-select';

const answer = await fuzzySelect({
  message: "Select a number to translate to german",
  choices: [
    { value: "Eins", name: "One", meta: 1 },
    { value: "Zwei", name: "Two", meta: 2 },
    { value: "Drei", name: "Three", meta: 3 },
    { value: "Vier", name: "Four", meta: 4 },
    { value: "Fünf", name: "Five", meta: 5 },
    { value: "Sechs", name: "Six", meta: 6 },
  ] as const,
  comparer(input) {
    return (choices) => {
      const query = input.toLowerCase();
      if (choices.type === "separator") return true;
      if (choices.name?.toLowerCase().includes(query)) return true;
      if (choices.meta?.toString().includes(query)) return true;
      return false;
    };
  },
});

License

Copyright ©2023 Henning Pohlmeyer
Licensed under the MIT license.

inquirer-fuzzy-select's People

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.