@pretto/places 0.21.0 → 0.23.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 +35 -13
- package/dist/module.js +35 -13
- package/dist/municipalitySearch.d.ts +7 -0
- package/dist/municipalitySearch.d.ts.map +1 -1
- package/dist/reverseGeolocSearch.d.ts +7 -1
- package/dist/reverseGeolocSearch.d.ts.map +1 -1
- package/dist/utils.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 ? ',centre' : ',codesPostaux,centre'}`;
|
|
51
|
+
const QUERY_FIELDS = `boost=population&fields=departement${departmentOnly ? ',centre,contour' : ',codesPostaux,centre,contour'}`;
|
|
52
52
|
const formatedSearch = encodeURIComponent(search);
|
|
53
53
|
const uri = {
|
|
54
54
|
departments: `${PLACES_API}/departements/${formatedSearch}/communes?${QUERY_FIELDS}`,
|
|
@@ -79,6 +79,7 @@ const responseFormat = (places, country, search, departmentOnly) => {
|
|
|
79
79
|
center,
|
|
80
80
|
city: place.nom,
|
|
81
81
|
country,
|
|
82
|
+
outline: place.contour.coordinates[0].map(([longitude, latitude]) => ({ longitude, latitude })),
|
|
82
83
|
zipcode: ((_b = place.departement) === null || _b === void 0 ? void 0 : _b.code) || '',
|
|
83
84
|
},
|
|
84
85
|
};
|
|
@@ -91,7 +92,13 @@ const responseFormat = (places, country, search, departmentOnly) => {
|
|
|
91
92
|
return [
|
|
92
93
|
{
|
|
93
94
|
label: `${places[0].nom} (${search})`,
|
|
94
|
-
value: {
|
|
95
|
+
value: {
|
|
96
|
+
center,
|
|
97
|
+
city: places[0].nom,
|
|
98
|
+
country,
|
|
99
|
+
outline: places[0].contour.coordinates[0].map(([longitude, latitude]) => ({ longitude, latitude })),
|
|
100
|
+
zipcode: search,
|
|
101
|
+
},
|
|
95
102
|
},
|
|
96
103
|
];
|
|
97
104
|
}
|
|
@@ -104,7 +111,13 @@ const responseFormat = (places, country, search, departmentOnly) => {
|
|
|
104
111
|
...acc,
|
|
105
112
|
{
|
|
106
113
|
label: `${place.nom} (${curr})`,
|
|
107
|
-
value: {
|
|
114
|
+
value: {
|
|
115
|
+
center,
|
|
116
|
+
city: place.nom,
|
|
117
|
+
country,
|
|
118
|
+
outline: place.contour.coordinates[0].map(([longitude, latitude]) => ({ longitude, latitude })),
|
|
119
|
+
zipcode: curr,
|
|
120
|
+
},
|
|
108
121
|
},
|
|
109
122
|
];
|
|
110
123
|
}, []);
|
|
@@ -289,22 +302,31 @@ var geolocSearch = /*#__PURE__*/Object.freeze({
|
|
|
289
302
|
get: get$1
|
|
290
303
|
});
|
|
291
304
|
|
|
292
|
-
const formatData = (
|
|
293
|
-
|
|
305
|
+
const formatData = (geoResults, addressResults) => {
|
|
306
|
+
const district = addressResults.features.length > 0 ? addressResults.features[0].properties.district : null;
|
|
307
|
+
const postcode = addressResults.features.length > 0 ? addressResults.features[0].properties.postcode : null;
|
|
308
|
+
return geoResults.map(result => ({
|
|
294
309
|
center: { latitude: result.centre.coordinates[1], longitude: result.centre.coordinates[0] },
|
|
295
310
|
city: result.nom,
|
|
296
311
|
code: result.code,
|
|
297
312
|
coordinates: result.centre.coordinates,
|
|
298
313
|
zipcode: result.codesPostaux[0],
|
|
314
|
+
outline: result.contour.coordinates[0].map(([longitude, latitude]) => ({ longitude, latitude })),
|
|
315
|
+
district,
|
|
316
|
+
postcode,
|
|
299
317
|
}));
|
|
300
318
|
};
|
|
301
|
-
const getData = (search) => __awaiter(void 0, void 0, void 0, function* () {
|
|
319
|
+
const getData = (search, signal) => __awaiter(void 0, void 0, void 0, function* () {
|
|
302
320
|
try {
|
|
303
|
-
const
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
321
|
+
const [geoResponse, addressResponse] = yield Promise.all([
|
|
322
|
+
fetch(`https://geo.api.gouv.fr/communes?lat=${search.latitude}&lon=${search.longitude}&fields=departement,codesPostaux,centre,contour`, { signal }),
|
|
323
|
+
fetch(`https://api-adresse.data.gouv.fr/reverse/?lat=${search.latitude}&lon=${search.longitude}&limit=1&&autocomplete=0`, { signal }),
|
|
324
|
+
]);
|
|
325
|
+
if (!geoResponse.ok)
|
|
326
|
+
return Promise.reject(geoResponse);
|
|
327
|
+
const geoResults = yield geoResponse.json();
|
|
328
|
+
const addressResults = yield addressResponse.json();
|
|
329
|
+
return formatData(geoResults, addressResults);
|
|
308
330
|
}
|
|
309
331
|
catch (error) {
|
|
310
332
|
if (typeof error === 'string')
|
|
@@ -313,11 +335,11 @@ const getData = (search) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
313
335
|
}
|
|
314
336
|
});
|
|
315
337
|
let getDelayedData;
|
|
316
|
-
const get = (search, debounceValue = 300) => {
|
|
338
|
+
const get = (search, debounceValue = 300, signal) => {
|
|
317
339
|
clearTimeout(getDelayedData);
|
|
318
340
|
return new Promise((resolve, reject) => {
|
|
319
341
|
getDelayedData = setTimeout(() => {
|
|
320
|
-
resolve(getData(search));
|
|
342
|
+
resolve(getData(search, signal));
|
|
321
343
|
}, debounceValue);
|
|
322
344
|
});
|
|
323
345
|
};
|
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 ? ',centre' : ',codesPostaux,centre'}`;
|
|
41
|
+
const QUERY_FIELDS = `boost=population&fields=departement${departmentOnly ? ',centre,contour' : ',codesPostaux,centre,contour'}`;
|
|
42
42
|
const formatedSearch = encodeURIComponent(search);
|
|
43
43
|
const uri = {
|
|
44
44
|
departments: `${PLACES_API}/departements/${formatedSearch}/communes?${QUERY_FIELDS}`,
|
|
@@ -69,6 +69,7 @@ const responseFormat = (places, country, search, departmentOnly) => {
|
|
|
69
69
|
center,
|
|
70
70
|
city: place.nom,
|
|
71
71
|
country,
|
|
72
|
+
outline: place.contour.coordinates[0].map(([longitude, latitude]) => ({ longitude, latitude })),
|
|
72
73
|
zipcode: ((_b = place.departement) === null || _b === void 0 ? void 0 : _b.code) || '',
|
|
73
74
|
},
|
|
74
75
|
};
|
|
@@ -81,7 +82,13 @@ const responseFormat = (places, country, search, departmentOnly) => {
|
|
|
81
82
|
return [
|
|
82
83
|
{
|
|
83
84
|
label: `${places[0].nom} (${search})`,
|
|
84
|
-
value: {
|
|
85
|
+
value: {
|
|
86
|
+
center,
|
|
87
|
+
city: places[0].nom,
|
|
88
|
+
country,
|
|
89
|
+
outline: places[0].contour.coordinates[0].map(([longitude, latitude]) => ({ longitude, latitude })),
|
|
90
|
+
zipcode: search,
|
|
91
|
+
},
|
|
85
92
|
},
|
|
86
93
|
];
|
|
87
94
|
}
|
|
@@ -94,7 +101,13 @@ const responseFormat = (places, country, search, departmentOnly) => {
|
|
|
94
101
|
...acc,
|
|
95
102
|
{
|
|
96
103
|
label: `${place.nom} (${curr})`,
|
|
97
|
-
value: {
|
|
104
|
+
value: {
|
|
105
|
+
center,
|
|
106
|
+
city: place.nom,
|
|
107
|
+
country,
|
|
108
|
+
outline: place.contour.coordinates[0].map(([longitude, latitude]) => ({ longitude, latitude })),
|
|
109
|
+
zipcode: curr,
|
|
110
|
+
},
|
|
98
111
|
},
|
|
99
112
|
];
|
|
100
113
|
}, []);
|
|
@@ -279,22 +292,31 @@ var geolocSearch = /*#__PURE__*/Object.freeze({
|
|
|
279
292
|
get: get$1
|
|
280
293
|
});
|
|
281
294
|
|
|
282
|
-
const formatData = (
|
|
283
|
-
|
|
295
|
+
const formatData = (geoResults, addressResults) => {
|
|
296
|
+
const district = addressResults.features.length > 0 ? addressResults.features[0].properties.district : null;
|
|
297
|
+
const postcode = addressResults.features.length > 0 ? addressResults.features[0].properties.postcode : null;
|
|
298
|
+
return geoResults.map(result => ({
|
|
284
299
|
center: { latitude: result.centre.coordinates[1], longitude: result.centre.coordinates[0] },
|
|
285
300
|
city: result.nom,
|
|
286
301
|
code: result.code,
|
|
287
302
|
coordinates: result.centre.coordinates,
|
|
288
303
|
zipcode: result.codesPostaux[0],
|
|
304
|
+
outline: result.contour.coordinates[0].map(([longitude, latitude]) => ({ longitude, latitude })),
|
|
305
|
+
district,
|
|
306
|
+
postcode,
|
|
289
307
|
}));
|
|
290
308
|
};
|
|
291
|
-
const getData = (search) => __awaiter(void 0, void 0, void 0, function* () {
|
|
309
|
+
const getData = (search, signal) => __awaiter(void 0, void 0, void 0, function* () {
|
|
292
310
|
try {
|
|
293
|
-
const
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
311
|
+
const [geoResponse, addressResponse] = yield Promise.all([
|
|
312
|
+
fetch(`https://geo.api.gouv.fr/communes?lat=${search.latitude}&lon=${search.longitude}&fields=departement,codesPostaux,centre,contour`, { signal }),
|
|
313
|
+
fetch(`https://api-adresse.data.gouv.fr/reverse/?lat=${search.latitude}&lon=${search.longitude}&limit=1&&autocomplete=0`, { signal }),
|
|
314
|
+
]);
|
|
315
|
+
if (!geoResponse.ok)
|
|
316
|
+
return Promise.reject(geoResponse);
|
|
317
|
+
const geoResults = yield geoResponse.json();
|
|
318
|
+
const addressResults = yield addressResponse.json();
|
|
319
|
+
return formatData(geoResults, addressResults);
|
|
298
320
|
}
|
|
299
321
|
catch (error) {
|
|
300
322
|
if (typeof error === 'string')
|
|
@@ -303,11 +325,11 @@ const getData = (search) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
303
325
|
}
|
|
304
326
|
});
|
|
305
327
|
let getDelayedData;
|
|
306
|
-
const get = (search, debounceValue = 300) => {
|
|
328
|
+
const get = (search, debounceValue = 300, signal) => {
|
|
307
329
|
clearTimeout(getDelayedData);
|
|
308
330
|
return new Promise((resolve, reject) => {
|
|
309
331
|
getDelayedData = setTimeout(() => {
|
|
310
|
-
resolve(getData(search));
|
|
332
|
+
resolve(getData(search, signal));
|
|
311
333
|
}, debounceValue);
|
|
312
334
|
});
|
|
313
335
|
};
|
|
@@ -7,6 +7,10 @@ export interface MunicipalitySearchResult {
|
|
|
7
7
|
} | null;
|
|
8
8
|
city: string;
|
|
9
9
|
country: string;
|
|
10
|
+
outline: Array<{
|
|
11
|
+
latitude: number;
|
|
12
|
+
longitude: number;
|
|
13
|
+
}>;
|
|
10
14
|
zipcode: string;
|
|
11
15
|
};
|
|
12
16
|
}
|
|
@@ -21,6 +25,9 @@ export interface MunicipalityApiResult {
|
|
|
21
25
|
nom: string;
|
|
22
26
|
};
|
|
23
27
|
codesPostaux: string[];
|
|
28
|
+
contour: {
|
|
29
|
+
coordinates: Array<Array<Array<number>>>;
|
|
30
|
+
};
|
|
24
31
|
}
|
|
25
32
|
interface Options {
|
|
26
33
|
country?: 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,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,WA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B,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;AA6E7G,eAAO,MAAM,OAAO,EAAE,kBAoCrB,CAAA;AAID,eAAO,MAAM,GAAG,EAAE,2BAQjB,CAAA"}
|
|
@@ -6,10 +6,16 @@ export declare type ReverseGeolocSearchResult = {
|
|
|
6
6
|
city: string;
|
|
7
7
|
code: string;
|
|
8
8
|
coordinates: [number, number];
|
|
9
|
+
outline: Array<{
|
|
10
|
+
latitude: number;
|
|
11
|
+
longitude: number;
|
|
12
|
+
}>;
|
|
9
13
|
zipcode: string;
|
|
14
|
+
postcode: string | null;
|
|
15
|
+
district: string | null;
|
|
10
16
|
};
|
|
11
17
|
export declare const get: (search: {
|
|
12
18
|
latitude: number;
|
|
13
19
|
longitude: number;
|
|
14
|
-
}, debounceValue?: number) => Promise<ReverseGeolocSearchResult[]>;
|
|
20
|
+
}, debounceValue?: number, signal?: AbortSignal | undefined) => Promise<ReverseGeolocSearchResult[]>;
|
|
15
21
|
//# sourceMappingURL=reverseGeolocSearch.d.ts.map
|
|
@@ -1 +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;
|
|
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,KAAK,CAAC;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;IACvD,OAAO,EAAE,MAAM,CAAA;IACf,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAA;IACvB,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAA;CACxB,CAAA;AAuED,eAAO,MAAM,GAAG,WACN;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,kBAChC,MAAM,uCAEpB,QAAQ,yBAAyB,EAAE,CAQrC,CAAA"}
|
package/dist/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,6BAA6B,QAAS,MAAM,WAMxD,CAAA;AAED,eAAO,MAAM,MAAM,WAAY,MAAM,kBAAkB,OAAO,
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,6BAA6B,QAAS,MAAM,WAMxD,CAAA;AAED,eAAO,MAAM,MAAM,WAAY,MAAM,kBAAkB,OAAO,WAe7D,CAAA"}
|