Neatly Packaged Magic

    magic-search

    1.0.0 • Public • Published

    magic-search

    A simple fuzzy search tool similar to Sublime-Text's cmd-P search system.

    Filters a collection down to only items that contain all of the characters in the query:

    • in the correct order;
    • with any amount of other characters in between.

    It should work with any collection that implements filter(lambda) like Array does.

    const search = require('magic-search');
     
    const fruit = [
      'Apple',
      'Apricot',
      'Avocado',
      'Banana',
      'Bilberry',
      'Blackberry',
      'Blackcurrant',
      ...
    ];
     
    search(fruit, 'aple')
    → ['Apple', 'Custard apple', 'Pineapple']
     
    search(fruit, 'sberry')
    → ['Boysenberry', 'Gooseberry', 'Raspberry', ...]

    Use with a getter

    If you need to filter a collection of items that are more than just strings, you can use a getter function as the third argument.

    const filteredByGenus = search(fruit, 'rosales', item => item.getGenus())

    Keywords

    none

    Install

    npm i magic-search

    DownloadsWeekly Downloads

    0

    Version

    1.0.0

    License

    MIT

    Last publish

    Collaborators

    • eseb