@pretto/places 0.19.0 → 0.21.0
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +16 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +73 -23
- package/dist/module.js +73 -24
- package/dist/municipalitySearch.d.ts +8 -0
- package/dist/municipalitySearch.d.ts.map +1 -1
- package/dist/reverseGeolocSearch.d.ts +15 -0
- package/dist/reverseGeolocSearch.d.ts.map +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
@@ -143,6 +143,22 @@ const results = await geolocSearch.get('75010')
|
|
143
143
|
// }]
|
144
144
|
```
|
145
145
|
|
146
|
+
For reverse geolocalisation
|
147
|
+
|
148
|
+
```typescript
|
149
|
+
import { reverseGeolocSearch } from '@pretto/places'
|
150
|
+
|
151
|
+
const results = await reverseGeolocSearch.get({ latitude: 48.8932244326416, longitude: 2.289395548568507 })
|
152
|
+
// result object format :
|
153
|
+
// [{
|
154
|
+
// center: {latitude: 48.8946, longitude: 2.2874}
|
155
|
+
// city: 'Levallois-Perret'
|
156
|
+
// code: '92044',
|
157
|
+
// coordinates: [2.2874, 48.8946],
|
158
|
+
// zipcode: 92300,
|
159
|
+
// }]
|
160
|
+
```
|
161
|
+
|
146
162
|
### Debounce
|
147
163
|
|
148
164
|
`addressSearch`, `municipalitySearch` and `geolocSearch` have defaut debounce value fixed to **300ms**\
|
package/dist/index.d.ts
CHANGED
@@ -2,4 +2,5 @@ export * as municipalitySearch from './municipalitySearch';
|
|
2
2
|
export * as addressSearch from './addressSearch';
|
3
3
|
export * as countrySearch from './countrySearch';
|
4
4
|
export * as geolocSearch from './geolocSearch';
|
5
|
+
export * as reverseGeolocSearch from './reverseGeolocSearch';
|
5
6
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,kBAAkB,MAAM,sBAAsB,CAAA;AAC1D,OAAO,KAAK,aAAa,MAAM,iBAAiB,CAAA;AAChD,OAAO,KAAK,aAAa,MAAM,iBAAiB,CAAA;AAChD,OAAO,KAAK,YAAY,MAAM,gBAAgB,CAAA"}
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,kBAAkB,MAAM,sBAAsB,CAAA;AAC1D,OAAO,KAAK,aAAa,MAAM,iBAAiB,CAAA;AAChD,OAAO,KAAK,aAAa,MAAM,iBAAiB,CAAA;AAChD,OAAO,KAAK,YAAY,MAAM,gBAAgB,CAAA;AAC9C,OAAO,KAAK,mBAAmB,MAAM,uBAAuB,CAAA"}
|
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,27 +85,33 @@ 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
|
}, []);
|
100
111
|
});
|
101
112
|
return flat__default["default"](allPlaces);
|
102
113
|
};
|
103
|
-
const getData$
|
114
|
+
const getData$3 = (search, options) => __awaiter(void 0, void 0, void 0, function* () {
|
104
115
|
const { country = 'fr', limit = 5, departmentOnly = false } = options || {};
|
105
116
|
const isNumber = !isNaN(parseInt(search, 10));
|
106
117
|
if (!search || (isNumber && search.length < 2))
|
@@ -133,23 +144,23 @@ const getData$2 = (search, options) => __awaiter(void 0, void 0, void 0, functio
|
|
133
144
|
return 'An error occurred.';
|
134
145
|
}
|
135
146
|
});
|
136
|
-
let getDelayedData$
|
137
|
-
const get$
|
138
|
-
clearTimeout(getDelayedData$
|
147
|
+
let getDelayedData$3;
|
148
|
+
const get$4 = (search, options, debounceValue = 300) => {
|
149
|
+
clearTimeout(getDelayedData$3);
|
139
150
|
return new Promise((resolve, reject) => {
|
140
|
-
getDelayedData$
|
141
|
-
resolve(getData$
|
151
|
+
getDelayedData$3 = setTimeout(() => {
|
152
|
+
resolve(getData$3(search, options));
|
142
153
|
}, debounceValue);
|
143
154
|
});
|
144
155
|
};
|
145
156
|
|
146
157
|
var municipalitySearch = /*#__PURE__*/Object.freeze({
|
147
158
|
__proto__: null,
|
148
|
-
getData: getData$
|
149
|
-
get: get$
|
159
|
+
getData: getData$3,
|
160
|
+
get: get$4
|
150
161
|
});
|
151
162
|
|
152
|
-
const getData$
|
163
|
+
const getData$2 = (search, options) => __awaiter(void 0, void 0, void 0, function* () {
|
153
164
|
if (!search || search.length < 2)
|
154
165
|
return [];
|
155
166
|
try {
|
@@ -182,22 +193,22 @@ const getData$1 = (search, options) => __awaiter(void 0, void 0, void 0, functio
|
|
182
193
|
return 'An error occurred.';
|
183
194
|
}
|
184
195
|
});
|
185
|
-
let getDelayedData$
|
186
|
-
const get$
|
187
|
-
clearTimeout(getDelayedData$
|
196
|
+
let getDelayedData$2;
|
197
|
+
const get$3 = (search, options, debounceValue = 300) => {
|
198
|
+
clearTimeout(getDelayedData$2);
|
188
199
|
return new Promise((resolve, reject) => {
|
189
|
-
getDelayedData$
|
190
|
-
resolve(getData$
|
200
|
+
getDelayedData$2 = setTimeout(() => {
|
201
|
+
resolve(getData$2(search, options));
|
191
202
|
}, debounceValue);
|
192
203
|
});
|
193
204
|
};
|
194
205
|
|
195
206
|
var addressSearch = /*#__PURE__*/Object.freeze({
|
196
207
|
__proto__: null,
|
197
|
-
get: get$
|
208
|
+
get: get$3
|
198
209
|
});
|
199
210
|
|
200
|
-
const get$
|
211
|
+
const get$2 = (instance, search, options) => __awaiter(void 0, void 0, void 0, function* () {
|
201
212
|
if (!search)
|
202
213
|
return [];
|
203
214
|
const { limit = 5 } = options || {};
|
@@ -219,7 +230,7 @@ const init = (appId, apiKey, options) => {
|
|
219
230
|
return {
|
220
231
|
get(search, options) {
|
221
232
|
return __awaiter(this, void 0, void 0, function* () {
|
222
|
-
return yield get$
|
233
|
+
return yield get$2(ALGOLIA_COUNTRIES_API, search, options);
|
223
234
|
});
|
224
235
|
},
|
225
236
|
};
|
@@ -238,7 +249,7 @@ var countrySearch = /*#__PURE__*/Object.freeze({
|
|
238
249
|
init: init
|
239
250
|
});
|
240
251
|
|
241
|
-
const formatData = (results) => results.map(result => ({
|
252
|
+
const formatData$1 = (results) => results.map(result => ({
|
242
253
|
city: result.nom,
|
243
254
|
code: result.code,
|
244
255
|
coordinates: result.centre.coordinates,
|
@@ -246,7 +257,7 @@ const formatData = (results) => results.map(result => ({
|
|
246
257
|
// All french zipcode are only numbers, even particular cases like Corse (2A, 2B > 20), Finistère (29N, 29S > 29x), etc..
|
247
258
|
// For more information: https://fr.wikipedia.org/wiki/Code_postal_en_France
|
248
259
|
// Kept as string for consistency with geo.api.gouv.fr
|
249
|
-
const getData = (search) => __awaiter(void 0, void 0, void 0, function* () {
|
260
|
+
const getData$1 = (search) => __awaiter(void 0, void 0, void 0, function* () {
|
250
261
|
if (!search || !/(\d){5}/.test(search))
|
251
262
|
return [];
|
252
263
|
try {
|
@@ -255,6 +266,44 @@ const getData = (search) => __awaiter(void 0, void 0, void 0, function* () {
|
|
255
266
|
if (!response.ok)
|
256
267
|
return Promise.reject(response);
|
257
268
|
const results = yield response.json();
|
269
|
+
return formatData$1(results);
|
270
|
+
}
|
271
|
+
catch (error) {
|
272
|
+
if (typeof error === 'string')
|
273
|
+
throw new Error(error);
|
274
|
+
throw new Error(error instanceof Error && error.message ? error.message : 'An error occurred.');
|
275
|
+
}
|
276
|
+
});
|
277
|
+
let getDelayedData$1;
|
278
|
+
const get$1 = (search, debounceValue = 300) => {
|
279
|
+
clearTimeout(getDelayedData$1);
|
280
|
+
return new Promise((resolve, reject) => {
|
281
|
+
getDelayedData$1 = setTimeout(() => {
|
282
|
+
resolve(getData$1(search));
|
283
|
+
}, debounceValue);
|
284
|
+
});
|
285
|
+
};
|
286
|
+
|
287
|
+
var geolocSearch = /*#__PURE__*/Object.freeze({
|
288
|
+
__proto__: null,
|
289
|
+
get: get$1
|
290
|
+
});
|
291
|
+
|
292
|
+
const formatData = (results) => {
|
293
|
+
return results.map(result => ({
|
294
|
+
center: { latitude: result.centre.coordinates[1], longitude: result.centre.coordinates[0] },
|
295
|
+
city: result.nom,
|
296
|
+
code: result.code,
|
297
|
+
coordinates: result.centre.coordinates,
|
298
|
+
zipcode: result.codesPostaux[0],
|
299
|
+
}));
|
300
|
+
};
|
301
|
+
const getData = (search) => __awaiter(void 0, void 0, void 0, function* () {
|
302
|
+
try {
|
303
|
+
const response = yield fetch(`https://geo.api.gouv.fr/communes?lat=${search.latitude}&lon=${search.longitude}&fields=departement,codesPostaux,centre`);
|
304
|
+
if (!response.ok)
|
305
|
+
return Promise.reject(response);
|
306
|
+
const results = yield response.json();
|
258
307
|
return formatData(results);
|
259
308
|
}
|
260
309
|
catch (error) {
|
@@ -273,7 +322,7 @@ const get = (search, debounceValue = 300) => {
|
|
273
322
|
});
|
274
323
|
};
|
275
324
|
|
276
|
-
var
|
325
|
+
var reverseGeolocSearch = /*#__PURE__*/Object.freeze({
|
277
326
|
__proto__: null,
|
278
327
|
get: get
|
279
328
|
});
|
@@ -282,3 +331,4 @@ exports.addressSearch = addressSearch;
|
|
282
331
|
exports.countrySearch = countrySearch;
|
283
332
|
exports.geolocSearch = geolocSearch;
|
284
333
|
exports.municipalitySearch = municipalitySearch;
|
334
|
+
exports.reverseGeolocSearch = reverseGeolocSearch;
|
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,27 +75,33 @@ 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
|
}, []);
|
90
101
|
});
|
91
102
|
return flat(allPlaces);
|
92
103
|
};
|
93
|
-
const getData$
|
104
|
+
const getData$3 = (search, options) => __awaiter(void 0, void 0, void 0, function* () {
|
94
105
|
const { country = 'fr', limit = 5, departmentOnly = false } = options || {};
|
95
106
|
const isNumber = !isNaN(parseInt(search, 10));
|
96
107
|
if (!search || (isNumber && search.length < 2))
|
@@ -123,23 +134,23 @@ const getData$2 = (search, options) => __awaiter(void 0, void 0, void 0, functio
|
|
123
134
|
return 'An error occurred.';
|
124
135
|
}
|
125
136
|
});
|
126
|
-
let getDelayedData$
|
127
|
-
const get$
|
128
|
-
clearTimeout(getDelayedData$
|
137
|
+
let getDelayedData$3;
|
138
|
+
const get$4 = (search, options, debounceValue = 300) => {
|
139
|
+
clearTimeout(getDelayedData$3);
|
129
140
|
return new Promise((resolve, reject) => {
|
130
|
-
getDelayedData$
|
131
|
-
resolve(getData$
|
141
|
+
getDelayedData$3 = setTimeout(() => {
|
142
|
+
resolve(getData$3(search, options));
|
132
143
|
}, debounceValue);
|
133
144
|
});
|
134
145
|
};
|
135
146
|
|
136
147
|
var municipalitySearch = /*#__PURE__*/Object.freeze({
|
137
148
|
__proto__: null,
|
138
|
-
getData: getData$
|
139
|
-
get: get$
|
149
|
+
getData: getData$3,
|
150
|
+
get: get$4
|
140
151
|
});
|
141
152
|
|
142
|
-
const getData$
|
153
|
+
const getData$2 = (search, options) => __awaiter(void 0, void 0, void 0, function* () {
|
143
154
|
if (!search || search.length < 2)
|
144
155
|
return [];
|
145
156
|
try {
|
@@ -172,22 +183,22 @@ const getData$1 = (search, options) => __awaiter(void 0, void 0, void 0, functio
|
|
172
183
|
return 'An error occurred.';
|
173
184
|
}
|
174
185
|
});
|
175
|
-
let getDelayedData$
|
176
|
-
const get$
|
177
|
-
clearTimeout(getDelayedData$
|
186
|
+
let getDelayedData$2;
|
187
|
+
const get$3 = (search, options, debounceValue = 300) => {
|
188
|
+
clearTimeout(getDelayedData$2);
|
178
189
|
return new Promise((resolve, reject) => {
|
179
|
-
getDelayedData$
|
180
|
-
resolve(getData$
|
190
|
+
getDelayedData$2 = setTimeout(() => {
|
191
|
+
resolve(getData$2(search, options));
|
181
192
|
}, debounceValue);
|
182
193
|
});
|
183
194
|
};
|
184
195
|
|
185
196
|
var addressSearch = /*#__PURE__*/Object.freeze({
|
186
197
|
__proto__: null,
|
187
|
-
get: get$
|
198
|
+
get: get$3
|
188
199
|
});
|
189
200
|
|
190
|
-
const get$
|
201
|
+
const get$2 = (instance, search, options) => __awaiter(void 0, void 0, void 0, function* () {
|
191
202
|
if (!search)
|
192
203
|
return [];
|
193
204
|
const { limit = 5 } = options || {};
|
@@ -209,7 +220,7 @@ const init = (appId, apiKey, options) => {
|
|
209
220
|
return {
|
210
221
|
get(search, options) {
|
211
222
|
return __awaiter(this, void 0, void 0, function* () {
|
212
|
-
return yield get$
|
223
|
+
return yield get$2(ALGOLIA_COUNTRIES_API, search, options);
|
213
224
|
});
|
214
225
|
},
|
215
226
|
};
|
@@ -228,7 +239,7 @@ var countrySearch = /*#__PURE__*/Object.freeze({
|
|
228
239
|
init: init
|
229
240
|
});
|
230
241
|
|
231
|
-
const formatData = (results) => results.map(result => ({
|
242
|
+
const formatData$1 = (results) => results.map(result => ({
|
232
243
|
city: result.nom,
|
233
244
|
code: result.code,
|
234
245
|
coordinates: result.centre.coordinates,
|
@@ -236,7 +247,7 @@ const formatData = (results) => results.map(result => ({
|
|
236
247
|
// All french zipcode are only numbers, even particular cases like Corse (2A, 2B > 20), Finistère (29N, 29S > 29x), etc..
|
237
248
|
// For more information: https://fr.wikipedia.org/wiki/Code_postal_en_France
|
238
249
|
// Kept as string for consistency with geo.api.gouv.fr
|
239
|
-
const getData = (search) => __awaiter(void 0, void 0, void 0, function* () {
|
250
|
+
const getData$1 = (search) => __awaiter(void 0, void 0, void 0, function* () {
|
240
251
|
if (!search || !/(\d){5}/.test(search))
|
241
252
|
return [];
|
242
253
|
try {
|
@@ -245,6 +256,44 @@ const getData = (search) => __awaiter(void 0, void 0, void 0, function* () {
|
|
245
256
|
if (!response.ok)
|
246
257
|
return Promise.reject(response);
|
247
258
|
const results = yield response.json();
|
259
|
+
return formatData$1(results);
|
260
|
+
}
|
261
|
+
catch (error) {
|
262
|
+
if (typeof error === 'string')
|
263
|
+
throw new Error(error);
|
264
|
+
throw new Error(error instanceof Error && error.message ? error.message : 'An error occurred.');
|
265
|
+
}
|
266
|
+
});
|
267
|
+
let getDelayedData$1;
|
268
|
+
const get$1 = (search, debounceValue = 300) => {
|
269
|
+
clearTimeout(getDelayedData$1);
|
270
|
+
return new Promise((resolve, reject) => {
|
271
|
+
getDelayedData$1 = setTimeout(() => {
|
272
|
+
resolve(getData$1(search));
|
273
|
+
}, debounceValue);
|
274
|
+
});
|
275
|
+
};
|
276
|
+
|
277
|
+
var geolocSearch = /*#__PURE__*/Object.freeze({
|
278
|
+
__proto__: null,
|
279
|
+
get: get$1
|
280
|
+
});
|
281
|
+
|
282
|
+
const formatData = (results) => {
|
283
|
+
return results.map(result => ({
|
284
|
+
center: { latitude: result.centre.coordinates[1], longitude: result.centre.coordinates[0] },
|
285
|
+
city: result.nom,
|
286
|
+
code: result.code,
|
287
|
+
coordinates: result.centre.coordinates,
|
288
|
+
zipcode: result.codesPostaux[0],
|
289
|
+
}));
|
290
|
+
};
|
291
|
+
const getData = (search) => __awaiter(void 0, void 0, void 0, function* () {
|
292
|
+
try {
|
293
|
+
const response = yield fetch(`https://geo.api.gouv.fr/communes?lat=${search.latitude}&lon=${search.longitude}&fields=departement,codesPostaux,centre`);
|
294
|
+
if (!response.ok)
|
295
|
+
return Promise.reject(response);
|
296
|
+
const results = yield response.json();
|
248
297
|
return formatData(results);
|
249
298
|
}
|
250
299
|
catch (error) {
|
@@ -263,9 +312,9 @@ const get = (search, debounceValue = 300) => {
|
|
263
312
|
});
|
264
313
|
};
|
265
314
|
|
266
|
-
var
|
315
|
+
var reverseGeolocSearch = /*#__PURE__*/Object.freeze({
|
267
316
|
__proto__: null,
|
268
317
|
get: get
|
269
318
|
});
|
270
319
|
|
271
|
-
export { addressSearch, countrySearch, geolocSearch, municipalitySearch };
|
320
|
+
export { addressSearch, countrySearch, geolocSearch, municipalitySearch, reverseGeolocSearch };
|
@@ -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,EAAE,CAAA;CACvB;AAED,UAAU,OAAO;IACf,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,cAAc,CAAC,EAAE,OAAO,CAAA;CACzB;AAED,aAAK,2BAA2B,GAAG,CACjC,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE,OAAO,EACjB,aAAa,CAAC,EAAE,MAAM,KACnB,OAAO,CAAC,wBAAwB,EAAE,GAAG,MAAM,CAAC,CAAA;AAEjD,aAAK,kBAAkB,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,KAAK,OAAO,CAAC,wBAAwB,EAAE,GAAG,MAAM,CAAC,CAAA;
|
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,MAAM,EAAE;YAAE,QAAQ,EAAE,MAAM,CAAC;YAAC,SAAS,EAAE,MAAM,CAAA;SAAE,GAAG,IAAI,CAAA;QACtD,IAAI,EAAE,MAAM,CAAA;QACZ,OAAO,EAAE,MAAM,CAAA;QACf,OAAO,EAAE,MAAM,CAAA;KAChB,CAAA;CACF;AAED,MAAM,WAAW,qBAAqB;IACpC,MAAM,CAAC,EAAE;QAAE,WAAW,EAAE,MAAM,EAAE,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAA;IACvD,GAAG,EAAE,MAAM,CAAA;IACX,WAAW,CAAC,EAAE;QACZ,IAAI,EAAE,MAAM,CAAA;QACZ,GAAG,EAAE,MAAM,CAAA;KACZ,CAAA;IACD,YAAY,EAAE,MAAM,EAAE,CAAA;CACvB;AAED,UAAU,OAAO;IACf,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,cAAc,CAAC,EAAE,OAAO,CAAA;CACzB;AAED,aAAK,2BAA2B,GAAG,CACjC,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE,OAAO,EACjB,aAAa,CAAC,EAAE,MAAM,KACnB,OAAO,CAAC,wBAAwB,EAAE,GAAG,MAAM,CAAC,CAAA;AAEjD,aAAK,kBAAkB,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,KAAK,OAAO,CAAC,wBAAwB,EAAE,GAAG,MAAM,CAAC,CAAA;AAgE7G,eAAO,MAAM,OAAO,EAAE,kBAoCrB,CAAA;AAID,eAAO,MAAM,GAAG,EAAE,2BAQjB,CAAA"}
|
@@ -0,0 +1,15 @@
|
|
1
|
+
export declare type ReverseGeolocSearchResult = {
|
2
|
+
center: {
|
3
|
+
latitude: number;
|
4
|
+
longitude: number;
|
5
|
+
};
|
6
|
+
city: string;
|
7
|
+
code: string;
|
8
|
+
coordinates: [number, number];
|
9
|
+
zipcode: string;
|
10
|
+
};
|
11
|
+
export declare const get: (search: {
|
12
|
+
latitude: number;
|
13
|
+
longitude: number;
|
14
|
+
}, debounceValue?: number) => Promise<ReverseGeolocSearchResult[]>;
|
15
|
+
//# sourceMappingURL=reverseGeolocSearch.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"reverseGeolocSearch.d.ts","sourceRoot":"","sources":["../src/reverseGeolocSearch.ts"],"names":[],"mappings":"AAAA,oBAAY,yBAAyB,GAAG;IACtC,MAAM,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAE,CAAA;IAC/C,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,CAAA;IACZ,WAAW,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAC7B,OAAO,EAAE,MAAM,CAAA;CAChB,CAAA;AAyCD,eAAO,MAAM,GAAG,WACN;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,kBAChC,MAAM,KACpB,QAAQ,yBAAyB,EAAE,CAQrC,CAAA"}
|