dutch-cities-formatter
v1.0.4
Published
small util library to get dutch cities in a formatted way
Downloads
1
Readme
Dutch Cities Formatter
Build status
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:
Install the Package:
You can install the package using npm or yarn:
npm install dutch-cities-formatter
or
yarn add dutch-cities-formatter
Import and Use:
Import the package into your JavaScript or TypeScript file:
// 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
and title
.
const matchingCities = search("amst"); // Example search for cities starting with 'amst'
console.log(matchingCities);
/* Output:
[
{ key: 'WP3594', title: 'Amsterdam' },
{ key: 'WP1050', title: 'Amstelveen' },
// ...
]
*/
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.
const bestMatch = searchOne("rottrdam"); // Example search for a closely matching city
console.log(bestMatch);
/* Output:
{
key: 'WP3086',
title: 'Rotterdam',
}
*/
These functions return city objects with key
, title
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.
For more details and usage examples, please refer to the documentation.