@cofondateurauchomage/libs 1.1.176 → 1.1.178

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.
@@ -1,6 +1,3 @@
1
1
  import type { ILocationSuggestion } from "./types";
2
- export declare function getRegionCodeForDepartment(departmentCode: string): Promise<string | undefined>;
3
2
  /** Search regions, departments (geo.api) and cities/postcodes (API Adresse). */
4
3
  export declare function searchLocationSuggestions(query: string): Promise<ILocationSuggestion[]>;
5
- /** Geocode a legacy free-text city label (migration script). */
6
- export declare function geocodeCityLabel(cityLabel: string): Promise<ILocationSuggestion | null>;
@@ -1,8 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getRegionCodeForDepartment = getRegionCodeForDepartment;
4
3
  exports.searchLocationSuggestions = searchLocationSuggestions;
5
- exports.geocodeCityLabel = geocodeCityLabel;
4
+ const legacyCityLabel_1 = require("./legacyCityLabel");
6
5
  const parse_1 = require("./parse");
7
6
  const GEO_API = "https://geo.api.gouv.fr";
8
7
  const ADRESSE_API = "https://api-adresse.data.gouv.fr";
@@ -139,6 +138,9 @@ async function searchLocationSuggestions(query) {
139
138
  }
140
139
  /** Geocode a legacy free-text city label (migration script). */
141
140
  async function geocodeCityLabel(cityLabel) {
141
+ if ((0, legacyCityLabel_1.isUngeocodableLegacyCityLabel)(cityLabel)) {
142
+ return null;
143
+ }
142
144
  const q = `${cityLabel.trim()}, France`;
143
145
  const features = await fetchAdresseFeatures(q);
144
146
  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
+ }
@@ -36,5 +36,6 @@ export declare function parseAdresseContext(context?: string): {
36
36
  };
37
37
  export declare function parseAdresseFeature(feature: AdresseFeature, regionCode: string): ILocationSuggestion | null;
38
38
  export declare function suggestionToProfileLocation(suggestion: ILocationSuggestion): IProfileLocation;
39
- export declare function normalizeProfileLocation(location: IProfileLocation): IProfileLocation;
39
+ /** Inverse of suggestionToProfileLocation — e.g. form controls that store IProfileLocation. */
40
+ export declare function profileLocationToSuggestion(location: IProfileLocation): ILocationSuggestion;
40
41
  export type { AdresseFeature, GeoApiDepartment, GeoApiRegion };
@@ -5,7 +5,7 @@ exports.parseGeoApiDepartment = parseGeoApiDepartment;
5
5
  exports.parseAdresseContext = parseAdresseContext;
6
6
  exports.parseAdresseFeature = parseAdresseFeature;
7
7
  exports.suggestionToProfileLocation = suggestionToProfileLocation;
8
- exports.normalizeProfileLocation = normalizeProfileLocation;
8
+ exports.profileLocationToSuggestion = profileLocationToSuggestion;
9
9
  const coordsFromCentre = (centre) => {
10
10
  const [lng, lat] = centre?.coordinates ?? [0, 0];
11
11
  return { lat, lng };
@@ -82,13 +82,19 @@ function suggestionToProfileLocation(suggestion) {
82
82
  }
83
83
  return base;
84
84
  }
85
- function normalizeProfileLocation(location) {
85
+ /** Inverse of suggestionToProfileLocation — e.g. form controls that store IProfileLocation. */
86
+ function profileLocationToSuggestion(location) {
87
+ const label = location.postcode && !/\(\d{5}\)$/.test(location.label.trim())
88
+ ? `${location.label} (${location.postcode})`
89
+ : location.label;
86
90
  return {
87
- ...location,
88
- label: location.label.trim(),
89
- regionCode: location.regionCode.trim(),
90
- departmentCode: location.departmentCode.trim(),
91
- cityCode: location.cityCode?.trim() || undefined,
92
- postcode: location.postcode?.trim() || undefined,
91
+ type: "city",
92
+ label,
93
+ regionCode: location.regionCode,
94
+ departmentCode: location.departmentCode || undefined,
95
+ cityCode: location.cityCode,
96
+ lat: location.lat,
97
+ lng: location.lng,
98
+ postcode: location.postcode,
93
99
  };
94
100
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cofondateurauchomage/libs",
3
- "version": "1.1.176",
3
+ "version": "1.1.178",
4
4
  "description": "",
5
5
  "main": "build/index",
6
6
  "scripts": {