Skip to content

Instantly share code, notes, and snippets.

@johnlindquist
Created December 22, 2023 21:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnlindquist/06b6aae31f4e6ffe6eea712c08427dc9 to your computer and use it in GitHub Desktop.
Save johnlindquist/06b6aae31f4e6ffe6eea712c08427dc9 to your computer and use it in GitHub Desktop.
// 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