mattyork / fuzzy

Filters a list based on a fuzzy string search
MIT License
831 stars 86 forks source link

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

Open YPCrumble opened 7 years ago

YPCrumble commented 7 years ago

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?

SamVerschueren commented 7 years ago

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']