UNPKG

france-cities-js

Version:

Search and get informations about french cities from the package offline database

44 lines (43 loc) 1.3 kB
import { cities } from '../../constants'; function byName(name, limit) { var tempCities = []; cities.forEach(function (city) { if (city.slug.includes(name)) { tempCities.push(city); } }); return limit ? tempCities.slice(0, limit) : tempCities; } function byZipCode(zipCode, limit) { var tempCities = []; cities.forEach(function (city) { if (city.zip_code.includes(zipCode)) { tempCities.push(city); } }); return limit ? tempCities.slice(0, limit) : tempCities; } function byInseeCode(inseeCode, limit) { var tempCities = []; cities.forEach(function (city) { if (city.insee_code.includes(inseeCode)) { tempCities.push(city); } }); return limit ? tempCities.slice(0, limit) : tempCities; } function byDepartmentCode(departmentCode, limit) { var tempCities = []; cities.forEach(function (city) { if (city.department_code.includes(departmentCode)) { tempCities.push(city); } }); return limit ? tempCities.slice(0, limit) : tempCities; } export var searchCity = { byName: byName, byDepartmentCode: byDepartmentCode, byInseeCode: byInseeCode, byZipCode: byZipCode, };