diff --git a/index.js b/index.js index 2f3994e657fbbfd1ca25939d8261d1f38df9d848..1faf750cd85840175c58f79830f1275ed643bdd1 100644 --- a/index.js +++ b/index.js @@ -247508,12 +247508,17 @@ async function getInseeCode(postalCode, city) { if (!city) throw new Error('No city') const parsedCity = sanitizeCity(city) - console.log(parsedCity) - const filteredResponse = response.data.filter( - town => sanitizeCity(town.nomCommune) === parsedCity + const filteredResponse = response.data.filter(commune => + sanitizeCity(commune.nomCommune).includes(parsedCity) ) + if (filteredResponse.length > 1) { + throw new Error( + 'Input city is not precise enough, more than one city was found' + ) + } + return filteredResponse[0].codeCommune } } catch (error) {