diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 0000000..1b07c39 --- /dev/null +++ b/.prettierignore @@ -0,0 +1,3 @@ +# Ignore artifacts: +build +coverage \ No newline at end of file diff --git a/.prettierrc b/.prettierrc index b06ca2e..0967ef4 100644 --- a/.prettierrc +++ b/.prettierrc @@ -1,6 +1 @@ -{ - "printWidth": 100, - "useTabs": false, - "tabWidth": 4, - "singleQuote": true -} +{} diff --git a/package-lock.json b/package-lock.json index b0957af..12b19e0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -18,6 +18,7 @@ "@types/node": "^20.8.7", "chokidar": "^3.5.3", "jest": "^29.7.0", + "prettier": "3.0.3", "rimraf": "^5.0.5", "ts-loader": "^9.5.0", "ts-node": "^10.9.1", @@ -5422,6 +5423,21 @@ "node": ">=8" } }, + "node_modules/prettier": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.0.3.tgz", + "integrity": "sha512-L/4pUDMxcNa8R/EthV08Zt42WBO4h1rarVtK0K+QJG0X187OLo7l699jWw0GKuwzkPQ//jMFA/8Xm6Fh3J/DAg==", + "dev": true, + "bin": { + "prettier": "bin/prettier.cjs" + }, + "engines": { + "node": ">=14" + }, + "funding": { + "url": "https://github.com/prettier/prettier?sponsor=1" + } + }, "node_modules/pretty-format": { "version": "29.7.0", "resolved": "https://registry.npmjs.org/pretty-format/-/pretty-format-29.7.0.tgz", @@ -10752,6 +10768,12 @@ "find-up": "^4.0.0" } }, + "prettier": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.0.3.tgz", + "integrity": "sha512-L/4pUDMxcNa8R/EthV08Zt42WBO4h1rarVtK0K+QJG0X187OLo7l699jWw0GKuwzkPQ//jMFA/8Xm6Fh3J/DAg==", + "dev": true + }, "pretty-format": { "version": "29.7.0", "resolved": "https://registry.npmjs.org/pretty-format/-/pretty-format-29.7.0.tgz", diff --git a/package.json b/package.json index bde4bf9..6bfce2b 100644 --- a/package.json +++ b/package.json @@ -17,6 +17,7 @@ "@types/node": "^20.8.7", "chokidar": "^3.5.3", "jest": "^29.7.0", + "prettier": "3.0.3", "rimraf": "^5.0.5", "ts-loader": "^9.5.0", "ts-node": "^10.9.1", diff --git a/src/getCities.ts b/src/getCities.ts index a4be6e7..96d96ba 100644 --- a/src/getCities.ts +++ b/src/getCities.ts @@ -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 => { - 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(); diff --git a/src/index.ts b/src/index.ts index d580bb8..c86ba9c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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); }; diff --git a/src/search.ts b/src/search.ts index 91346e8..cafd01c 100644 --- a/src/search.ts +++ b/src/search.ts @@ -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); };