-
-
Notifications
You must be signed in to change notification settings - Fork 121
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Search for multiple object properties in alfy.matches
and alfy.inputMatches
#175
Comments
alfy. matches
and alfy alfy. matches
and alfy.inputMatches
alfy. matches
and alfy.inputMatches
alfy.matches
and alfy.inputMatches
I should have read the README.md more carefully. I made my example to work using 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); |
In my specific example, I noticed that some properties may contain 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); |
Is this little example something worth adding to the README.md? Happy to propose a PR. |
The problem with supporting multiple properties like this: const items = alfy.inputMatches(data, ['title', 'body']).map((element) => ({
title: element.title,
subtitle: element.body,
arg: element.id,
})); is that it's not immediately clear whether either or both properties have to match. |
PR welcome for adding the tip to the readme. |
Good point. I was about to propose extending your dot.prop’s getProperty function, but that feels too over-engineered in the end. |
Assume I got the follwing workflow from the README.md:
How would I search for
title
and thebody
of the response? For example, I want to be able to search for quia et suscipit and get one result (i.e., the body of first element in the array)Is this already implemented or do I need to write my own matching function?
The text was updated successfully, but these errors were encountered: