Skip to content

Commit

Permalink
Merge pull request #3 from kadirahq/fuzzy-search
Browse files Browse the repository at this point in the history
Fuzzy kind filter
  • Loading branch information
Muhammed Thanish authored Jun 10, 2016
2 parents bd50036 + 2c83543 commit 5db400e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
13 changes: 11 additions & 2 deletions dist/modules/ui/libs/filters.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
"use strict";
'use strict';

Object.defineProperty(exports, "__esModule", {
value: true
});
exports.storyFilter = storyFilter;

var _fuzzysearch = require('fuzzysearch');

var _fuzzysearch2 = _interopRequireDefault(_fuzzysearch);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function storyFilter(stories, filter, selectedKind) {
if (!stories) return null;
if (!filter) return stories;

return stories.filter(function (kindInfo) {
if (kindInfo.kind === selectedKind) return true;
return kindInfo.kind.toLocaleLowerCase().indexOf(filter) >= 0;
var needle = filter.toLocaleLowerCase();
var hstack = kindInfo.kind.toLocaleLowerCase();
return (0, _fuzzysearch2.default)(needle, hstack);
});
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"@kadira/react-split-pane": "^1.4.0",
"babel-runtime": "^6.5.0",
"deep-equal": "^1.0.1",
"fuzzysearch": "^1.0.3",
"json-stringify-safe": "^5.0.1",
"keycode": "^2.1.1",
"lodash.pick": "^4.2.1",
Expand Down
6 changes: 5 additions & 1 deletion src/modules/ui/libs/filters.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import fuzzysearch from 'fuzzysearch';

export function storyFilter(stories, filter, selectedKind) {
if (!stories) return null;
if (!filter) return stories;

return stories.filter((kindInfo) => {
if (kindInfo.kind === selectedKind) return true;
return kindInfo.kind.toLocaleLowerCase().indexOf(filter) >= 0;
const needle = filter.toLocaleLowerCase();
const hstack = kindInfo.kind.toLocaleLowerCase();
return fuzzysearch(needle, hstack);
});
}

0 comments on commit 5db400e

Please sign in to comment.