@cofondateurauchomage/libs 1.1.176 → 1.1.177

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getRegionCodeForDepartment = getRegionCodeForDepartment;
4
4
  exports.searchLocationSuggestions = searchLocationSuggestions;
5
5
  exports.geocodeCityLabel = geocodeCityLabel;
6
+ const legacyCityLabel_1 = require("./legacyCityLabel");
6
7
  const parse_1 = require("./parse");
7
8
  const GEO_API = "https://geo.api.gouv.fr";
8
9
  const ADRESSE_API = "https://api-adresse.data.gouv.fr";
@@ -139,6 +140,9 @@ async function searchLocationSuggestions(query) {
139
140
  }
140
141
  /** Geocode a legacy free-text city label (migration script). */
141
142
  async function geocodeCityLabel(cityLabel) {
143
+ if ((0, legacyCityLabel_1.isUngeocodableLegacyCityLabel)(cityLabel)) {
144
+ return null;
145
+ }
142
146
  const q = `${cityLabel.trim()}, France`;
143
147
  const features = await fetchAdresseFeatures(q);
144
148
  if (!features.length) {
@@ -0,0 +1,4 @@
1
+ /** Normalize legacy free-text city labels for comparison. */
2
+ export declare function normalizeLegacyCityLabel(label: string): string;
3
+ /** Returns true when a legacy city string is too vague to geocode reliably. */
4
+ export declare function isUngeocodableLegacyCityLabel(cityLabel: string): boolean;
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.normalizeLegacyCityLabel = normalizeLegacyCityLabel;
4
+ exports.isUngeocodableLegacyCityLabel = isUngeocodableLegacyCityLabel;
5
+ /** Normalize legacy free-text city labels for comparison. */
6
+ function normalizeLegacyCityLabel(label) {
7
+ return label
8
+ .trim()
9
+ .toLowerCase()
10
+ .normalize("NFD")
11
+ .replace(/[\u0300-\u036f]/g, "")
12
+ .replace(/[.!,;:]+$/g, "")
13
+ .replace(/\s+/g, " ");
14
+ }
15
+ /** Country-wide or non-local labels that must not be sent to API Adresse. */
16
+ const UNGEOCODABLE_LEGACY_CITY_LABELS = new Set([
17
+ "france",
18
+ "toute la france",
19
+ "en france",
20
+ "france entiere",
21
+ "france metropolitaine",
22
+ "metropole",
23
+ "remote",
24
+ "teletravail",
25
+ "partout",
26
+ "n/a",
27
+ "na",
28
+ ]);
29
+ /** Returns true when a legacy city string is too vague to geocode reliably. */
30
+ function isUngeocodableLegacyCityLabel(cityLabel) {
31
+ const normalized = normalizeLegacyCityLabel(cityLabel);
32
+ if (!normalized) {
33
+ return true;
34
+ }
35
+ return UNGEOCODABLE_LEGACY_CITY_LABELS.has(normalized);
36
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cofondateurauchomage/libs",
3
- "version": "1.1.176",
3
+ "version": "1.1.177",
4
4
  "description": "",
5
5
  "main": "build/index",
6
6
  "scripts": {