@pretto/places 0.19.0 → 0.20.0
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.
- package/dist/index.js +14 -3
- package/dist/module.js +14 -3
- package/dist/municipalitySearch.d.ts +8 -0
- package/dist/municipalitySearch.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -48,7 +48,7 @@ const convertFirstLetterToUpperCase = (str) => {
|
|
|
48
48
|
};
|
|
49
49
|
const getUri = (search, departmentOnly) => {
|
|
50
50
|
const PLACES_API = 'https://geo.api.gouv.fr';
|
|
51
|
-
const QUERY_FIELDS = `boost=population&fields=departement${departmentOnly ? '' : ',codesPostaux'}`;
|
|
51
|
+
const QUERY_FIELDS = `boost=population&fields=departement${departmentOnly ? ',centre' : ',codesPostaux,centre'}`;
|
|
52
52
|
const formatedSearch = encodeURIComponent(search);
|
|
53
53
|
const uri = {
|
|
54
54
|
departments: `${PLACES_API}/departements/${formatedSearch}/communes?${QUERY_FIELDS}`,
|
|
@@ -64,14 +64,19 @@ let PREVIOUS_SEARCH = [];
|
|
|
64
64
|
let SEARCH_CACHE = [];
|
|
65
65
|
let PREVIOUS_VALUE = '';
|
|
66
66
|
const responseFormat = (places, country, search, departmentOnly) => {
|
|
67
|
+
var _a;
|
|
67
68
|
if (places.length === 0 || !places)
|
|
68
69
|
return [];
|
|
69
70
|
if (departmentOnly) {
|
|
70
71
|
return places.map(place => {
|
|
71
72
|
var _a, _b;
|
|
73
|
+
const center = !(place === null || place === void 0 ? void 0 : place.centre)
|
|
74
|
+
? null
|
|
75
|
+
: { latitude: place.centre.coordinates[1], longitude: place.centre.coordinates[0] };
|
|
72
76
|
return {
|
|
73
77
|
label: `${place.nom}${!!((_a = place.departement) === null || _a === void 0 ? void 0 : _a.code) ? ` (${place.departement.code})` : ''}`,
|
|
74
78
|
value: {
|
|
79
|
+
center,
|
|
75
80
|
city: place.nom,
|
|
76
81
|
country,
|
|
77
82
|
zipcode: ((_b = place.departement) === null || _b === void 0 ? void 0 : _b.code) || '',
|
|
@@ -80,20 +85,26 @@ const responseFormat = (places, country, search, departmentOnly) => {
|
|
|
80
85
|
});
|
|
81
86
|
}
|
|
82
87
|
if (!isNaN(parseInt(search, 10)) && search.length === 5 && places.length === 1) {
|
|
88
|
+
const center = !((_a = places[0]) === null || _a === void 0 ? void 0 : _a.centre)
|
|
89
|
+
? null
|
|
90
|
+
: { latitude: places[0].centre.coordinates[1], longitude: places[0].centre.coordinates[0] };
|
|
83
91
|
return [
|
|
84
92
|
{
|
|
85
93
|
label: `${places[0].nom} (${search})`,
|
|
86
|
-
value: { city: places[0].nom, country, zipcode: search },
|
|
94
|
+
value: { center, city: places[0].nom, country, zipcode: search },
|
|
87
95
|
},
|
|
88
96
|
];
|
|
89
97
|
}
|
|
90
98
|
const allPlaces = places.map(place => {
|
|
91
99
|
return place.codesPostaux.reduce((acc, curr) => {
|
|
100
|
+
const center = !(place === null || place === void 0 ? void 0 : place.centre)
|
|
101
|
+
? null
|
|
102
|
+
: { latitude: place.centre.coordinates[1], longitude: place.centre.coordinates[0] };
|
|
92
103
|
return [
|
|
93
104
|
...acc,
|
|
94
105
|
{
|
|
95
106
|
label: `${place.nom} (${curr})`,
|
|
96
|
-
value: { city: place.nom, country, zipcode: curr },
|
|
107
|
+
value: { center, city: place.nom, country, zipcode: curr },
|
|
97
108
|
},
|
|
98
109
|
];
|
|
99
110
|
}, []);
|
package/dist/module.js
CHANGED
|
@@ -38,7 +38,7 @@ const convertFirstLetterToUpperCase = (str) => {
|
|
|
38
38
|
};
|
|
39
39
|
const getUri = (search, departmentOnly) => {
|
|
40
40
|
const PLACES_API = 'https://geo.api.gouv.fr';
|
|
41
|
-
const QUERY_FIELDS = `boost=population&fields=departement${departmentOnly ? '' : ',codesPostaux'}`;
|
|
41
|
+
const QUERY_FIELDS = `boost=population&fields=departement${departmentOnly ? ',centre' : ',codesPostaux,centre'}`;
|
|
42
42
|
const formatedSearch = encodeURIComponent(search);
|
|
43
43
|
const uri = {
|
|
44
44
|
departments: `${PLACES_API}/departements/${formatedSearch}/communes?${QUERY_FIELDS}`,
|
|
@@ -54,14 +54,19 @@ let PREVIOUS_SEARCH = [];
|
|
|
54
54
|
let SEARCH_CACHE = [];
|
|
55
55
|
let PREVIOUS_VALUE = '';
|
|
56
56
|
const responseFormat = (places, country, search, departmentOnly) => {
|
|
57
|
+
var _a;
|
|
57
58
|
if (places.length === 0 || !places)
|
|
58
59
|
return [];
|
|
59
60
|
if (departmentOnly) {
|
|
60
61
|
return places.map(place => {
|
|
61
62
|
var _a, _b;
|
|
63
|
+
const center = !(place === null || place === void 0 ? void 0 : place.centre)
|
|
64
|
+
? null
|
|
65
|
+
: { latitude: place.centre.coordinates[1], longitude: place.centre.coordinates[0] };
|
|
62
66
|
return {
|
|
63
67
|
label: `${place.nom}${!!((_a = place.departement) === null || _a === void 0 ? void 0 : _a.code) ? ` (${place.departement.code})` : ''}`,
|
|
64
68
|
value: {
|
|
69
|
+
center,
|
|
65
70
|
city: place.nom,
|
|
66
71
|
country,
|
|
67
72
|
zipcode: ((_b = place.departement) === null || _b === void 0 ? void 0 : _b.code) || '',
|
|
@@ -70,20 +75,26 @@ const responseFormat = (places, country, search, departmentOnly) => {
|
|
|
70
75
|
});
|
|
71
76
|
}
|
|
72
77
|
if (!isNaN(parseInt(search, 10)) && search.length === 5 && places.length === 1) {
|
|
78
|
+
const center = !((_a = places[0]) === null || _a === void 0 ? void 0 : _a.centre)
|
|
79
|
+
? null
|
|
80
|
+
: { latitude: places[0].centre.coordinates[1], longitude: places[0].centre.coordinates[0] };
|
|
73
81
|
return [
|
|
74
82
|
{
|
|
75
83
|
label: `${places[0].nom} (${search})`,
|
|
76
|
-
value: { city: places[0].nom, country, zipcode: search },
|
|
84
|
+
value: { center, city: places[0].nom, country, zipcode: search },
|
|
77
85
|
},
|
|
78
86
|
];
|
|
79
87
|
}
|
|
80
88
|
const allPlaces = places.map(place => {
|
|
81
89
|
return place.codesPostaux.reduce((acc, curr) => {
|
|
90
|
+
const center = !(place === null || place === void 0 ? void 0 : place.centre)
|
|
91
|
+
? null
|
|
92
|
+
: { latitude: place.centre.coordinates[1], longitude: place.centre.coordinates[0] };
|
|
82
93
|
return [
|
|
83
94
|
...acc,
|
|
84
95
|
{
|
|
85
96
|
label: `${place.nom} (${curr})`,
|
|
86
|
-
value: { city: place.nom, country, zipcode: curr },
|
|
97
|
+
value: { center, city: place.nom, country, zipcode: curr },
|
|
87
98
|
},
|
|
88
99
|
];
|
|
89
100
|
}, []);
|
|
@@ -1,12 +1,20 @@
|
|
|
1
1
|
export interface MunicipalitySearchResult {
|
|
2
2
|
label: string;
|
|
3
3
|
value: {
|
|
4
|
+
center: {
|
|
5
|
+
latitude: number;
|
|
6
|
+
longitude: number;
|
|
7
|
+
} | null;
|
|
4
8
|
city: string;
|
|
5
9
|
country: string;
|
|
6
10
|
zipcode: string;
|
|
7
11
|
};
|
|
8
12
|
}
|
|
9
13
|
export interface MunicipalityApiResult {
|
|
14
|
+
centre?: {
|
|
15
|
+
coordinates: number[];
|
|
16
|
+
type: string;
|
|
17
|
+
} | null;
|
|
10
18
|
nom: string;
|
|
11
19
|
departement?: {
|
|
12
20
|
code: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"municipalitySearch.d.ts","sourceRoot":"","sources":["../src/municipalitySearch.ts"],"names":[],"mappings":"AAKA,MAAM,WAAW,wBAAwB;IACvC,KAAK,EAAE,MAAM,CAAA;IACb,KAAK,EAAE;QACL,IAAI,EAAE,MAAM,CAAA;QACZ,OAAO,EAAE,MAAM,CAAA;QACf,OAAO,EAAE,MAAM,CAAA;KAChB,CAAA;CACF;AAED,MAAM,WAAW,qBAAqB;IACpC,GAAG,EAAE,MAAM,CAAA;IACX,WAAW,CAAC,EAAE;QACZ,IAAI,EAAE,MAAM,CAAA;QACZ,GAAG,EAAE,MAAM,CAAA;KACZ,CAAA;IACD,YAAY,EAAE,MAAM,E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