@cofondateurauchomage/libs 1.1.177 → 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,6 @@
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;
6
4
  const legacyCityLabel_1 = require("./legacyCityLabel");
7
5
  const parse_1 = require("./parse");
8
6
  const GEO_API = "https://geo.api.gouv.fr";
@@ -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.177",
3
+ "version": "1.1.178",
4
4
  "description": "",
5
5
  "main": "build/index",
6
6
  "scripts": {