mattyork / fuzzy

Filters a list based on a fuzzy string search

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add a `noresults` option that returns a string to the user

YPCrumble opened this issue · comments

I'd like to provide the user with a default option in the event that their search returns no results. Something simple like "No results found" but that can be customized as well. Is that something you'd be interested in a PR for?

Isn't that easily implemented yourself?

const fuzzy = require('fuzzy');

function filter(input, term) {
    const results = fuzzy.filter(input, term);
    
    if (results.length === 0) {
        return ['No results found'];
    }

    return results.map(x => x.string);
}

const list = ['baconing', 'narwhal', 'a mighty bear canoe'];

filter(list, 'bcn');
//=> ['No results found']