firest commit
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
import { search } from "@inquirer/prompts"
|
||||
import Fuse from "fuse.js";
|
||||
|
||||
const colors = [
|
||||
{ title: 'Red', value: 'red' },
|
||||
{ title: 'Green', value: 'green' },
|
||||
{ title: 'Blue', value: 'blue' },
|
||||
{ title: 'Yellow', value: 'yellow' },
|
||||
];
|
||||
|
||||
(async () => {
|
||||
const fuse = new Fuse(colors, {
|
||||
keys: ['title'],
|
||||
threshold: 0.4,
|
||||
})
|
||||
const color = await search({
|
||||
message: "Pick a color",
|
||||
source: async (term) => {
|
||||
if (!term) {
|
||||
return colors.map(s => s.value);
|
||||
}
|
||||
const result = fuse.search(term);
|
||||
return result.map(s => s.item.value);
|
||||
}
|
||||
})
|
||||
console.log(color); // => { color: 'green' }
|
||||
})();
|
||||
Reference in New Issue
Block a user