Skip to content

Commit

Permalink
added prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark van der Steenhoven committed Oct 30, 2023
1 parent 2e4ac62 commit 9c76099
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 32 deletions.
3 changes: 3 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Ignore artifacts:
build
coverage
7 changes: 1 addition & 6 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -1,6 +1 @@
{
"printWidth": 100,
"useTabs": false,
"tabWidth": 4,
"singleQuote": true
}
{}
22 changes: 22 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
28 changes: 15 additions & 13 deletions src/getCities.ts
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();
18 changes: 11 additions & 7 deletions src/index.ts
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);
};
12 changes: 6 additions & 6 deletions src/search.ts
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);
};

0 comments on commit 9c76099

Please sign in to comment.