match_sorter 0.1.0 copy "match_sorter: ^0.1.0" to clipboard
match_sorter: ^0.1.0 copied to clipboard

A dart adaptation of the match-sorter package for javascript

match-sorter #

A dart adaptation of the match-sorter package for javascript

Examples #

Basic Usage #

import 'package:match_sorter/match_sorter.dart';

void main() {
  List<Item> items = stringsToItems(['Chakotay', 'Brunt', 'Charzard']);
  var searchQuery = 'Ch';

  List<Item> matchedItems = matchSorter(
    searchQuery: searchQuery,
    items: items,
  );

  print(matchedItems);
  // [{ value: Chakotay }, { value: Charzard }]
}

Multiple keys #

import 'package:match_sorter/match_sorter.dart';

void main() {
  var items = [
    {'name': 'baz', 'reverse': 'zab'},
    {'name': 'bat', 'reverse': 'tab'},
    {'name': 'foo', 'reverse': 'oof'},
    {'name': 'bag', 'reverse': 'gab'},
  ];
  var searchQuery = 'ab';
  var keys = [Key('name'), Key('reverse')];


  List<Item> matchedItems = matchSorter(
    searchQuery: searchQuery,
    items: items,
    keys: keys
  );

  print(matchedItems);
  // [ {'name': 'bag', 'reverse': 'gab'}, {'name': 'bat', 'reverse': 'tab'}, {'name': 'baz', 'reverse': 'zab'} ]
}

More examples coming soon. In the meantime you can browser the test suite to explore advanced usecases

2
likes
0
points
46
downloads

Publisher

verified publisherdecafdevs.com

Weekly Downloads

A dart adaptation of the match-sorter package for javascript

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

collection, diacritic

More

Packages that depend on match_sorter