Created
December 22, 2023 21:19
-
-
Save johnlindquist/06b6aae31f4e6ffe6eea712c08427dc9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Name: Search by Value | |
import "@johnlindquist/kit" | |
let fruits = [ | |
{ name: "Apple", description: "A sweet, edible fruit", value: "USA" }, | |
{ name: "Banana", description: "A long, curved fruit", value: "South America" }, | |
{ name: "Cherry", description: "A small, round fruit", value: "Europe" }, | |
{ name: "Date", description: "A sweet, chewy fruit", value: "Middle East" }, | |
{ name: "Elderberry", description: "A small, dark fruit", value: "North America" }, | |
] | |
await arg( | |
{ | |
placeholder: "Search for a fruit by country", | |
debounceInput: 0, // There's a default debounce input of 200ms because this might be a network call | |
}, | |
async input => { | |
let results = fruits.filter(fruit => fruit.value.toLowerCase().includes(input.toLowerCase())) | |
return results.map(fruit => ({ | |
name: fruit.name, | |
description: fruit.description, | |
value: fruit.value, | |
})) | |
} | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment