1.0.0 • Published 7 months ago
french-city v1.0.0
french-city
French cities utils
Install
npm install french-city
Usage
import {
getCityByExactName,
searchCitiesByName,
getCitiesByDepartement,
getCitiesByPostalCode,
} from 'french-city';
// Example usage
const exactCity = getCityByExactName('Lyon');
console.log(exactCity); // { city: 'Lyon', zip_code: '69001', department_name: 'Rhône' }
const cities = searchCitiesByName('Saint-');
console.log(cities); // Array of cities with 'Saint-' in their name
const departmentCities = getCitiesByDepartement('Rhône');
console.log(departmentCities); // Array of cities in the 'Rhône' department
const postalCodeCities = getCitiesByPostalCode('69001');
console.log(postalCodeCities); // Array of cities with postal code '69001'
API
getCityByInseeCode(codeInsee)
- codeInsee:
string
- The INSEE code of the city. - Returns:
City | undefined
- The city object or undefined if not found.
getCityByExactName(name)
- name:
string
- The exact name of the city. - Returns:
City | undefined
- The city object or undefined if not found.
searchCitiesByName(name)
- name:
string
- A part of the city's name. - Returns:
City[]
- An array of matching city objects.
getCitiesByDepartement(departement)
- departement:
string
- The name of the department. - Returns:
City[]
- An array of city objects in the department.
getCitiesByPostalCode(codePostal)
- codePostal:
string
- The postal code. - Returns:
City[]
- An array of city objects with the postal code.
City Interface
export interface City {
city: string;
zip_code: string;
department_name: string;
}