Skip to content

Commit

Permalink
Add usage example for matching multiple items (#176)
Browse files Browse the repository at this point in the history
Co-authored-by: Sindre Sorhus <sindresorhus@gmail.com>
  • Loading branch information
kalaschnik and sindresorhus authored Dec 11, 2023
1 parent b7c0862 commit 3d277f8
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,29 @@ alfy.matches('Foo', list, (item, input) => item === input);

Same as `matches()`, but with `alfy.input` as `input`.

If you want to match against multiple items, you must define your own matching function ([as shown here](#item)). Let’s extend the [example from the beginning](#example) to search for a keyword that appears either within the `title` or `body` property or both.

```js
import alfy from 'alfy';

const data = await alfy.fetch('https://jsonplaceholder.typicode.com/posts');

const items = alfy
.inputMatches(
data,
(item, input) =>
item.title?.toLowerCase().includes(input) ||
item.body?.toLowerCase().includes(input)
)
.map((element) => ({
title: element.title,
subtitle: element.body,
arg: element.id,
}));

alfy.output(items);
```
#### error(error)
Display an error or error message in Alfred.
Expand Down

0 comments on commit 3d277f8

Please sign in to comment.