@pretto/places 0.35.0 → 0.37.0
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/index.d.ts +6 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +68 -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 +68 -36
- 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
|
-
|
3
|
-
export declare const searchPlaces: (searchValue: string | LongLat, options?: CustomFetchOptions
|
4
|
-
export declare const searchDepartment: (searchValue: string, options?: CustomFetchOptions
|
5
|
-
export declare const searchAddress: (searchValue: string, options?: CustomFetchOptions
|
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[]>;
|
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
|
10
|
+
export declare const municipalitySearch: (searchValue: string | LongLat, options?: CustomFetchOptions, searchType?: SearchType[]) => Promise<MunicipalitySearchResult[]>;
|
11
11
|
/**
|
12
12
|
* @deprecated Use searchPlaces instead
|
13
13
|
*/
|
14
|
-
export declare const geolocSearch: (searchValue: string | LongLat, options?: CustomFetchOptions
|
14
|
+
export declare const geolocSearch: (searchValue: string | LongLat, options?: CustomFetchOptions, 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":"AAMA,OAAO,EAAE,kBAAkB,EAAE,OAAO,EAAE,wBAAwB,EAAE,MAAM,SAAS,CAAC;AAEhF,KAAK,UAAU,GAAG,MAAM,GAAG,SAAS,GAAG,aAAa,CAAA;AAEpD,eAAO,MAAM,YAAY,gBACV,MAAM,GAAG,OAAO,YACnB,kBAAkB,eAChB,UAAU,EAAE,KACvB,QAAQ,wBAAwB,EAAE,CAmCpC,CAAA;AAED,eAAO,MAAM,gBAAgB,gBAAuB,MAAM,YAAY,kBAAkB,wDAWvF,CAAA;AAED,eAAO,MAAM,aAAa,gBAAuB,MAAM,YAAY,kBAAkB,qDAOpF,CAAA;AAED,OAAO,KAAK,aAAa,MAAM,mBAAmB,CAAA;AAIlD;;GAEG;AACH,eAAO,MAAM,kBAAkB,gBArEhB,MAAM,GAAG,OAAO,YACnB,kBAAkB,eAChB,UAAU,EAAE,KACvB,QAAQ,wBAAwB,EAAE,CAkES,CAAA;AAE9C;;GAEG;AACH,eAAO,MAAM,YAAY,gBA1EV,MAAM,GAAG,OAAO,YACnB,kBAAkB,eAChB,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
@@ -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,7 +31,21 @@ 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
|
-
}
|
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
|
+
};
|
35
49
|
|
36
50
|
const MUNICIPALITY_API_URL = 'https://geo.api.gouv.fr/communes';
|
37
51
|
const DEPARTMENT_API_URL = 'https://geo.api.gouv.fr/departements';
|
@@ -41,49 +55,55 @@ const BOOST = '&boost=population';
|
|
41
55
|
const TYPES = '&type=arrondissement-municipal,commune-actuelle';
|
42
56
|
|
43
57
|
const DEFAULT_DEBOUNCE_TIME = 300;
|
44
|
-
let getDelayedData;
|
45
|
-
|
58
|
+
let getDelayedData = null;
|
59
|
+
const fetchData = (url, signal) => __awaiter(void 0, void 0, void 0, function* () {
|
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;
|
46
76
|
return __awaiter(this, void 0, void 0, function* () {
|
47
|
-
|
77
|
+
if (getDelayedData) {
|
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;
|
48
81
|
return new Promise((resolve, reject) => {
|
49
82
|
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
83
|
try {
|
58
84
|
if (Array.isArray(url)) {
|
59
|
-
const responses = yield Promise.all(url.map(singleUrl => fetchData(singleUrl)));
|
85
|
+
const responses = yield Promise.all(url.map(singleUrl => fetchData(singleUrl, options === null || options === void 0 ? void 0 : options.signal)));
|
60
86
|
resolve(responses);
|
61
87
|
}
|
62
88
|
else {
|
63
|
-
const response = yield fetchData(url);
|
89
|
+
const response = yield fetchData(url, options === null || options === void 0 ? void 0 : options.signal);
|
64
90
|
resolve(response);
|
65
91
|
}
|
66
92
|
}
|
67
93
|
catch (error) {
|
94
|
+
if (error instanceof DOMException && error.name === 'AbortError') {
|
95
|
+
return;
|
96
|
+
}
|
68
97
|
reject(error);
|
69
98
|
}
|
70
|
-
}),
|
99
|
+
}), debounceTime);
|
71
100
|
});
|
72
101
|
});
|
73
102
|
}
|
74
103
|
|
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
104
|
const searchByAddress = (searchValue, options) => __awaiter(void 0, void 0, void 0, function* () {
|
85
105
|
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(
|
106
|
+
const signal = (options === null || options === void 0 ? void 0 : options.signal) || getSignal();
|
87
107
|
const addressResponse = yield customFetch(url, Object.assign(Object.assign({}, options), { signal }));
|
88
108
|
const addressResult = yield addressResponse.json();
|
89
109
|
const formatAddressResult = addressResult.features.reduce((acc, { properties }) => {
|
@@ -116,10 +136,9 @@ const formatToMunicipalitySearchResult = (results) => {
|
|
116
136
|
}));
|
117
137
|
};
|
118
138
|
|
119
|
-
let controller$3 = null;
|
120
139
|
const searchByCoordinates = ({ latitude, longitude }, options) => __awaiter(void 0, void 0, void 0, function* () {
|
121
140
|
const url = `${MUNICIPALITY_API_URL}?lat=${latitude}&lon=${longitude}${FIELDS}${BOOST}`;
|
122
|
-
const signal = (options === null || options === void 0 ? void 0 : options.signal) || getSignal(
|
141
|
+
const signal = (options === null || options === void 0 ? void 0 : options.signal) || getSignal();
|
123
142
|
try {
|
124
143
|
const gpsResponse = yield customFetch([url + TYPES, url], Object.assign(Object.assign({}, options), { signal }));
|
125
144
|
const arrondissementsResponse = yield gpsResponse[0].json();
|
@@ -133,11 +152,10 @@ const searchByCoordinates = ({ latitude, longitude }, options) => __awaiter(void
|
|
133
152
|
}
|
134
153
|
});
|
135
154
|
|
136
|
-
let controller$2 = null;
|
137
155
|
const searchByDepartment = (searchValue, options) => __awaiter(void 0, void 0, void 0, function* () {
|
138
156
|
if (isNaN(parseInt(searchValue))) {
|
139
157
|
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(
|
158
|
+
const signal = (options === null || options === void 0 ? void 0 : options.signal) || getSignal();
|
141
159
|
const departmentResponse = yield customFetch(nameDepartmentUrl, Object.assign(Object.assign({}, options), { signal }));
|
142
160
|
const departmentResult = yield departmentResponse.json();
|
143
161
|
return departmentResult.map(result => ({
|
@@ -166,7 +184,6 @@ function isStartsWith(arr, value) {
|
|
166
184
|
|
167
185
|
const SPECIAL_CITIES = ['paris ', 'lyon ', 'marseille '];
|
168
186
|
let CURRENT_RESULT = [];
|
169
|
-
let controller$1 = null;
|
170
187
|
const filterOnCurrentResult = (searchValue) => {
|
171
188
|
const searchRegex = new RegExp(searchValue
|
172
189
|
.split(' ')
|
@@ -182,13 +199,13 @@ const searchByMunicipality = (searchValue, options) => __awaiter(void 0, void 0,
|
|
182
199
|
}
|
183
200
|
CURRENT_RESULT = [];
|
184
201
|
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(
|
202
|
+
const signal = (options === null || options === void 0 ? void 0 : options.signal) || getSignal();
|
186
203
|
const cityResponse = yield customFetch(url, Object.assign(Object.assign({}, options), { signal }));
|
187
204
|
const cityResult = yield cityResponse.json();
|
188
205
|
// The first result is Paris, Lyon or Marseille, we want get all arrondissements
|
189
206
|
if (cityResult.length > 0 && ['75', '13', '69'].includes(cityResult[0].codeDepartement)) {
|
190
207
|
const url = `${MUNICIPALITY_API_URL}?nom=${searchValue}&codeDepartement=${cityResult[0].codeDepartement}${FIELDS}${BOOST}${TYPES}&limit=21`;
|
191
|
-
const arrondissementsResponse = yield customFetch(url
|
208
|
+
const arrondissementsResponse = yield customFetch(url);
|
192
209
|
const arrondissementsResult = yield arrondissementsResponse.json();
|
193
210
|
const filtredAndSortArrondissementsResult = arrondissementsResult
|
194
211
|
.filter(item => item.codesPostaux.length === 1)
|
@@ -203,10 +220,9 @@ const searchByMunicipality = (searchValue, options) => __awaiter(void 0, void 0,
|
|
203
220
|
return formatToMunicipalitySearchResult(filterCityResults(cityResult));
|
204
221
|
});
|
205
222
|
|
206
|
-
let controller = null;
|
207
223
|
const searchByZipcode = (searchValue, options) => __awaiter(void 0, void 0, void 0, function* () {
|
208
224
|
const url = `${MUNICIPALITY_API_URL}?codePostal=${searchValue}${FIELDS}${BOOST}${TYPES}`;
|
209
|
-
const signal = (options === null || options === void 0 ? void 0 : options.signal) || getSignal(
|
225
|
+
const signal = (options === null || options === void 0 ? void 0 : options.signal) || getSignal();
|
210
226
|
const zipCodeResponse = yield customFetch(url, Object.assign(Object.assign({}, options), { signal }));
|
211
227
|
const zipCodeResult = yield zipCodeResponse.json();
|
212
228
|
const filtredZipCodeResult = zipCodeResult.filter(item => item.codesPostaux.length <= 1);
|
@@ -268,6 +284,7 @@ var searchByCountry = /*#__PURE__*/Object.freeze({
|
|
268
284
|
|
269
285
|
const searchPlaces = (searchValue, options, searchType = ['city', 'zipcode', 'coordinates']) => __awaiter(void 0, void 0, void 0, function* () {
|
270
286
|
if (!searchValue) {
|
287
|
+
getSignal();
|
271
288
|
return [];
|
272
289
|
}
|
273
290
|
try {
|
@@ -294,8 +311,23 @@ const searchPlaces = (searchValue, options, searchType = ['city', 'zipcode', 'co
|
|
294
311
|
return [];
|
295
312
|
}
|
296
313
|
});
|
297
|
-
const searchDepartment = (searchValue, options) =>
|
298
|
-
|
314
|
+
const searchDepartment = (searchValue, options) => __awaiter(void 0, void 0, void 0, function* () {
|
315
|
+
if (/\d/.test(searchValue)) {
|
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
|
+
});
|
299
331
|
/* Deprecated names */
|
300
332
|
/**
|
301
333
|
* @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
@@ -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,7 +23,21 @@ 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
|
-
}
|
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
|
+
};
|
27
41
|
|
28
42
|
const MUNICIPALITY_API_URL = 'https://geo.api.gouv.fr/communes';
|
29
43
|
const DEPARTMENT_API_URL = 'https://geo.api.gouv.fr/departements';
|
@@ -33,49 +47,55 @@ const BOOST = '&boost=population';
|
|
33
47
|
const TYPES = '&type=arrondissement-municipal,commune-actuelle';
|
34
48
|
|
35
49
|
const DEFAULT_DEBOUNCE_TIME = 300;
|
36
|
-
let getDelayedData;
|
37
|
-
|
50
|
+
let getDelayedData = null;
|
51
|
+
const fetchData = (url, signal) => __awaiter(void 0, void 0, void 0, function* () {
|
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;
|
38
68
|
return __awaiter(this, void 0, void 0, function* () {
|
39
|
-
|
69
|
+
if (getDelayedData) {
|
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;
|
40
73
|
return new Promise((resolve, reject) => {
|
41
74
|
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
75
|
try {
|
50
76
|
if (Array.isArray(url)) {
|
51
|
-
const responses = yield Promise.all(url.map(singleUrl => fetchData(singleUrl)));
|
77
|
+
const responses = yield Promise.all(url.map(singleUrl => fetchData(singleUrl, options === null || options === void 0 ? void 0 : options.signal)));
|
52
78
|
resolve(responses);
|
53
79
|
}
|
54
80
|
else {
|
55
|
-
const response = yield fetchData(url);
|
81
|
+
const response = yield fetchData(url, options === null || options === void 0 ? void 0 : options.signal);
|
56
82
|
resolve(response);
|
57
83
|
}
|
58
84
|
}
|
59
85
|
catch (error) {
|
86
|
+
if (error instanceof DOMException && error.name === 'AbortError') {
|
87
|
+
return;
|
88
|
+
}
|
60
89
|
reject(error);
|
61
90
|
}
|
62
|
-
}),
|
91
|
+
}), debounceTime);
|
63
92
|
});
|
64
93
|
});
|
65
94
|
}
|
66
95
|
|
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
96
|
const searchByAddress = (searchValue, options) => __awaiter(void 0, void 0, void 0, function* () {
|
77
97
|
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(
|
98
|
+
const signal = (options === null || options === void 0 ? void 0 : options.signal) || getSignal();
|
79
99
|
const addressResponse = yield customFetch(url, Object.assign(Object.assign({}, options), { signal }));
|
80
100
|
const addressResult = yield addressResponse.json();
|
81
101
|
const formatAddressResult = addressResult.features.reduce((acc, { properties }) => {
|
@@ -108,10 +128,9 @@ const formatToMunicipalitySearchResult = (results) => {
|
|
108
128
|
}));
|
109
129
|
};
|
110
130
|
|
111
|
-
let controller$3 = null;
|
112
131
|
const searchByCoordinates = ({ latitude, longitude }, options) => __awaiter(void 0, void 0, void 0, function* () {
|
113
132
|
const url = `${MUNICIPALITY_API_URL}?lat=${latitude}&lon=${longitude}${FIELDS}${BOOST}`;
|
114
|
-
const signal = (options === null || options === void 0 ? void 0 : options.signal) || getSignal(
|
133
|
+
const signal = (options === null || options === void 0 ? void 0 : options.signal) || getSignal();
|
115
134
|
try {
|
116
135
|
const gpsResponse = yield customFetch([url + TYPES, url], Object.assign(Object.assign({}, options), { signal }));
|
117
136
|
const arrondissementsResponse = yield gpsResponse[0].json();
|
@@ -125,11 +144,10 @@ const searchByCoordinates = ({ latitude, longitude }, options) => __awaiter(void
|
|
125
144
|
}
|
126
145
|
});
|
127
146
|
|
128
|
-
let controller$2 = null;
|
129
147
|
const searchByDepartment = (searchValue, options) => __awaiter(void 0, void 0, void 0, function* () {
|
130
148
|
if (isNaN(parseInt(searchValue))) {
|
131
149
|
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(
|
150
|
+
const signal = (options === null || options === void 0 ? void 0 : options.signal) || getSignal();
|
133
151
|
const departmentResponse = yield customFetch(nameDepartmentUrl, Object.assign(Object.assign({}, options), { signal }));
|
134
152
|
const departmentResult = yield departmentResponse.json();
|
135
153
|
return departmentResult.map(result => ({
|
@@ -158,7 +176,6 @@ function isStartsWith(arr, value) {
|
|
158
176
|
|
159
177
|
const SPECIAL_CITIES = ['paris ', 'lyon ', 'marseille '];
|
160
178
|
let CURRENT_RESULT = [];
|
161
|
-
let controller$1 = null;
|
162
179
|
const filterOnCurrentResult = (searchValue) => {
|
163
180
|
const searchRegex = new RegExp(searchValue
|
164
181
|
.split(' ')
|
@@ -174,13 +191,13 @@ const searchByMunicipality = (searchValue, options) => __awaiter(void 0, void 0,
|
|
174
191
|
}
|
175
192
|
CURRENT_RESULT = [];
|
176
193
|
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(
|
194
|
+
const signal = (options === null || options === void 0 ? void 0 : options.signal) || getSignal();
|
178
195
|
const cityResponse = yield customFetch(url, Object.assign(Object.assign({}, options), { signal }));
|
179
196
|
const cityResult = yield cityResponse.json();
|
180
197
|
// The first result is Paris, Lyon or Marseille, we want get all arrondissements
|
181
198
|
if (cityResult.length > 0 && ['75', '13', '69'].includes(cityResult[0].codeDepartement)) {
|
182
199
|
const url = `${MUNICIPALITY_API_URL}?nom=${searchValue}&codeDepartement=${cityResult[0].codeDepartement}${FIELDS}${BOOST}${TYPES}&limit=21`;
|
183
|
-
const arrondissementsResponse = yield customFetch(url
|
200
|
+
const arrondissementsResponse = yield customFetch(url);
|
184
201
|
const arrondissementsResult = yield arrondissementsResponse.json();
|
185
202
|
const filtredAndSortArrondissementsResult = arrondissementsResult
|
186
203
|
.filter(item => item.codesPostaux.length === 1)
|
@@ -195,10 +212,9 @@ const searchByMunicipality = (searchValue, options) => __awaiter(void 0, void 0,
|
|
195
212
|
return formatToMunicipalitySearchResult(filterCityResults(cityResult));
|
196
213
|
});
|
197
214
|
|
198
|
-
let controller = null;
|
199
215
|
const searchByZipcode = (searchValue, options) => __awaiter(void 0, void 0, void 0, function* () {
|
200
216
|
const url = `${MUNICIPALITY_API_URL}?codePostal=${searchValue}${FIELDS}${BOOST}${TYPES}`;
|
201
|
-
const signal = (options === null || options === void 0 ? void 0 : options.signal) || getSignal(
|
217
|
+
const signal = (options === null || options === void 0 ? void 0 : options.signal) || getSignal();
|
202
218
|
const zipCodeResponse = yield customFetch(url, Object.assign(Object.assign({}, options), { signal }));
|
203
219
|
const zipCodeResult = yield zipCodeResponse.json();
|
204
220
|
const filtredZipCodeResult = zipCodeResult.filter(item => item.codesPostaux.length <= 1);
|
@@ -260,6 +276,7 @@ var searchByCountry = /*#__PURE__*/Object.freeze({
|
|
260
276
|
|
261
277
|
const searchPlaces = (searchValue, options, searchType = ['city', 'zipcode', 'coordinates']) => __awaiter(void 0, void 0, void 0, function* () {
|
262
278
|
if (!searchValue) {
|
279
|
+
getSignal();
|
263
280
|
return [];
|
264
281
|
}
|
265
282
|
try {
|
@@ -286,8 +303,23 @@ const searchPlaces = (searchValue, options, searchType = ['city', 'zipcode', 'co
|
|
286
303
|
return [];
|
287
304
|
}
|
288
305
|
});
|
289
|
-
const searchDepartment = (searchValue, options) =>
|
290
|
-
|
306
|
+
const searchDepartment = (searchValue, options) => __awaiter(void 0, void 0, void 0, function* () {
|
307
|
+
if (/\d/.test(searchValue)) {
|
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
|
+
});
|
291
323
|
/* Deprecated names */
|
292
324
|
/**
|
293
325
|
* @deprecated Use searchPlaces instead
|
@@ -1,3 +1,3 @@
|
|
1
1
|
import { AddressSearchResult, CustomFetchOptions } from './types';
|
2
|
-
export declare const searchByAddress: (searchValue: string, options?: CustomFetchOptions
|
2
|
+
export declare const searchByAddress: (searchValue: string, options?: CustomFetchOptions) => 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;AAalE,eAAO,MAAM,eAAe,gBACb,MAAM,YACT,kBAAkB,KAC3B,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
|
2
|
+
export declare const searchByCoordinates: ({ latitude, longitude }: LongLat, options?: CustomFetchOptions) => 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;AAE9F,eAAO,MAAM,mBAAmB,4BACL,OAAO,YACtB,kBAAkB,KAC3B,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
|
8
|
-
get(search: string, options?: Options
|
7
|
+
export declare const init: (appId: string, apiKey: string, options?: AlgoliaSearchOptions) => "An error occurred." | {
|
8
|
+
get(search: string, options?: Options): 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,YAAY,oBAAoB;gBAK1D,MAAM,YAAY,OAAO;CAShD,CAAA"}
|
@@ -1,3 +1,3 @@
|
|
1
1
|
import { CustomFetchOptions, DepartmentSearchResult } from './types';
|
2
|
-
export declare const searchByDepartment: (searchValue: string, options?: CustomFetchOptions
|
2
|
+
export declare const searchByDepartment: (searchValue: string, options?: CustomFetchOptions) => 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;AAEjB,eAAO,MAAM,kBAAkB,gBAChB,MAAM,YACT,kBAAkB,KAC3B,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
|
2
|
+
export declare const searchByMunicipality: (searchValue: string, options?: CustomFetchOptions) => 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;AAoBrF,eAAO,MAAM,oBAAoB,gBAClB,MAAM,YACT,kBAAkB,KAC3B,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
|
2
|
+
export declare const searchByZipcode: (searchValue: string, options?: CustomFetchOptions) => 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;AAErF,eAAO,MAAM,eAAe,gBACb,MAAM,YACT,kBAAkB,KAC3B,QAAQ,wBAAwB,EAAE,CAUpC,CAAA"}
|