Comments (6)
PR welcome for adding the tip to the readme.
from alfy.
I should have read the README.md more carefully. I made my example to work using includes
as such:
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);
from alfy.
In my specific example, I noticed that some properties may contain null
on which toLowerCase()
would fail. It makes sense to add optional chaining for such properties
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);
from alfy.
Is this little example something worth adding to the README.md? Happy to propose a PR.
from alfy.
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.
from alfy.
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.
Good point. I was about to propose extending your dot.prop’s getProperty function, but that feels too over-engineered in the end.
from alfy.
Related Issues (20)
- Error [ERR_UNSUPPORTED_ESM_URL_SCHEME]: Only file and data URLs are supported by the default ESM loader HOT 3
- Type for "mods" requires all properties to be defined
- alfy.matches doesn't work with umlauts
- fetch method does not work correctly HOT 1
- fetch with `json: false` is ignored? HOT 2
- Script filter with images? HOT 1
- Usage with bun? HOT 1
- Dependabot alerts on dependencies HOT 2
- Using console log in global scope crashes the execution HOT 3
- Package location different than workflow location
- Cannot use import statement outside a module HOT 1
- Package workflows so that end users don’t require `node` at runtime? HOT 1
- How should Alfy change to accommodate the new Alfred Gallery? HOT 2
- How to show a loading indicator? HOT 1
- Alfred 5 HOT 1
- Unable to install and use Alfred workflow locally HOT 1
- Alfy.fetch not working with https HOT 1
- alfy-init failed if using volta as a toolchain manager.
- Question about caching, fetch vs alfy.fetch HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from alfy.