Giter Site home page Giter Site logo

did-you-mean's Introduction

Did You Mean ...

Fuzzy match a word from your list of commands or keywords in Node.js to provide a friendly typo-safe human prompt.

You can use it in:

  • your CLI
  • a web application
  • URLs
  • etc.

Installation

$ npm install did-you-mean

Usage

var Matcher = require('did-you-mean');

// Create a matcher with a list of values
var m = new Matcher('init install update upgrade');

// Get the closest match
m.get('udpate');   // 'update'

// Set the threshold (the maximum Levenshtein distance)
m.setThreshold(3);

// List all matches
m.list('udpate');    // [ { value: 'update', distance: 2 }, { value: 'upgrade', distance: 3 } ]

// Set ignore case
m.ignoreCase();

// Set match case
m.matchCase();

// Add more values
m.add('merge', 'checkout', 'commit');

did-you-mean's People

Contributors

myhlamaeus avatar peecky avatar shama avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

did-you-mean's Issues

Further document list function

Does this code snippet return a list in the order of least-to-most distance?

// List all matches
m.list('udpate');    // [ { value: 'update', distance: 2 }, { value: 'upgrade', distance: 3 } ]

[Update] After looking through the source, this seems to be ordered. Think that could be documented in the readme?

Parameterize distance algorithm

Allow to set the distance algorithm as an option in the constructor. Example:

var levenshtein = require('fast-levenshtein');

// Receives two words and returns their distance
var myAlgorithm = function( word1, word2 ) {
    return levenshtein.get( word1, word2 );
};

// Passing the algorithm to use as an option
var m = new Matcher('init install update upgrade', { algorithm: myAlgorithm } );

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.