-
-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from kadirahq/fuzzy-search
Fuzzy kind filter
- Loading branch information
Showing
3 changed files
with
17 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
} |