node-fzf: Fuzzy CLI List Selector

0.14.0 · active · verified Sun Apr 19

node-fzf is a Node.js utility inspired by the `fzf` command-line fuzzy finder, providing an interactive CLI for list selection. It enables developers to integrate fuzzy searching capabilities into their Node.js applications, offering both a standalone CLI and a programmatic API. The current stable version is 0.14.0, published approximately 10 months ago, suggesting a maintenance or slow release cadence rather than rapid iteration. Key differentiators include its promise-based and callback-based API for integration, support for piping input and output with other CLI tools, and customizable display options like height and pre/post-line hooks. Unlike `fzf-node` which are direct Go bindings, `node-fzf` is a pure JavaScript implementation.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates the promise-based API of `node-fzf` to present an interactive fuzzy selection list to the user, allowing them to pick an item from a predefined array. It showcases basic configuration, result handling, and interactive features.

const nfzf = require('node-fzf');

const opts = {
  list: ['apple', 'banana', 'orange', 'grape', 'strawberry', 'blueberry', 'raspberry', 'pineapple', 'mango', 'kiwi'],
  mode: 'fuzzy',
  query: '',
  selectOne: false,
  height: 50, // Use 50% of the screen height
  prelinehook: function (index) { return `[${index + 1}] `; },
  postlinehook: function (index) { return ` (${this.list[index].length} chars)`; }
};

(async function () {
  console.log('Starting fuzzy search. Use Ctrl-S to switch modes, Up/Down to navigate.');
  const result = await nfzf(opts);

  const { selected, query } = result;

  if (!selected) {
    console.log(`No match found for query: '${query}'`);
  } else {
    console.log(`\nSelected item: '${selected.value}' at index ${selected.index}`);
    console.log(`Original list item: '${opts.list[selected.index]}'`);
  }
  process.exit(0); // Ensure the process exits after selection
})();

view raw JSON →