-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Mark van der Steenhoven
committed
Oct 30, 2023
1 parent
2e4ac62
commit 9c76099
Showing
7 changed files
with
59 additions
and
32 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Ignore artifacts: | ||
build | ||
coverage |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1 @@ | ||
{ | ||
"printWidth": 100, | ||
"useTabs": false, | ||
"tabWidth": 4, | ||
"singleQuote": true | ||
} | ||
{} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,19 @@ | ||
import { City } from './types/city'; | ||
import { writeFileSync } from 'fs'; | ||
import { City } from "./types/city"; | ||
import { writeFileSync } from "fs"; | ||
|
||
const FILE_PATH = 'src/cities.json'; | ||
const FILE_PATH = "src/cities.json"; | ||
export const getCitiesDataToJson = async (): Promise<void> => { | ||
const response = await fetch('https://opendata.cbs.nl/ODataApi/OData/85516NED/Woonplaatsen'); | ||
const json = await response.json(); | ||
const mappedJson = json.value.map((city: any): City => { | ||
return { | ||
key: city.Key, | ||
title: city.Title, | ||
categoryGroupId: city.CategoryGroupID, | ||
}; | ||
}) as City[]; | ||
writeFileSync(FILE_PATH, JSON.stringify(mappedJson), 'utf8'); | ||
const response = await fetch( | ||
"https://opendata.cbs.nl/ODataApi/OData/85516NED/Woonplaatsen", | ||
); | ||
const json = await response.json(); | ||
const mappedJson = json.value.map((city: any): City => { | ||
return { | ||
key: city.Key, | ||
title: city.Title, | ||
categoryGroupId: city.CategoryGroupID, | ||
}; | ||
}) as City[]; | ||
writeFileSync(FILE_PATH, JSON.stringify(mappedJson), "utf8"); | ||
}; | ||
getCitiesDataToJson(); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,15 @@ | ||
import { City } from './types/city'; | ||
import { searchCity } from './search'; | ||
import { City } from "./types/city"; | ||
import { searchCity } from "./search"; | ||
|
||
import * as cities from './cities.json'; | ||
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 = async ( | ||
needle: string, | ||
): Promise<{ item: City; refIndex: number }> => { | ||
return searchCity(cities, needle)[0]; | ||
}; | ||
export const search = async (needle: string): Promise<{ item: City; refIndex: number }[]> => { | ||
return searchCity(cities, needle); | ||
export const search = async ( | ||
needle: string, | ||
): Promise<{ item: City; refIndex: number }[]> => { | ||
return searchCity(cities, needle); | ||
}; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
import Fuse from 'fuse.js'; | ||
import { City } from './types/city'; | ||
import Fuse from "fuse.js"; | ||
import { City } from "./types/city"; | ||
|
||
export const searchCity = (cities: City[], input: string) => { | ||
const fuse = new Fuse(cities, { | ||
keys: ['title'], | ||
}); | ||
return fuse.search(input); | ||
const fuse = new Fuse(cities, { | ||
keys: ["title"], | ||
}); | ||
return fuse.search(input); | ||
}; |