Skip to content

Commit

Permalink
added a readme, thank chatgpt
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark van der Steenhoven committed Oct 30, 2023
1 parent 44d49c0 commit 22dc6cf
Show file tree
Hide file tree
Showing 5 changed files with 131 additions and 13 deletions.
94 changes: 93 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,93 @@
## I Will do this laterrrr
Thank you for providing more details about the objects returned by your package. Here's an updated README that reflects the object structure:

---

# Dutch Cities Formatter

## Description

The `dutch-cities-formatter` is a lightweight JavaScript package that provides two essential functions for handling Dutch city names: `search` and `searchOne`. These functions allow you to search for Dutch city names, correct capitalization, expand abbreviations, and handle common misspellings.

This package is particularly useful when dealing with user-generated data where city names may come in various formats with different capitalization, abbreviations, or misspellings.

## Features

- Corrects capitalization for city names.
- Expands abbreviations to full city names.
- Handles common misspellings and variations.
- Provides search capabilities for Dutch city names.
- Returns city objects with keys and titles.

## Installation

To use the `dutch-cities-formatter` package in your project, follow these steps:

1. **Install the Package**:

You can install the package using npm or yarn:

```bash
npm install dutch-cities-formatter
```

or

```bash
yarn add dutch-cities-formatter
```

2. **Import and Use**:

Import the package into your JavaScript or TypeScript file:

```javascript
// CommonJS
const { search, searchOne } = require("dutch-cities-formatter");

// ES modules (for modern JavaScript)
import { search, searchOne } from "dutch-cities-formatter";
```

## Usage

### `search(cityName: string): City[]`

The `search` function allows you to search for Dutch city names that match the input `cityName`. It returns an array of city objects, each containing a `key`, `title`, and `categoryGroupId`.

```javascript
const matchingCities = search("amst"); // Example search for cities starting with 'amst'
console.log(matchingCities);
/* Output:
[
{ key: 'amsterdam', title: 'Amsterdam', categoryGroupId: 1 },
{ key: 'amstelveen', title: 'Amstelveen', categoryGroupId: 2 },
// ...
]
*/
```

### `searchOne(cityName: string): City | null`

The `searchOne` function searches for a Dutch city name that most closely matches the input `cityName`. It returns a single city object that is the best match or `null` if no match is found.

```javascript
const bestMatch = searchOne("rottrdam"); // Example search for a closely matching city
console.log(bestMatch);
/* Output:
{
key: 'rotterdam',
title: 'Rotterdam',
categoryGroupId: 1
}
*/
```

These functions return city objects with `key`, `title`, and `categoryGroupId`, ensuring that your Dutch city names are consistently formatted and corrected, making them suitable for various applications.

## License

This package is open-source and available under the MIT License. Feel free to use it in your projects and contribute to its development on [GitHub](https://github.com/yourusername/dutch-cities-formatter).

For more details and usage examples, please refer to the [documentation](https://github.com/yourusername/dutch-cities-formatter).

---
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dutch-cities-formatter",
"version": "1.0.1",
"version": "1.0.2",
"description": "small util library to get dutch cities in a formatted way",
"author": "Mark van der Steenhoven",
"license": "MIT",
Expand Down
3 changes: 2 additions & 1 deletion src/getCities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { City } from "./types/city";
import { writeFileSync } from "fs";

const FILE_PATH = "src/cities.json";

export const getCitiesDataToJson = async (): Promise<void> => {
const response = await fetch(
"https://opendata.cbs.nl/ODataApi/OData/85516NED/Woonplaatsen",
Expand All @@ -13,7 +14,7 @@ export const getCitiesDataToJson = async (): Promise<void> => {
title: city.Title,
categoryGroupId: city.CategoryGroupID,
};
}) as City[];
});
writeFileSync(FILE_PATH, JSON.stringify(mappedJson), "utf8");
};
getCitiesDataToJson();
43 changes: 35 additions & 8 deletions src/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,37 @@
import * as fs from 'fs';
import { getCitiesDataToJson } from './getCities';
import * as fs from "fs";
import { getCitiesDataToJson } from "./getCities";
import { search } from "./index";
describe("writeCitiesToDist", () => {
it("should write cities to file and check if it exists", async () => {
await getCitiesDataToJson();
const fileExists = fs.existsSync("src/cities.json");
expect(fileExists).toBe(true);
});
});

describe("search", () => {
it("should return an empty array when no cities match the search term", () => {
const result = search("nonexistent city");
expect(result).toEqual([]);
});

//This tests also lets me know when anything changes on fuse their side
it("should return an array of matching cities and their indices", () => {
const result = search("amsterdam").slice(0, 2);

describe('writeCitiesToDist', () => {
it('should write cities to file and check if it exists', async () => {
await getCitiesDataToJson();
const fileExists = fs.existsSync('src/cities.json');
expect(fileExists).toBe(true);
});
expect(result).toEqual([
{
item: { key: "WP3594", title: "Amsterdam", categoryGroupId: 1 },
refIndex: 67,
},
{
item: {
key: "WP3569",
title: "Amsterdam-Duivendrecht",
categoryGroupId: 1,
},
refIndex: 68,
},
]);
});
});
2 changes: 0 additions & 2 deletions src/types/city.js

This file was deleted.

0 comments on commit 22dc6cf

Please sign in to comment.