Skip to content

Commit

Permalink
fixed the search, did know why it broke
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark van der Steenhoven committed Oct 30, 2023
1 parent d1b7969 commit 44d49c0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 12 deletions.
14 changes: 4 additions & 10 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
import { City } from "./types/city";
import { searchCity } from "./search";

import * as cities from "./cities.json";

export const searchOne = async (
needle: string,
): Promise<{ item: City; refIndex: number }> => {
return searchCity(cities, needle)[0];
export const searchOne = (needle: string): { item: City; refIndex: number } => {
return searchCity(needle)[0];
};
export const search = async (
needle: string,
): Promise<{ item: City; refIndex: number }[]> => {
return searchCity(cities, needle);
export const search = (needle: string): { item: City; refIndex: number }[] => {
return searchCity(needle);
};
5 changes: 3 additions & 2 deletions src/search.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import Fuse from "fuse.js";
import { City } from "./types/city";

export const searchCity = (cities: City[], input: string) => {
const fuse = new Fuse(cities, {
import cityData from "./cities.json";
export const searchCity = (input: string): Fuse.FuseResult<City>[] => {
const fuse = new Fuse(cityData, {
keys: ["title"],
});
return fuse.search(input);
Expand Down

0 comments on commit 44d49c0

Please sign in to comment.