Skip to content

Commit 3d277f8

Browse files
Add usage example for matching multiple items (#176)
Co-authored-by: Sindre Sorhus <sindresorhus@gmail.com>
1 parent b7c0862 commit 3d277f8

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

readme.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,29 @@ alfy.matches('Foo', list, (item, input) => item === input);
323323

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

326+
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.
327+
328+
```js
329+
import alfy from 'alfy';
330+
331+
const data = await alfy.fetch('https://jsonplaceholder.typicode.com/posts');
332+
333+
const items = alfy
334+
.inputMatches(
335+
data,
336+
(item, input) =>
337+
item.title?.toLowerCase().includes(input) ||
338+
item.body?.toLowerCase().includes(input)
339+
)
340+
.map((element) => ({
341+
title: element.title,
342+
subtitle: element.body,
343+
arg: element.id,
344+
}));
345+
346+
alfy.output(items);
347+
```
348+
326349
#### error(error)
327350
328351
Display an error or error message in Alfred.

0 commit comments

Comments
 (0)