@pretto/places 0.37.0 → 0.38.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 +6 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +36 -68
- 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 +36 -68
- package/dist/searchByAddress.d.ts +1 -1
- package/dist/searchByAddress.d.ts.map +1 -1
- package/dist/searchByCoordinates.d.ts +1 -1
- package/dist/searchByCoordinates.d.ts.map +1 -1
- package/dist/searchByCountry.d.ts +2 -2
- package/dist/searchByCountry.d.ts.map +1 -1
- package/dist/searchByDepartment.d.ts +1 -1
- package/dist/searchByDepartment.d.ts.map +1 -1
- package/dist/searchByMunicipality.d.ts +1 -1
- package/dist/searchByMunicipality.d.ts.map +1 -1
- package/dist/searchByZipcode.d.ts +1 -1
- package/dist/searchByZipcode.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
import { CustomFetchOptions, LongLat, MunicipalitySearchResult } from './types';
|
2
|
-
type SearchType = 'city' | 'zipcode' | 'coordinates';
|
3
|
-
export declare const searchPlaces: (searchValue: string | LongLat, options?: CustomFetchOptions, searchType?: SearchType[]) => Promise<MunicipalitySearchResult[]>;
|
4
|
-
export declare const searchDepartment: (searchValue: string, options?: CustomFetchOptions) => Promise<import("./types").DepartmentSearchResult[]>;
|
5
|
-
export declare const searchAddress: (searchValue: string, options?: CustomFetchOptions) => Promise<import("./types").AddressSearchResult[]>;
|
2
|
+
declare type SearchType = 'city' | 'zipcode' | 'coordinates';
|
3
|
+
export declare const searchPlaces: (searchValue: string | LongLat, options?: CustomFetchOptions | undefined, searchType?: SearchType[]) => Promise<MunicipalitySearchResult[]>;
|
4
|
+
export declare const searchDepartment: (searchValue: string, options?: CustomFetchOptions | undefined) => Promise<import("./types").DepartmentSearchResult[]>;
|
5
|
+
export declare const searchAddress: (searchValue: string, options?: CustomFetchOptions | undefined) => Promise<import("./types").AddressSearchResult[]>;
|
6
6
|
export * as searchCountry from './searchByCountry';
|
7
7
|
/**
|
8
8
|
* @deprecated Use searchPlaces instead
|
9
9
|
*/
|
10
|
-
export declare const municipalitySearch: (searchValue: string | LongLat, options?: CustomFetchOptions, searchType?: SearchType[]) => Promise<MunicipalitySearchResult[]>;
|
10
|
+
export declare const municipalitySearch: (searchValue: string | LongLat, options?: CustomFetchOptions | undefined, searchType?: SearchType[]) => Promise<MunicipalitySearchResult[]>;
|
11
11
|
/**
|
12
12
|
* @deprecated Use searchPlaces instead
|
13
13
|
*/
|
14
|
-
export declare const geolocSearch: (searchValue: string | LongLat, options?: CustomFetchOptions, searchType?: SearchType[]) => Promise<MunicipalitySearchResult[]>;
|
14
|
+
export declare const geolocSearch: (searchValue: string | LongLat, options?: CustomFetchOptions | undefined, searchType?: SearchType[]) => Promise<MunicipalitySearchResult[]>;
|
15
15
|
/**
|
16
16
|
* @deprecated Use searchByCoordinates instead
|
17
17
|
*/
|
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":"AAKA,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,CAkCpC,CAAA;AAED,eAAO,MAAM,gBAAgB,gBAAiB,MAAM,kGACV,CAAA;AAE1C,eAAO,MAAM,aAAa,gBAAiB,MAAM,+FACV,CAAA;AAEvC,OAAO,KAAK,aAAa,MAAM,mBAAmB,CAAA;AAIlD;;GAEG;AACH,eAAO,MAAM,kBAAkB,gBApDhB,MAAM,GAAG,OAAO,yDAEjB,UAAU,EAAE,KACvB,QAAQ,wBAAwB,EAAE,CAiDS,CAAA;AAE9C;;GAEG;AACH,eAAO,MAAM,YAAY,gBAzDV,MAAM,GAAG,OAAO,yDAEjB,UAAU,EAAE,KACvB,QAAQ,wBAAwB,EAAE,CAsDG,CAAA;AAExC;;GAEG;AACH,eAAO,MAAM,mBAAmB,qHAAsB,CAAA;AAEtD;;GAEG;AACH,eAAO,MAAM,aAAa,qHAAkB,CAAA"}
|
package/dist/index.js
CHANGED
@@ -8,7 +8,7 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
|
|
8
8
|
|
9
9
|
var algoliasearch__default = /*#__PURE__*/_interopDefaultLegacy(algoliasearch);
|
10
10
|
|
11
|
-
|
11
|
+
/*! *****************************************************************************
|
12
12
|
Copyright (c) Microsoft Corporation.
|
13
13
|
|
14
14
|
Permission to use, copy, modify, and/or distribute this software for any
|
@@ -31,21 +31,7 @@ function __awaiter(thisArg, _arguments, P, generator) {
|
|
31
31
|
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
32
32
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
33
33
|
});
|
34
|
-
}
|
35
|
-
|
36
|
-
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
37
|
-
var e = new Error(message);
|
38
|
-
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
39
|
-
};
|
40
|
-
|
41
|
-
let controller = { current: null };
|
42
|
-
const getSignal = () => {
|
43
|
-
if (controller.current) {
|
44
|
-
controller.current.abort();
|
45
|
-
}
|
46
|
-
controller.current = new AbortController();
|
47
|
-
return controller.current.signal;
|
48
|
-
};
|
34
|
+
}
|
49
35
|
|
50
36
|
const MUNICIPALITY_API_URL = 'https://geo.api.gouv.fr/communes';
|
51
37
|
const DEPARTMENT_API_URL = 'https://geo.api.gouv.fr/departements';
|
@@ -55,55 +41,49 @@ const BOOST = '&boost=population';
|
|
55
41
|
const TYPES = '&type=arrondissement-municipal,commune-actuelle';
|
56
42
|
|
57
43
|
const DEFAULT_DEBOUNCE_TIME = 300;
|
58
|
-
let getDelayedData
|
59
|
-
|
60
|
-
try {
|
61
|
-
const response = yield fetch(url, { signal });
|
62
|
-
if (!response.ok) {
|
63
|
-
throw new Error('Error: ' + response.status);
|
64
|
-
}
|
65
|
-
return response;
|
66
|
-
}
|
67
|
-
catch (error) {
|
68
|
-
if (error instanceof DOMException && error.name === 'AbortError') {
|
69
|
-
return new Promise(() => { });
|
70
|
-
}
|
71
|
-
throw error;
|
72
|
-
}
|
73
|
-
});
|
74
|
-
function customFetch(url, options) {
|
75
|
-
var _a;
|
44
|
+
let getDelayedData;
|
45
|
+
function customFetch(url, options = { debouncetime: DEFAULT_DEBOUNCE_TIME }) {
|
76
46
|
return __awaiter(this, void 0, void 0, function* () {
|
77
|
-
|
78
|
-
clearTimeout(getDelayedData);
|
79
|
-
}
|
80
|
-
const debounceTime = (_a = options === null || options === void 0 ? void 0 : options.debouncetime) !== null && _a !== void 0 ? _a : DEFAULT_DEBOUNCE_TIME;
|
47
|
+
clearTimeout(getDelayedData);
|
81
48
|
return new Promise((resolve, reject) => {
|
82
49
|
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
|
+
});
|
83
57
|
try {
|
84
58
|
if (Array.isArray(url)) {
|
85
|
-
const responses = yield Promise.all(url.map(singleUrl => fetchData(singleUrl
|
59
|
+
const responses = yield Promise.all(url.map(singleUrl => fetchData(singleUrl)));
|
86
60
|
resolve(responses);
|
87
61
|
}
|
88
62
|
else {
|
89
|
-
const response = yield fetchData(url
|
63
|
+
const response = yield fetchData(url);
|
90
64
|
resolve(response);
|
91
65
|
}
|
92
66
|
}
|
93
67
|
catch (error) {
|
94
|
-
if (error instanceof DOMException && error.name === 'AbortError') {
|
95
|
-
return;
|
96
|
-
}
|
97
68
|
reject(error);
|
98
69
|
}
|
99
|
-
}),
|
70
|
+
}), options.debouncetime);
|
100
71
|
});
|
101
72
|
});
|
102
73
|
}
|
103
74
|
|
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;
|
104
84
|
const searchByAddress = (searchValue, options) => __awaiter(void 0, void 0, void 0, function* () {
|
105
85
|
const url = `${ADDRESS_API_URL}/?q=${searchValue}&autocomplete=1&limit=${(options === null || options === void 0 ? void 0 : options.limit) || 10}`;
|
106
|
-
const signal = (options === null || options === void 0 ? void 0 : options.signal) || getSignal();
|
86
|
+
const signal = (options === null || options === void 0 ? void 0 : options.signal) || getSignal(controller$4);
|
107
87
|
const addressResponse = yield customFetch(url, Object.assign(Object.assign({}, options), { signal }));
|
108
88
|
const addressResult = yield addressResponse.json();
|
109
89
|
const formatAddressResult = addressResult.features.reduce((acc, { properties }) => {
|
@@ -136,9 +116,10 @@ const formatToMunicipalitySearchResult = (results) => {
|
|
136
116
|
}));
|
137
117
|
};
|
138
118
|
|
119
|
+
let controller$3 = null;
|
139
120
|
const searchByCoordinates = ({ latitude, longitude }, options) => __awaiter(void 0, void 0, void 0, function* () {
|
140
121
|
const url = `${MUNICIPALITY_API_URL}?lat=${latitude}&lon=${longitude}${FIELDS}${BOOST}`;
|
141
|
-
const signal = (options === null || options === void 0 ? void 0 : options.signal) || getSignal();
|
122
|
+
const signal = (options === null || options === void 0 ? void 0 : options.signal) || getSignal(controller$3);
|
142
123
|
try {
|
143
124
|
const gpsResponse = yield customFetch([url + TYPES, url], Object.assign(Object.assign({}, options), { signal }));
|
144
125
|
const arrondissementsResponse = yield gpsResponse[0].json();
|
@@ -152,10 +133,11 @@ const searchByCoordinates = ({ latitude, longitude }, options) => __awaiter(void
|
|
152
133
|
}
|
153
134
|
});
|
154
135
|
|
136
|
+
let controller$2 = null;
|
155
137
|
const searchByDepartment = (searchValue, options) => __awaiter(void 0, void 0, void 0, function* () {
|
156
138
|
if (isNaN(parseInt(searchValue))) {
|
157
139
|
const nameDepartmentUrl = `${DEPARTMENT_API_URL}?nom=${searchValue}&fields=region,codeRegion&limit=21`;
|
158
|
-
const signal = (options === null || options === void 0 ? void 0 : options.signal) || getSignal();
|
140
|
+
const signal = (options === null || options === void 0 ? void 0 : options.signal) || getSignal(controller$2);
|
159
141
|
const departmentResponse = yield customFetch(nameDepartmentUrl, Object.assign(Object.assign({}, options), { signal }));
|
160
142
|
const departmentResult = yield departmentResponse.json();
|
161
143
|
return departmentResult.map(result => ({
|
@@ -184,6 +166,7 @@ function isStartsWith(arr, value) {
|
|
184
166
|
|
185
167
|
const SPECIAL_CITIES = ['paris ', 'lyon ', 'marseille '];
|
186
168
|
let CURRENT_RESULT = [];
|
169
|
+
let controller$1 = null;
|
187
170
|
const filterOnCurrentResult = (searchValue) => {
|
188
171
|
const searchRegex = new RegExp(searchValue
|
189
172
|
.split(' ')
|
@@ -199,13 +182,13 @@ const searchByMunicipality = (searchValue, options) => __awaiter(void 0, void 0,
|
|
199
182
|
}
|
200
183
|
CURRENT_RESULT = [];
|
201
184
|
const url = `${MUNICIPALITY_API_URL}?nom=${searchValue}${FIELDS}${BOOST}&limit=${(options === null || options === void 0 ? void 0 : options.limit) || 10}`;
|
202
|
-
const signal = (options === null || options === void 0 ? void 0 : options.signal) || getSignal();
|
185
|
+
const signal = (options === null || options === void 0 ? void 0 : options.signal) || getSignal(controller$1);
|
203
186
|
const cityResponse = yield customFetch(url, Object.assign(Object.assign({}, options), { signal }));
|
204
187
|
const cityResult = yield cityResponse.json();
|
205
188
|
// The first result is Paris, Lyon or Marseille, we want get all arrondissements
|
206
189
|
if (cityResult.length > 0 && ['75', '13', '69'].includes(cityResult[0].codeDepartement)) {
|
207
190
|
const url = `${MUNICIPALITY_API_URL}?nom=${searchValue}&codeDepartement=${cityResult[0].codeDepartement}${FIELDS}${BOOST}${TYPES}&limit=21`;
|
208
|
-
const arrondissementsResponse = yield customFetch(url);
|
191
|
+
const arrondissementsResponse = yield customFetch(url, options);
|
209
192
|
const arrondissementsResult = yield arrondissementsResponse.json();
|
210
193
|
const filtredAndSortArrondissementsResult = arrondissementsResult
|
211
194
|
.filter(item => item.codesPostaux.length === 1)
|
@@ -220,9 +203,10 @@ const searchByMunicipality = (searchValue, options) => __awaiter(void 0, void 0,
|
|
220
203
|
return formatToMunicipalitySearchResult(filterCityResults(cityResult));
|
221
204
|
});
|
222
205
|
|
206
|
+
let controller = null;
|
223
207
|
const searchByZipcode = (searchValue, options) => __awaiter(void 0, void 0, void 0, function* () {
|
224
208
|
const url = `${MUNICIPALITY_API_URL}?codePostal=${searchValue}${FIELDS}${BOOST}${TYPES}`;
|
225
|
-
const signal = (options === null || options === void 0 ? void 0 : options.signal) || getSignal();
|
209
|
+
const signal = (options === null || options === void 0 ? void 0 : options.signal) || getSignal(controller);
|
226
210
|
const zipCodeResponse = yield customFetch(url, Object.assign(Object.assign({}, options), { signal }));
|
227
211
|
const zipCodeResult = yield zipCodeResponse.json();
|
228
212
|
const filtredZipCodeResult = zipCodeResult.filter(item => item.codesPostaux.length <= 1);
|
@@ -284,7 +268,6 @@ var searchByCountry = /*#__PURE__*/Object.freeze({
|
|
284
268
|
|
285
269
|
const searchPlaces = (searchValue, options, searchType = ['city', 'zipcode', 'coordinates']) => __awaiter(void 0, void 0, void 0, function* () {
|
286
270
|
if (!searchValue) {
|
287
|
-
getSignal();
|
288
271
|
return [];
|
289
272
|
}
|
290
273
|
try {
|
@@ -311,23 +294,8 @@ const searchPlaces = (searchValue, options, searchType = ['city', 'zipcode', 'co
|
|
311
294
|
return [];
|
312
295
|
}
|
313
296
|
});
|
314
|
-
const searchDepartment = (searchValue, options) =>
|
315
|
-
|
316
|
-
throw new Error('Search value cannot contain numbers');
|
317
|
-
}
|
318
|
-
if (!searchValue) {
|
319
|
-
getSignal();
|
320
|
-
return [];
|
321
|
-
}
|
322
|
-
return searchByDepartment(searchValue, options);
|
323
|
-
});
|
324
|
-
const searchAddress = (searchValue, options) => __awaiter(void 0, void 0, void 0, function* () {
|
325
|
-
if (!searchValue || searchValue.length < 3) {
|
326
|
-
getSignal();
|
327
|
-
return [];
|
328
|
-
}
|
329
|
-
return searchByAddress(searchValue, options);
|
330
|
-
});
|
297
|
+
const searchDepartment = (searchValue, options) => searchByDepartment(searchValue, options);
|
298
|
+
const searchAddress = (searchValue, options) => searchByAddress(searchValue, options);
|
331
299
|
/* Deprecated names */
|
332
300
|
/**
|
333
301
|
* @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;AAO9C,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: () => AbortSignal;
|
1
|
+
export declare const getSignal: (controller: AbortController | null) => 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":"AAAA,eAAO,MAAM,SAAS,eAAgB,eAAe,GAAG,IAAI,gBAO3D,CAAA"}
|
package/dist/module.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
import algoliasearch from 'algoliasearch';
|
2
2
|
|
3
|
-
|
3
|
+
/*! *****************************************************************************
|
4
4
|
Copyright (c) Microsoft Corporation.
|
5
5
|
|
6
6
|
Permission to use, copy, modify, and/or distribute this software for any
|
@@ -23,21 +23,7 @@ function __awaiter(thisArg, _arguments, P, generator) {
|
|
23
23
|
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
24
24
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
25
25
|
});
|
26
|
-
}
|
27
|
-
|
28
|
-
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
29
|
-
var e = new Error(message);
|
30
|
-
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
31
|
-
};
|
32
|
-
|
33
|
-
let controller = { current: null };
|
34
|
-
const getSignal = () => {
|
35
|
-
if (controller.current) {
|
36
|
-
controller.current.abort();
|
37
|
-
}
|
38
|
-
controller.current = new AbortController();
|
39
|
-
return controller.current.signal;
|
40
|
-
};
|
26
|
+
}
|
41
27
|
|
42
28
|
const MUNICIPALITY_API_URL = 'https://geo.api.gouv.fr/communes';
|
43
29
|
const DEPARTMENT_API_URL = 'https://geo.api.gouv.fr/departements';
|
@@ -47,55 +33,49 @@ const BOOST = '&boost=population';
|
|
47
33
|
const TYPES = '&type=arrondissement-municipal,commune-actuelle';
|
48
34
|
|
49
35
|
const DEFAULT_DEBOUNCE_TIME = 300;
|
50
|
-
let getDelayedData
|
51
|
-
|
52
|
-
try {
|
53
|
-
const response = yield fetch(url, { signal });
|
54
|
-
if (!response.ok) {
|
55
|
-
throw new Error('Error: ' + response.status);
|
56
|
-
}
|
57
|
-
return response;
|
58
|
-
}
|
59
|
-
catch (error) {
|
60
|
-
if (error instanceof DOMException && error.name === 'AbortError') {
|
61
|
-
return new Promise(() => { });
|
62
|
-
}
|
63
|
-
throw error;
|
64
|
-
}
|
65
|
-
});
|
66
|
-
function customFetch(url, options) {
|
67
|
-
var _a;
|
36
|
+
let getDelayedData;
|
37
|
+
function customFetch(url, options = { debouncetime: DEFAULT_DEBOUNCE_TIME }) {
|
68
38
|
return __awaiter(this, void 0, void 0, function* () {
|
69
|
-
|
70
|
-
clearTimeout(getDelayedData);
|
71
|
-
}
|
72
|
-
const debounceTime = (_a = options === null || options === void 0 ? void 0 : options.debouncetime) !== null && _a !== void 0 ? _a : DEFAULT_DEBOUNCE_TIME;
|
39
|
+
clearTimeout(getDelayedData);
|
73
40
|
return new Promise((resolve, reject) => {
|
74
41
|
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
|
+
});
|
75
49
|
try {
|
76
50
|
if (Array.isArray(url)) {
|
77
|
-
const responses = yield Promise.all(url.map(singleUrl => fetchData(singleUrl
|
51
|
+
const responses = yield Promise.all(url.map(singleUrl => fetchData(singleUrl)));
|
78
52
|
resolve(responses);
|
79
53
|
}
|
80
54
|
else {
|
81
|
-
const response = yield fetchData(url
|
55
|
+
const response = yield fetchData(url);
|
82
56
|
resolve(response);
|
83
57
|
}
|
84
58
|
}
|
85
59
|
catch (error) {
|
86
|
-
if (error instanceof DOMException && error.name === 'AbortError') {
|
87
|
-
return;
|
88
|
-
}
|
89
60
|
reject(error);
|
90
61
|
}
|
91
|
-
}),
|
62
|
+
}), options.debouncetime);
|
92
63
|
});
|
93
64
|
});
|
94
65
|
}
|
95
66
|
|
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;
|
96
76
|
const searchByAddress = (searchValue, options) => __awaiter(void 0, void 0, void 0, function* () {
|
97
77
|
const url = `${ADDRESS_API_URL}/?q=${searchValue}&autocomplete=1&limit=${(options === null || options === void 0 ? void 0 : options.limit) || 10}`;
|
98
|
-
const signal = (options === null || options === void 0 ? void 0 : options.signal) || getSignal();
|
78
|
+
const signal = (options === null || options === void 0 ? void 0 : options.signal) || getSignal(controller$4);
|
99
79
|
const addressResponse = yield customFetch(url, Object.assign(Object.assign({}, options), { signal }));
|
100
80
|
const addressResult = yield addressResponse.json();
|
101
81
|
const formatAddressResult = addressResult.features.reduce((acc, { properties }) => {
|
@@ -128,9 +108,10 @@ const formatToMunicipalitySearchResult = (results) => {
|
|
128
108
|
}));
|
129
109
|
};
|
130
110
|
|
111
|
+
let controller$3 = null;
|
131
112
|
const searchByCoordinates = ({ latitude, longitude }, options) => __awaiter(void 0, void 0, void 0, function* () {
|
132
113
|
const url = `${MUNICIPALITY_API_URL}?lat=${latitude}&lon=${longitude}${FIELDS}${BOOST}`;
|
133
|
-
const signal = (options === null || options === void 0 ? void 0 : options.signal) || getSignal();
|
114
|
+
const signal = (options === null || options === void 0 ? void 0 : options.signal) || getSignal(controller$3);
|
134
115
|
try {
|
135
116
|
const gpsResponse = yield customFetch([url + TYPES, url], Object.assign(Object.assign({}, options), { signal }));
|
136
117
|
const arrondissementsResponse = yield gpsResponse[0].json();
|
@@ -144,10 +125,11 @@ const searchByCoordinates = ({ latitude, longitude }, options) => __awaiter(void
|
|
144
125
|
}
|
145
126
|
});
|
146
127
|
|
128
|
+
let controller$2 = null;
|
147
129
|
const searchByDepartment = (searchValue, options) => __awaiter(void 0, void 0, void 0, function* () {
|
148
130
|
if (isNaN(parseInt(searchValue))) {
|
149
131
|
const nameDepartmentUrl = `${DEPARTMENT_API_URL}?nom=${searchValue}&fields=region,codeRegion&limit=21`;
|
150
|
-
const signal = (options === null || options === void 0 ? void 0 : options.signal) || getSignal();
|
132
|
+
const signal = (options === null || options === void 0 ? void 0 : options.signal) || getSignal(controller$2);
|
151
133
|
const departmentResponse = yield customFetch(nameDepartmentUrl, Object.assign(Object.assign({}, options), { signal }));
|
152
134
|
const departmentResult = yield departmentResponse.json();
|
153
135
|
return departmentResult.map(result => ({
|
@@ -176,6 +158,7 @@ function isStartsWith(arr, value) {
|
|
176
158
|
|
177
159
|
const SPECIAL_CITIES = ['paris ', 'lyon ', 'marseille '];
|
178
160
|
let CURRENT_RESULT = [];
|
161
|
+
let controller$1 = null;
|
179
162
|
const filterOnCurrentResult = (searchValue) => {
|
180
163
|
const searchRegex = new RegExp(searchValue
|
181
164
|
.split(' ')
|
@@ -191,13 +174,13 @@ const searchByMunicipality = (searchValue, options) => __awaiter(void 0, void 0,
|
|
191
174
|
}
|
192
175
|
CURRENT_RESULT = [];
|
193
176
|
const url = `${MUNICIPALITY_API_URL}?nom=${searchValue}${FIELDS}${BOOST}&limit=${(options === null || options === void 0 ? void 0 : options.limit) || 10}`;
|
194
|
-
const signal = (options === null || options === void 0 ? void 0 : options.signal) || getSignal();
|
177
|
+
const signal = (options === null || options === void 0 ? void 0 : options.signal) || getSignal(controller$1);
|
195
178
|
const cityResponse = yield customFetch(url, Object.assign(Object.assign({}, options), { signal }));
|
196
179
|
const cityResult = yield cityResponse.json();
|
197
180
|
// The first result is Paris, Lyon or Marseille, we want get all arrondissements
|
198
181
|
if (cityResult.length > 0 && ['75', '13', '69'].includes(cityResult[0].codeDepartement)) {
|
199
182
|
const url = `${MUNICIPALITY_API_URL}?nom=${searchValue}&codeDepartement=${cityResult[0].codeDepartement}${FIELDS}${BOOST}${TYPES}&limit=21`;
|
200
|
-
const arrondissementsResponse = yield customFetch(url);
|
183
|
+
const arrondissementsResponse = yield customFetch(url, options);
|
201
184
|
const arrondissementsResult = yield arrondissementsResponse.json();
|
202
185
|
const filtredAndSortArrondissementsResult = arrondissementsResult
|
203
186
|
.filter(item => item.codesPostaux.length === 1)
|
@@ -212,9 +195,10 @@ const searchByMunicipality = (searchValue, options) => __awaiter(void 0, void 0,
|
|
212
195
|
return formatToMunicipalitySearchResult(filterCityResults(cityResult));
|
213
196
|
});
|
214
197
|
|
198
|
+
let controller = null;
|
215
199
|
const searchByZipcode = (searchValue, options) => __awaiter(void 0, void 0, void 0, function* () {
|
216
200
|
const url = `${MUNICIPALITY_API_URL}?codePostal=${searchValue}${FIELDS}${BOOST}${TYPES}`;
|
217
|
-
const signal = (options === null || options === void 0 ? void 0 : options.signal) || getSignal();
|
201
|
+
const signal = (options === null || options === void 0 ? void 0 : options.signal) || getSignal(controller);
|
218
202
|
const zipCodeResponse = yield customFetch(url, Object.assign(Object.assign({}, options), { signal }));
|
219
203
|
const zipCodeResult = yield zipCodeResponse.json();
|
220
204
|
const filtredZipCodeResult = zipCodeResult.filter(item => item.codesPostaux.length <= 1);
|
@@ -276,7 +260,6 @@ var searchByCountry = /*#__PURE__*/Object.freeze({
|
|
276
260
|
|
277
261
|
const searchPlaces = (searchValue, options, searchType = ['city', 'zipcode', 'coordinates']) => __awaiter(void 0, void 0, void 0, function* () {
|
278
262
|
if (!searchValue) {
|
279
|
-
getSignal();
|
280
263
|
return [];
|
281
264
|
}
|
282
265
|
try {
|
@@ -303,23 +286,8 @@ const searchPlaces = (searchValue, options, searchType = ['city', 'zipcode', 'co
|
|
303
286
|
return [];
|
304
287
|
}
|
305
288
|
});
|
306
|
-
const searchDepartment = (searchValue, options) =>
|
307
|
-
|
308
|
-
throw new Error('Search value cannot contain numbers');
|
309
|
-
}
|
310
|
-
if (!searchValue) {
|
311
|
-
getSignal();
|
312
|
-
return [];
|
313
|
-
}
|
314
|
-
return searchByDepartment(searchValue, options);
|
315
|
-
});
|
316
|
-
const searchAddress = (searchValue, options) => __awaiter(void 0, void 0, void 0, function* () {
|
317
|
-
if (!searchValue || searchValue.length < 3) {
|
318
|
-
getSignal();
|
319
|
-
return [];
|
320
|
-
}
|
321
|
-
return searchByAddress(searchValue, options);
|
322
|
-
});
|
289
|
+
const searchDepartment = (searchValue, options) => searchByDepartment(searchValue, options);
|
290
|
+
const searchAddress = (searchValue, options) => searchByAddress(searchValue, options);
|
323
291
|
/* Deprecated names */
|
324
292
|
/**
|
325
293
|
* @deprecated Use searchPlaces instead
|
@@ -1,3 +1,3 @@
|
|
1
1
|
import { AddressSearchResult, CustomFetchOptions } from './types';
|
2
|
-
export declare const searchByAddress: (searchValue: string, options?: CustomFetchOptions) => Promise<AddressSearchResult[]>;
|
2
|
+
export declare const searchByAddress: (searchValue: string, options?: CustomFetchOptions | undefined) => Promise<AddressSearchResult[]>;
|
3
3
|
//# sourceMappingURL=searchByAddress.d.ts.map
|
@@ -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;AAelE,eAAO,MAAM,eAAe,gBACb,MAAM,+CAElB,QAAQ,mBAAmB,EAAE,CAuB/B,CAAA"}
|
@@ -1,3 +1,3 @@
|
|
1
1
|
import { CustomFetchOptions, LongLat, MunicipalitySearchResult } from './types';
|
2
|
-
export declare const searchByCoordinates: ({ latitude, longitude }: LongLat, options?: CustomFetchOptions) => Promise<MunicipalitySearchResult[]>;
|
2
|
+
export declare const searchByCoordinates: ({ latitude, longitude }: LongLat, options?: CustomFetchOptions | undefined) => Promise<MunicipalitySearchResult[]>;
|
3
3
|
//# sourceMappingURL=searchByCoordinates.d.ts.map
|
@@ -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;AAI9F,eAAO,MAAM,mBAAmB,4BACL,OAAO,+CAE/B,QAAQ,wBAAwB,EAAE,CAiBpC,CAAA"}
|
@@ -4,8 +4,8 @@ interface Options {
|
|
4
4
|
limit?: number;
|
5
5
|
language?: 'fr' | 'en';
|
6
6
|
}
|
7
|
-
export declare const init: (appId: string, apiKey: string, options?: AlgoliaSearchOptions) => "An error occurred." | {
|
8
|
-
get(search: string, options?: Options): Promise<CountriesSearchResult[]>;
|
7
|
+
export declare const init: (appId: string, apiKey: string, options?: AlgoliaSearchOptions | undefined) => "An error occurred." | {
|
8
|
+
get(search: string, options?: Options | undefined): Promise<CountriesSearchResult[]>;
|
9
9
|
};
|
10
10
|
export {};
|
11
11
|
//# sourceMappingURL=searchByCountry.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"searchByCountry.d.ts","sourceRoot":"","sources":["../src/searchByCountry.ts"],"names":[],"mappings":"AAAA,OAAsB,EAAE,oBAAoB,EAAgB,MAAM,eAAe,CAAC;AAGlF,OAAO,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AAShD,UAAU,OAAO;IACf,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,QAAQ,CAAC,EAAE,IAAI,GAAG,IAAI,CAAA;CACvB;AAyBD,eAAO,MAAM,IAAI,UAAW,MAAM,UAAU,MAAM
|
1
|
+
{"version":3,"file":"searchByCountry.d.ts","sourceRoot":"","sources":["../src/searchByCountry.ts"],"names":[],"mappings":"AAAA,OAAsB,EAAE,oBAAoB,EAAgB,MAAM,eAAe,CAAC;AAGlF,OAAO,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AAShD,UAAU,OAAO;IACf,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,QAAQ,CAAC,EAAE,IAAI,GAAG,IAAI,CAAA;CACvB;AAyBD,eAAO,MAAM,IAAI,UAAW,MAAM,UAAU,MAAM;gBAK1B,MAAM;CAS7B,CAAA"}
|
@@ -1,3 +1,3 @@
|
|
1
1
|
import { CustomFetchOptions, DepartmentSearchResult } from './types';
|
2
|
-
export declare const searchByDepartment: (searchValue: string, options?: CustomFetchOptions) => Promise<DepartmentSearchResult[]>;
|
2
|
+
export declare const searchByDepartment: (searchValue: string, options?: CustomFetchOptions | undefined) => Promise<DepartmentSearchResult[]>;
|
3
3
|
//# sourceMappingURL=searchByDepartment.d.ts.map
|
@@ -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;AAIjB,eAAO,MAAM,kBAAkB,gBAChB,MAAM,+CAElB,QAAQ,sBAAsB,EAAE,CA4BlC,CAAA"}
|
@@ -1,3 +1,3 @@
|
|
1
1
|
import { CustomFetchOptions, MunicipalitySearchResult } from './types';
|
2
|
-
export declare const searchByMunicipality: (searchValue: string, options?: CustomFetchOptions) => Promise<MunicipalitySearchResult[]>;
|
2
|
+
export declare const searchByMunicipality: (searchValue: string, options?: CustomFetchOptions | undefined) => Promise<MunicipalitySearchResult[]>;
|
3
3
|
//# sourceMappingURL=searchByMunicipality.d.ts.map
|
@@ -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;AAqBrF,eAAO,MAAM,oBAAoB,gBAClB,MAAM,+CAElB,QAAQ,wBAAwB,EAAE,CAqCpC,CAAA"}
|
@@ -1,3 +1,3 @@
|
|
1
1
|
import { CustomFetchOptions, MunicipalitySearchResult } from './types';
|
2
|
-
export declare const searchByZipcode: (searchValue: string, options?: CustomFetchOptions) => Promise<MunicipalitySearchResult[]>;
|
2
|
+
export declare const searchByZipcode: (searchValue: string, options?: CustomFetchOptions | undefined) => Promise<MunicipalitySearchResult[]>;
|
3
3
|
//# sourceMappingURL=searchByZipcode.d.ts.map
|
@@ -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;AAIrF,eAAO,MAAM,eAAe,gBACb,MAAM,+CAElB,QAAQ,wBAAwB,EAAE,CAUpC,CAAA"}
|