@pretto/places 0.38.0 → 0.39.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.d.ts.map +1 -1
- package/dist/index.js +70 -36
- package/dist/lib/customFetch.d.ts.map +1 -1
- package/dist/lib/getSignal.d.ts +1 -1
- package/dist/lib/getSignal.d.ts.map +1 -1
- package/dist/module.js +70 -36
- package/dist/searchByAddress.d.ts.map +1 -1
- package/dist/searchByCoordinates.d.ts.map +1 -1
- package/dist/searchByDepartment.d.ts.map +1 -1
- package/dist/searchByMunicipality.d.ts.map +1 -1
- package/dist/searchByZipcode.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,kBAAkB,EAAE,OAAO,EAAE,wBAAwB,EAAE,MAAM,SAAS,CAAC;AAEhF,aAAK,UAAU,GAAG,MAAM,GAAG,SAAS,GAAG,aAAa,CAAA;AAEpD,eAAO,MAAM,YAAY,gBACV,MAAM,GAAG,OAAO,yDAEjB,UAAU,EAAE,KACvB,QAAQ,wBAAwB,EAAE,CAmCpC,CAAA;AAED,eAAO,MAAM,gBAAgB,gBAAuB,MAAM,kGAWzD,CAAA;AAED,eAAO,MAAM,aAAa,gBAAuB,MAAM,+FAOtD,CAAA;AAED,OAAO,KAAK,aAAa,MAAM,mBAAmB,CAAA;AAIlD;;GAEG;AACH,eAAO,MAAM,kBAAkB,gBArEhB,MAAM,GAAG,OAAO,yDAEjB,UAAU,EAAE,KACvB,QAAQ,wBAAwB,EAAE,CAkES,CAAA;AAE9C;;GAEG;AACH,eAAO,MAAM,YAAY,gBA1EV,MAAM,GAAG,OAAO,yDAEjB,UAAU,EAAE,KACvB,QAAQ,wBAAwB,EAAE,CAuEG,CAAA;AAExC;;GAEG;AACH,eAAO,MAAM,mBAAmB,qHAAsB,CAAA;AAEtD;;GAEG;AACH,eAAO,MAAM,aAAa,qHAAkB,CAAA"}
|
package/dist/index.js
CHANGED
@@ -33,6 +33,15 @@ function __awaiter(thisArg, _arguments, P, generator) {
|
|
33
33
|
});
|
34
34
|
}
|
35
35
|
|
36
|
+
let controller = { current: null };
|
37
|
+
const getSignal = () => {
|
38
|
+
if (controller.current) {
|
39
|
+
controller.current.abort();
|
40
|
+
}
|
41
|
+
controller.current = new AbortController();
|
42
|
+
return controller.current.signal;
|
43
|
+
};
|
44
|
+
|
36
45
|
const MUNICIPALITY_API_URL = 'https://geo.api.gouv.fr/communes';
|
37
46
|
const DEPARTMENT_API_URL = 'https://geo.api.gouv.fr/departements';
|
38
47
|
const ADDRESS_API_URL = 'https://api-adresse.data.gouv.fr/search';
|
@@ -41,49 +50,55 @@ const BOOST = '&boost=population';
|
|
41
50
|
const TYPES = '&type=arrondissement-municipal,commune-actuelle';
|
42
51
|
|
43
52
|
const DEFAULT_DEBOUNCE_TIME = 300;
|
44
|
-
let getDelayedData;
|
45
|
-
|
53
|
+
let getDelayedData = null;
|
54
|
+
const fetchData = (url, signal) => __awaiter(void 0, void 0, void 0, function* () {
|
55
|
+
try {
|
56
|
+
const response = yield fetch(url, { signal });
|
57
|
+
if (!response.ok) {
|
58
|
+
throw new Error('Error: ' + response.status);
|
59
|
+
}
|
60
|
+
return response;
|
61
|
+
}
|
62
|
+
catch (error) {
|
63
|
+
if (error instanceof DOMException && error.name === 'AbortError') {
|
64
|
+
return new Promise(() => { });
|
65
|
+
}
|
66
|
+
throw error;
|
67
|
+
}
|
68
|
+
});
|
69
|
+
function customFetch(url, options) {
|
70
|
+
var _a;
|
46
71
|
return __awaiter(this, void 0, void 0, function* () {
|
47
|
-
|
72
|
+
if (getDelayedData) {
|
73
|
+
clearTimeout(getDelayedData);
|
74
|
+
}
|
75
|
+
const debounceTime = (_a = options === null || options === void 0 ? void 0 : options.debouncetime) !== null && _a !== void 0 ? _a : DEFAULT_DEBOUNCE_TIME;
|
48
76
|
return new Promise((resolve, reject) => {
|
49
77
|
getDelayedData = setTimeout(() => __awaiter(this, void 0, void 0, function* () {
|
50
|
-
const fetchData = (singleUrl) => __awaiter(this, void 0, void 0, function* () {
|
51
|
-
const response = yield fetch(singleUrl, { signal: options.signal });
|
52
|
-
if (!response.ok) {
|
53
|
-
throw new Error('Error: ' + response.status);
|
54
|
-
}
|
55
|
-
return response;
|
56
|
-
});
|
57
78
|
try {
|
58
79
|
if (Array.isArray(url)) {
|
59
|
-
const responses = yield Promise.all(url.map(singleUrl => fetchData(singleUrl)));
|
80
|
+
const responses = yield Promise.all(url.map(singleUrl => fetchData(singleUrl, options === null || options === void 0 ? void 0 : options.signal)));
|
60
81
|
resolve(responses);
|
61
82
|
}
|
62
83
|
else {
|
63
|
-
const response = yield fetchData(url);
|
84
|
+
const response = yield fetchData(url, options === null || options === void 0 ? void 0 : options.signal);
|
64
85
|
resolve(response);
|
65
86
|
}
|
66
87
|
}
|
67
88
|
catch (error) {
|
89
|
+
if (error instanceof DOMException && error.name === 'AbortError') {
|
90
|
+
return;
|
91
|
+
}
|
68
92
|
reject(error);
|
69
93
|
}
|
70
|
-
}),
|
94
|
+
}), debounceTime);
|
71
95
|
});
|
72
96
|
});
|
73
97
|
}
|
74
98
|
|
75
|
-
const getSignal = (controller) => {
|
76
|
-
if (controller) {
|
77
|
-
controller.abort();
|
78
|
-
}
|
79
|
-
controller = new AbortController();
|
80
|
-
return controller.signal;
|
81
|
-
};
|
82
|
-
|
83
|
-
let controller$4 = null;
|
84
99
|
const searchByAddress = (searchValue, options) => __awaiter(void 0, void 0, void 0, function* () {
|
85
100
|
const url = `${ADDRESS_API_URL}/?q=${searchValue}&autocomplete=1&limit=${(options === null || options === void 0 ? void 0 : options.limit) || 10}`;
|
86
|
-
const signal = (options === null || options === void 0 ? void 0 : options.signal) || getSignal(
|
101
|
+
const signal = (options === null || options === void 0 ? void 0 : options.signal) || getSignal();
|
87
102
|
const addressResponse = yield customFetch(url, Object.assign(Object.assign({}, options), { signal }));
|
88
103
|
const addressResult = yield addressResponse.json();
|
89
104
|
const formatAddressResult = addressResult.features.reduce((acc, { properties }) => {
|
@@ -116,10 +131,9 @@ const formatToMunicipalitySearchResult = (results) => {
|
|
116
131
|
}));
|
117
132
|
};
|
118
133
|
|
119
|
-
let controller$3 = null;
|
120
134
|
const searchByCoordinates = ({ latitude, longitude }, options) => __awaiter(void 0, void 0, void 0, function* () {
|
121
135
|
const url = `${MUNICIPALITY_API_URL}?lat=${latitude}&lon=${longitude}${FIELDS}${BOOST}`;
|
122
|
-
const signal = (options === null || options === void 0 ? void 0 : options.signal) || getSignal(
|
136
|
+
const signal = (options === null || options === void 0 ? void 0 : options.signal) || getSignal();
|
123
137
|
try {
|
124
138
|
const gpsResponse = yield customFetch([url + TYPES, url], Object.assign(Object.assign({}, options), { signal }));
|
125
139
|
const arrondissementsResponse = yield gpsResponse[0].json();
|
@@ -133,11 +147,10 @@ const searchByCoordinates = ({ latitude, longitude }, options) => __awaiter(void
|
|
133
147
|
}
|
134
148
|
});
|
135
149
|
|
136
|
-
let controller$2 = null;
|
137
150
|
const searchByDepartment = (searchValue, options) => __awaiter(void 0, void 0, void 0, function* () {
|
138
151
|
if (isNaN(parseInt(searchValue))) {
|
139
152
|
const nameDepartmentUrl = `${DEPARTMENT_API_URL}?nom=${searchValue}&fields=region,codeRegion&limit=21`;
|
140
|
-
const signal = (options === null || options === void 0 ? void 0 : options.signal) || getSignal(
|
153
|
+
const signal = (options === null || options === void 0 ? void 0 : options.signal) || getSignal();
|
141
154
|
const departmentResponse = yield customFetch(nameDepartmentUrl, Object.assign(Object.assign({}, options), { signal }));
|
142
155
|
const departmentResult = yield departmentResponse.json();
|
143
156
|
return departmentResult.map(result => ({
|
@@ -166,7 +179,6 @@ function isStartsWith(arr, value) {
|
|
166
179
|
|
167
180
|
const SPECIAL_CITIES = ['paris ', 'lyon ', 'marseille '];
|
168
181
|
let CURRENT_RESULT = [];
|
169
|
-
let controller$1 = null;
|
170
182
|
const filterOnCurrentResult = (searchValue) => {
|
171
183
|
const searchRegex = new RegExp(searchValue
|
172
184
|
.split(' ')
|
@@ -182,16 +194,23 @@ const searchByMunicipality = (searchValue, options) => __awaiter(void 0, void 0,
|
|
182
194
|
}
|
183
195
|
CURRENT_RESULT = [];
|
184
196
|
const url = `${MUNICIPALITY_API_URL}?nom=${searchValue}${FIELDS}${BOOST}&limit=${(options === null || options === void 0 ? void 0 : options.limit) || 10}`;
|
185
|
-
const signal = (options === null || options === void 0 ? void 0 : options.signal) || getSignal(
|
197
|
+
const signal = (options === null || options === void 0 ? void 0 : options.signal) || getSignal();
|
186
198
|
const cityResponse = yield customFetch(url, Object.assign(Object.assign({}, options), { signal }));
|
187
199
|
const cityResult = yield cityResponse.json();
|
188
200
|
// The first result is Paris, Lyon or Marseille, we want get all arrondissements
|
189
201
|
if (cityResult.length > 0 && ['75', '13', '69'].includes(cityResult[0].codeDepartement)) {
|
190
202
|
const url = `${MUNICIPALITY_API_URL}?nom=${searchValue}&codeDepartement=${cityResult[0].codeDepartement}${FIELDS}${BOOST}${TYPES}&limit=21`;
|
191
|
-
const arrondissementsResponse = yield customFetch(url
|
203
|
+
const arrondissementsResponse = yield customFetch(url);
|
192
204
|
const arrondissementsResult = yield arrondissementsResponse.json();
|
193
205
|
const filtredAndSortArrondissementsResult = arrondissementsResult
|
194
|
-
.
|
206
|
+
.reduce((acc, item) => {
|
207
|
+
if (['75056', '13055', '69123'].includes(item.code))
|
208
|
+
return acc;
|
209
|
+
return [
|
210
|
+
...acc,
|
211
|
+
Object.assign(Object.assign({}, item), { codesPostaux: [item.codesPostaux[0]] }),
|
212
|
+
];
|
213
|
+
}, [])
|
195
214
|
.sort((a, b) => parseInt(a.codesPostaux[0]) - parseInt(b.codesPostaux[0]));
|
196
215
|
CURRENT_RESULT = filtredAndSortArrondissementsResult;
|
197
216
|
if (isStartsWith(SPECIAL_CITIES, searchValue.toLowerCase())) {
|
@@ -203,13 +222,12 @@ const searchByMunicipality = (searchValue, options) => __awaiter(void 0, void 0,
|
|
203
222
|
return formatToMunicipalitySearchResult(filterCityResults(cityResult));
|
204
223
|
});
|
205
224
|
|
206
|
-
let controller = null;
|
207
225
|
const searchByZipcode = (searchValue, options) => __awaiter(void 0, void 0, void 0, function* () {
|
208
226
|
const url = `${MUNICIPALITY_API_URL}?codePostal=${searchValue}${FIELDS}${BOOST}${TYPES}`;
|
209
|
-
const signal = (options === null || options === void 0 ? void 0 : options.signal) || getSignal(
|
227
|
+
const signal = (options === null || options === void 0 ? void 0 : options.signal) || getSignal();
|
210
228
|
const zipCodeResponse = yield customFetch(url, Object.assign(Object.assign({}, options), { signal }));
|
211
229
|
const zipCodeResult = yield zipCodeResponse.json();
|
212
|
-
const filtredZipCodeResult = zipCodeResult.filter(item => item.
|
230
|
+
const filtredZipCodeResult = zipCodeResult.filter(item => !['75056', '13055', '69123'].includes(item.code));
|
213
231
|
return formatToMunicipalitySearchResult(filtredZipCodeResult);
|
214
232
|
});
|
215
233
|
|
@@ -268,6 +286,7 @@ var searchByCountry = /*#__PURE__*/Object.freeze({
|
|
268
286
|
|
269
287
|
const searchPlaces = (searchValue, options, searchType = ['city', 'zipcode', 'coordinates']) => __awaiter(void 0, void 0, void 0, function* () {
|
270
288
|
if (!searchValue) {
|
289
|
+
getSignal();
|
271
290
|
return [];
|
272
291
|
}
|
273
292
|
try {
|
@@ -294,8 +313,23 @@ const searchPlaces = (searchValue, options, searchType = ['city', 'zipcode', 'co
|
|
294
313
|
return [];
|
295
314
|
}
|
296
315
|
});
|
297
|
-
const searchDepartment = (searchValue, options) =>
|
298
|
-
|
316
|
+
const searchDepartment = (searchValue, options) => __awaiter(void 0, void 0, void 0, function* () {
|
317
|
+
if (/\d/.test(searchValue)) {
|
318
|
+
throw new Error('Search value cannot contain numbers');
|
319
|
+
}
|
320
|
+
if (!searchValue) {
|
321
|
+
getSignal();
|
322
|
+
return [];
|
323
|
+
}
|
324
|
+
return searchByDepartment(searchValue, options);
|
325
|
+
});
|
326
|
+
const searchAddress = (searchValue, options) => __awaiter(void 0, void 0, void 0, function* () {
|
327
|
+
if (!searchValue || searchValue.length < 3) {
|
328
|
+
getSignal();
|
329
|
+
return [];
|
330
|
+
}
|
331
|
+
return searchByAddress(searchValue, options);
|
332
|
+
});
|
299
333
|
/* Deprecated names */
|
300
334
|
/**
|
301
335
|
* @deprecated Use searchPlaces instead
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"customFetch.d.ts","sourceRoot":"","sources":["../../src/lib/customFetch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;
|
1
|
+
{"version":3,"file":"customFetch.d.ts","sourceRoot":"","sources":["../../src/lib/customFetch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAwB9C,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,CAAC,kBAAkB,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAA;AAC3G,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE,OAAO,CAAC,EAAE,OAAO,CAAC,kBAAkB,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAA"}
|
package/dist/lib/getSignal.d.ts
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
export declare const getSignal: (
|
1
|
+
export declare const getSignal: () => AbortSignal;
|
2
2
|
//# sourceMappingURL=getSignal.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"getSignal.d.ts","sourceRoot":"","sources":["../../src/lib/getSignal.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"getSignal.d.ts","sourceRoot":"","sources":["../../src/lib/getSignal.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,SAAS,mBAQrB,CAAA"}
|
package/dist/module.js
CHANGED
@@ -25,6 +25,15 @@ function __awaiter(thisArg, _arguments, P, generator) {
|
|
25
25
|
});
|
26
26
|
}
|
27
27
|
|
28
|
+
let controller = { current: null };
|
29
|
+
const getSignal = () => {
|
30
|
+
if (controller.current) {
|
31
|
+
controller.current.abort();
|
32
|
+
}
|
33
|
+
controller.current = new AbortController();
|
34
|
+
return controller.current.signal;
|
35
|
+
};
|
36
|
+
|
28
37
|
const MUNICIPALITY_API_URL = 'https://geo.api.gouv.fr/communes';
|
29
38
|
const DEPARTMENT_API_URL = 'https://geo.api.gouv.fr/departements';
|
30
39
|
const ADDRESS_API_URL = 'https://api-adresse.data.gouv.fr/search';
|
@@ -33,49 +42,55 @@ const BOOST = '&boost=population';
|
|
33
42
|
const TYPES = '&type=arrondissement-municipal,commune-actuelle';
|
34
43
|
|
35
44
|
const DEFAULT_DEBOUNCE_TIME = 300;
|
36
|
-
let getDelayedData;
|
37
|
-
|
45
|
+
let getDelayedData = null;
|
46
|
+
const fetchData = (url, signal) => __awaiter(void 0, void 0, void 0, function* () {
|
47
|
+
try {
|
48
|
+
const response = yield fetch(url, { signal });
|
49
|
+
if (!response.ok) {
|
50
|
+
throw new Error('Error: ' + response.status);
|
51
|
+
}
|
52
|
+
return response;
|
53
|
+
}
|
54
|
+
catch (error) {
|
55
|
+
if (error instanceof DOMException && error.name === 'AbortError') {
|
56
|
+
return new Promise(() => { });
|
57
|
+
}
|
58
|
+
throw error;
|
59
|
+
}
|
60
|
+
});
|
61
|
+
function customFetch(url, options) {
|
62
|
+
var _a;
|
38
63
|
return __awaiter(this, void 0, void 0, function* () {
|
39
|
-
|
64
|
+
if (getDelayedData) {
|
65
|
+
clearTimeout(getDelayedData);
|
66
|
+
}
|
67
|
+
const debounceTime = (_a = options === null || options === void 0 ? void 0 : options.debouncetime) !== null && _a !== void 0 ? _a : DEFAULT_DEBOUNCE_TIME;
|
40
68
|
return new Promise((resolve, reject) => {
|
41
69
|
getDelayedData = setTimeout(() => __awaiter(this, void 0, void 0, function* () {
|
42
|
-
const fetchData = (singleUrl) => __awaiter(this, void 0, void 0, function* () {
|
43
|
-
const response = yield fetch(singleUrl, { signal: options.signal });
|
44
|
-
if (!response.ok) {
|
45
|
-
throw new Error('Error: ' + response.status);
|
46
|
-
}
|
47
|
-
return response;
|
48
|
-
});
|
49
70
|
try {
|
50
71
|
if (Array.isArray(url)) {
|
51
|
-
const responses = yield Promise.all(url.map(singleUrl => fetchData(singleUrl)));
|
72
|
+
const responses = yield Promise.all(url.map(singleUrl => fetchData(singleUrl, options === null || options === void 0 ? void 0 : options.signal)));
|
52
73
|
resolve(responses);
|
53
74
|
}
|
54
75
|
else {
|
55
|
-
const response = yield fetchData(url);
|
76
|
+
const response = yield fetchData(url, options === null || options === void 0 ? void 0 : options.signal);
|
56
77
|
resolve(response);
|
57
78
|
}
|
58
79
|
}
|
59
80
|
catch (error) {
|
81
|
+
if (error instanceof DOMException && error.name === 'AbortError') {
|
82
|
+
return;
|
83
|
+
}
|
60
84
|
reject(error);
|
61
85
|
}
|
62
|
-
}),
|
86
|
+
}), debounceTime);
|
63
87
|
});
|
64
88
|
});
|
65
89
|
}
|
66
90
|
|
67
|
-
const getSignal = (controller) => {
|
68
|
-
if (controller) {
|
69
|
-
controller.abort();
|
70
|
-
}
|
71
|
-
controller = new AbortController();
|
72
|
-
return controller.signal;
|
73
|
-
};
|
74
|
-
|
75
|
-
let controller$4 = null;
|
76
91
|
const searchByAddress = (searchValue, options) => __awaiter(void 0, void 0, void 0, function* () {
|
77
92
|
const url = `${ADDRESS_API_URL}/?q=${searchValue}&autocomplete=1&limit=${(options === null || options === void 0 ? void 0 : options.limit) || 10}`;
|
78
|
-
const signal = (options === null || options === void 0 ? void 0 : options.signal) || getSignal(
|
93
|
+
const signal = (options === null || options === void 0 ? void 0 : options.signal) || getSignal();
|
79
94
|
const addressResponse = yield customFetch(url, Object.assign(Object.assign({}, options), { signal }));
|
80
95
|
const addressResult = yield addressResponse.json();
|
81
96
|
const formatAddressResult = addressResult.features.reduce((acc, { properties }) => {
|
@@ -108,10 +123,9 @@ const formatToMunicipalitySearchResult = (results) => {
|
|
108
123
|
}));
|
109
124
|
};
|
110
125
|
|
111
|
-
let controller$3 = null;
|
112
126
|
const searchByCoordinates = ({ latitude, longitude }, options) => __awaiter(void 0, void 0, void 0, function* () {
|
113
127
|
const url = `${MUNICIPALITY_API_URL}?lat=${latitude}&lon=${longitude}${FIELDS}${BOOST}`;
|
114
|
-
const signal = (options === null || options === void 0 ? void 0 : options.signal) || getSignal(
|
128
|
+
const signal = (options === null || options === void 0 ? void 0 : options.signal) || getSignal();
|
115
129
|
try {
|
116
130
|
const gpsResponse = yield customFetch([url + TYPES, url], Object.assign(Object.assign({}, options), { signal }));
|
117
131
|
const arrondissementsResponse = yield gpsResponse[0].json();
|
@@ -125,11 +139,10 @@ const searchByCoordinates = ({ latitude, longitude }, options) => __awaiter(void
|
|
125
139
|
}
|
126
140
|
});
|
127
141
|
|
128
|
-
let controller$2 = null;
|
129
142
|
const searchByDepartment = (searchValue, options) => __awaiter(void 0, void 0, void 0, function* () {
|
130
143
|
if (isNaN(parseInt(searchValue))) {
|
131
144
|
const nameDepartmentUrl = `${DEPARTMENT_API_URL}?nom=${searchValue}&fields=region,codeRegion&limit=21`;
|
132
|
-
const signal = (options === null || options === void 0 ? void 0 : options.signal) || getSignal(
|
145
|
+
const signal = (options === null || options === void 0 ? void 0 : options.signal) || getSignal();
|
133
146
|
const departmentResponse = yield customFetch(nameDepartmentUrl, Object.assign(Object.assign({}, options), { signal }));
|
134
147
|
const departmentResult = yield departmentResponse.json();
|
135
148
|
return departmentResult.map(result => ({
|
@@ -158,7 +171,6 @@ function isStartsWith(arr, value) {
|
|
158
171
|
|
159
172
|
const SPECIAL_CITIES = ['paris ', 'lyon ', 'marseille '];
|
160
173
|
let CURRENT_RESULT = [];
|
161
|
-
let controller$1 = null;
|
162
174
|
const filterOnCurrentResult = (searchValue) => {
|
163
175
|
const searchRegex = new RegExp(searchValue
|
164
176
|
.split(' ')
|
@@ -174,16 +186,23 @@ const searchByMunicipality = (searchValue, options) => __awaiter(void 0, void 0,
|
|
174
186
|
}
|
175
187
|
CURRENT_RESULT = [];
|
176
188
|
const url = `${MUNICIPALITY_API_URL}?nom=${searchValue}${FIELDS}${BOOST}&limit=${(options === null || options === void 0 ? void 0 : options.limit) || 10}`;
|
177
|
-
const signal = (options === null || options === void 0 ? void 0 : options.signal) || getSignal(
|
189
|
+
const signal = (options === null || options === void 0 ? void 0 : options.signal) || getSignal();
|
178
190
|
const cityResponse = yield customFetch(url, Object.assign(Object.assign({}, options), { signal }));
|
179
191
|
const cityResult = yield cityResponse.json();
|
180
192
|
// The first result is Paris, Lyon or Marseille, we want get all arrondissements
|
181
193
|
if (cityResult.length > 0 && ['75', '13', '69'].includes(cityResult[0].codeDepartement)) {
|
182
194
|
const url = `${MUNICIPALITY_API_URL}?nom=${searchValue}&codeDepartement=${cityResult[0].codeDepartement}${FIELDS}${BOOST}${TYPES}&limit=21`;
|
183
|
-
const arrondissementsResponse = yield customFetch(url
|
195
|
+
const arrondissementsResponse = yield customFetch(url);
|
184
196
|
const arrondissementsResult = yield arrondissementsResponse.json();
|
185
197
|
const filtredAndSortArrondissementsResult = arrondissementsResult
|
186
|
-
.
|
198
|
+
.reduce((acc, item) => {
|
199
|
+
if (['75056', '13055', '69123'].includes(item.code))
|
200
|
+
return acc;
|
201
|
+
return [
|
202
|
+
...acc,
|
203
|
+
Object.assign(Object.assign({}, item), { codesPostaux: [item.codesPostaux[0]] }),
|
204
|
+
];
|
205
|
+
}, [])
|
187
206
|
.sort((a, b) => parseInt(a.codesPostaux[0]) - parseInt(b.codesPostaux[0]));
|
188
207
|
CURRENT_RESULT = filtredAndSortArrondissementsResult;
|
189
208
|
if (isStartsWith(SPECIAL_CITIES, searchValue.toLowerCase())) {
|
@@ -195,13 +214,12 @@ const searchByMunicipality = (searchValue, options) => __awaiter(void 0, void 0,
|
|
195
214
|
return formatToMunicipalitySearchResult(filterCityResults(cityResult));
|
196
215
|
});
|
197
216
|
|
198
|
-
let controller = null;
|
199
217
|
const searchByZipcode = (searchValue, options) => __awaiter(void 0, void 0, void 0, function* () {
|
200
218
|
const url = `${MUNICIPALITY_API_URL}?codePostal=${searchValue}${FIELDS}${BOOST}${TYPES}`;
|
201
|
-
const signal = (options === null || options === void 0 ? void 0 : options.signal) || getSignal(
|
219
|
+
const signal = (options === null || options === void 0 ? void 0 : options.signal) || getSignal();
|
202
220
|
const zipCodeResponse = yield customFetch(url, Object.assign(Object.assign({}, options), { signal }));
|
203
221
|
const zipCodeResult = yield zipCodeResponse.json();
|
204
|
-
const filtredZipCodeResult = zipCodeResult.filter(item => item.
|
222
|
+
const filtredZipCodeResult = zipCodeResult.filter(item => !['75056', '13055', '69123'].includes(item.code));
|
205
223
|
return formatToMunicipalitySearchResult(filtredZipCodeResult);
|
206
224
|
});
|
207
225
|
|
@@ -260,6 +278,7 @@ var searchByCountry = /*#__PURE__*/Object.freeze({
|
|
260
278
|
|
261
279
|
const searchPlaces = (searchValue, options, searchType = ['city', 'zipcode', 'coordinates']) => __awaiter(void 0, void 0, void 0, function* () {
|
262
280
|
if (!searchValue) {
|
281
|
+
getSignal();
|
263
282
|
return [];
|
264
283
|
}
|
265
284
|
try {
|
@@ -286,8 +305,23 @@ const searchPlaces = (searchValue, options, searchType = ['city', 'zipcode', 'co
|
|
286
305
|
return [];
|
287
306
|
}
|
288
307
|
});
|
289
|
-
const searchDepartment = (searchValue, options) =>
|
290
|
-
|
308
|
+
const searchDepartment = (searchValue, options) => __awaiter(void 0, void 0, void 0, function* () {
|
309
|
+
if (/\d/.test(searchValue)) {
|
310
|
+
throw new Error('Search value cannot contain numbers');
|
311
|
+
}
|
312
|
+
if (!searchValue) {
|
313
|
+
getSignal();
|
314
|
+
return [];
|
315
|
+
}
|
316
|
+
return searchByDepartment(searchValue, options);
|
317
|
+
});
|
318
|
+
const searchAddress = (searchValue, options) => __awaiter(void 0, void 0, void 0, function* () {
|
319
|
+
if (!searchValue || searchValue.length < 3) {
|
320
|
+
getSignal();
|
321
|
+
return [];
|
322
|
+
}
|
323
|
+
return searchByAddress(searchValue, options);
|
324
|
+
});
|
291
325
|
/* Deprecated names */
|
292
326
|
/**
|
293
327
|
* @deprecated Use searchPlaces instead
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"searchByAddress.d.ts","sourceRoot":"","sources":["../src/searchByAddress.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;
|
1
|
+
{"version":3,"file":"searchByAddress.d.ts","sourceRoot":"","sources":["../src/searchByAddress.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAalE,eAAO,MAAM,eAAe,gBACb,MAAM,+CAElB,QAAQ,mBAAmB,EAAE,CAuB/B,CAAA"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"searchByCoordinates.d.ts","sourceRoot":"","sources":["../src/searchByCoordinates.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,kBAAkB,EAAgB,OAAO,EAAE,wBAAwB,EAAE,MAAM,SAAS,CAAC;
|
1
|
+
{"version":3,"file":"searchByCoordinates.d.ts","sourceRoot":"","sources":["../src/searchByCoordinates.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,kBAAkB,EAAgB,OAAO,EAAE,wBAAwB,EAAE,MAAM,SAAS,CAAC;AAE9F,eAAO,MAAM,mBAAmB,4BACL,OAAO,+CAE/B,QAAQ,wBAAwB,EAAE,CAiBpC,CAAA"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"searchByDepartment.d.ts","sourceRoot":"","sources":["../src/searchByDepartment.ts"],"names":[],"mappings":"AAGA,OAAO,EACH,kBAAkB,EAAE,sBAAsB,EAC7C,MAAM,SAAS,CAAC;
|
1
|
+
{"version":3,"file":"searchByDepartment.d.ts","sourceRoot":"","sources":["../src/searchByDepartment.ts"],"names":[],"mappings":"AAGA,OAAO,EACH,kBAAkB,EAAE,sBAAsB,EAC7C,MAAM,SAAS,CAAC;AAEjB,eAAO,MAAM,kBAAkB,gBAChB,MAAM,+CAElB,QAAQ,sBAAsB,EAAE,CA4BlC,CAAA"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"searchByMunicipality.d.ts","sourceRoot":"","sources":["../src/searchByMunicipality.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,kBAAkB,EAAgB,wBAAwB,EAAE,MAAM,SAAS,CAAC;
|
1
|
+
{"version":3,"file":"searchByMunicipality.d.ts","sourceRoot":"","sources":["../src/searchByMunicipality.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,kBAAkB,EAAgB,wBAAwB,EAAE,MAAM,SAAS,CAAC;AAoBrF,eAAO,MAAM,oBAAoB,gBAClB,MAAM,+CAElB,QAAQ,wBAAwB,EAAE,CA+CpC,CAAA"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"searchByZipcode.d.ts","sourceRoot":"","sources":["../src/searchByZipcode.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,kBAAkB,EAAgB,wBAAwB,EAAE,MAAM,SAAS,CAAC;
|
1
|
+
{"version":3,"file":"searchByZipcode.d.ts","sourceRoot":"","sources":["../src/searchByZipcode.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,kBAAkB,EAAgB,wBAAwB,EAAE,MAAM,SAAS,CAAC;AAErF,eAAO,MAAM,eAAe,gBACb,MAAM,+CAElB,QAAQ,wBAAwB,EAAE,CAUpC,CAAA"}
|