Skip to content

Commit

Permalink
build: bump to 0.3.2 (#42)
Browse files Browse the repository at this point in the history
  • Loading branch information
ajit authored Aug 1, 2021
2 parents fa23aa3 + f317ac7 commit 639aa04
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"===== INFO =====": "",
"name": "fzf",
"version": "0.3.1",
"version": "0.3.2",
"description": "Do fuzzy matching using FZF algorithm in JavaScript",
"license": "BSD-3-Clause",
"keywords": [
Expand Down
17 changes: 12 additions & 5 deletions src/lib/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,12 @@ interface Options<U> {
* @defaultValue false
*/
normalize: boolean;
// TODO we need different sort metric
// sort: boolean;
/*
* If true, FZF will sort result items in descending by score.
*
* @defaultValue true
*/
sort: boolean;
}

const defaultOpts: Options<any> = {
Expand All @@ -54,6 +58,7 @@ const defaultOpts: Options<any> = {
selector: (v) => v,
casing: "smart-case",
normalize: false,
sort: true,
};

export interface FzfResultItem<U = string> {
Expand Down Expand Up @@ -121,9 +126,11 @@ export class Fzf<U> {
const thresholdFilter = (v: FzfResultItem<U>) => v.result.score !== 0;
let result = this.runesList.map(getResult).filter(thresholdFilter);

const descScoreSorter = (a: FzfResultItem<U>, b: FzfResultItem<U>) =>
b.result.score - a.result.score;
result.sort(descScoreSorter);
if (this.opts.sort) {
const descScoreSorter = (a: FzfResultItem<U>, b: FzfResultItem<U>) =>
b.result.score - a.result.score;
result.sort(descScoreSorter);
}

if (Number.isFinite(this.opts.maxResultItems)) {
result = result.slice(0, this.opts.maxResultItems);
Expand Down
3 changes: 2 additions & 1 deletion src/views/docs.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ const reactElement = <HighlightChars str={entry.item} highlightIndices={entry.po
// where `entry` is an item from the result list which is returned from `fzf.find()`
```
Find a [working example](basic) for this and its [sourcecode](https://github.com/ajitid/fzf-for-js/blob/stable-releases/src/views/basic.tsx).
Find a [working example](basic) for this and its [sourcecode](https://github.com/ajitid/fzf-for-js/blob/fa23aa35ca32f3964349452e03358dacdd136d68/src/views/basic.tsx#L96-L99).
### Notes
Expand All @@ -116,6 +116,7 @@ Find a [working example](basic) for this and its [sourcecode](https://github.com
- `selector?` - function, defaults to `v => v` - For each item in the list, target a specific property of the item to search for. This becomes a required option to pass when `list` is composed of items other than strings.
- `casing?` - string, defaults to `"smart-case"`, accepts `"smart-case" | "case-sensitive" | "case-insensitive"` - Defines what type of case sensitive search you want.
- `normalize?` - boolean, defaults to `false` - If true, FZF will try to remove diacritics from list items. This is useful if the list contains items with diacritics but you want to query with plain A-Z letters. For example, Zoë will be converted to Zoe.
- `sort?` - boolean, defaults to `true` - If true, result items will be sorted in descending order by their score.
### `fzf.find(query)`
Expand Down

0 comments on commit 639aa04

Please sign in to comment.