@pretto/places 0.33.0 → 0.37.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.
@@ -1 +1 @@
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,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,CAkCpC,CAAA;AAED,eAAO,MAAM,gBAAgB,gBAAiB,MAAM,YAAY,kBAAkB,wDACxC,CAAA;AAE1C,eAAO,MAAM,aAAa,gBAAiB,MAAM,YAAY,kBAAkB,qDACxC,CAAA;AAEvC,OAAO,KAAK,aAAa,MAAM,mBAAmB,CAAA;AAIlD;;GAEG;AACH,eAAO,MAAM,kBAAkB,gBApDhB,MAAM,GAAG,OAAO,YACnB,kBAAkB,eAChB,UAAU,EAAE,KACvB,QAAQ,wBAAwB,EAAE,CAiDS,CAAA;AAE9C;;GAEG;AACH,eAAO,MAAM,YAAY,gBAzDV,MAAM,GAAG,OAAO,YACnB,kBAAkB,eAChB,UAAU,EAAE,KACvB,QAAQ,wBAAwB,EAAE,CAsDG,CAAA;AAExC;;GAEG;AACH,eAAO,MAAM,mBAAmB,qHAAsB,CAAA;AAEtD;;GAEG;AACH,eAAO,MAAM,aAAa,qHAAkB,CAAA"}
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
@@ -38,6 +38,15 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
38
38
  return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
39
39
  };
40
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
+ };
49
+
41
50
  const MUNICIPALITY_API_URL = 'https://geo.api.gouv.fr/communes';
42
51
  const DEPARTMENT_API_URL = 'https://geo.api.gouv.fr/departements';
43
52
  const ADDRESS_API_URL = 'https://api-adresse.data.gouv.fr/search';
@@ -46,49 +55,55 @@ const BOOST = '&boost=population';
46
55
  const TYPES = '&type=arrondissement-municipal,commune-actuelle';
47
56
 
48
57
  const DEFAULT_DEBOUNCE_TIME = 300;
49
- let getDelayedData;
50
- function customFetch(url, options = { debouncetime: DEFAULT_DEBOUNCE_TIME }) {
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;
51
76
  return __awaiter(this, void 0, void 0, function* () {
52
- clearTimeout(getDelayedData);
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;
53
81
  return new Promise((resolve, reject) => {
54
82
  getDelayedData = setTimeout(() => __awaiter(this, void 0, void 0, function* () {
55
- const fetchData = (singleUrl) => __awaiter(this, void 0, void 0, function* () {
56
- const response = yield fetch(singleUrl, { signal: options.signal });
57
- if (!response.ok) {
58
- throw new Error('Error: ' + response.status);
59
- }
60
- return response;
61
- });
62
83
  try {
63
84
  if (Array.isArray(url)) {
64
- 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)));
65
86
  resolve(responses);
66
87
  }
67
88
  else {
68
- const response = yield fetchData(url);
89
+ const response = yield fetchData(url, options === null || options === void 0 ? void 0 : options.signal);
69
90
  resolve(response);
70
91
  }
71
92
  }
72
93
  catch (error) {
94
+ if (error instanceof DOMException && error.name === 'AbortError') {
95
+ return;
96
+ }
73
97
  reject(error);
74
98
  }
75
- }), options.debouncetime);
99
+ }), debounceTime);
76
100
  });
77
101
  });
78
102
  }
79
103
 
80
- const getSignal = (controller) => {
81
- if (controller) {
82
- controller.abort();
83
- }
84
- controller = new AbortController();
85
- return controller.signal;
86
- };
87
-
88
- let controller$4 = null;
89
104
  const searchByAddress = (searchValue, options) => __awaiter(void 0, void 0, void 0, function* () {
90
105
  const url = `${ADDRESS_API_URL}/?q=${searchValue}&autocomplete=1&limit=${(options === null || options === void 0 ? void 0 : options.limit) || 10}`;
91
- const signal = (options === null || options === void 0 ? void 0 : options.signal) || getSignal(controller$4);
106
+ const signal = (options === null || options === void 0 ? void 0 : options.signal) || getSignal();
92
107
  const addressResponse = yield customFetch(url, Object.assign(Object.assign({}, options), { signal }));
93
108
  const addressResult = yield addressResponse.json();
94
109
  const formatAddressResult = addressResult.features.reduce((acc, { properties }) => {
@@ -121,10 +136,9 @@ const formatToMunicipalitySearchResult = (results) => {
121
136
  }));
122
137
  };
123
138
 
124
- let controller$3 = null;
125
139
  const searchByCoordinates = ({ latitude, longitude }, options) => __awaiter(void 0, void 0, void 0, function* () {
126
140
  const url = `${MUNICIPALITY_API_URL}?lat=${latitude}&lon=${longitude}${FIELDS}${BOOST}`;
127
- const signal = (options === null || options === void 0 ? void 0 : options.signal) || getSignal(controller$3);
141
+ const signal = (options === null || options === void 0 ? void 0 : options.signal) || getSignal();
128
142
  try {
129
143
  const gpsResponse = yield customFetch([url + TYPES, url], Object.assign(Object.assign({}, options), { signal }));
130
144
  const arrondissementsResponse = yield gpsResponse[0].json();
@@ -138,11 +152,10 @@ const searchByCoordinates = ({ latitude, longitude }, options) => __awaiter(void
138
152
  }
139
153
  });
140
154
 
141
- let controller$2 = null;
142
155
  const searchByDepartment = (searchValue, options) => __awaiter(void 0, void 0, void 0, function* () {
143
156
  if (isNaN(parseInt(searchValue))) {
144
157
  const nameDepartmentUrl = `${DEPARTMENT_API_URL}?nom=${searchValue}&fields=region,codeRegion&limit=21`;
145
- const signal = (options === null || options === void 0 ? void 0 : options.signal) || getSignal(controller$2);
158
+ const signal = (options === null || options === void 0 ? void 0 : options.signal) || getSignal();
146
159
  const departmentResponse = yield customFetch(nameDepartmentUrl, Object.assign(Object.assign({}, options), { signal }));
147
160
  const departmentResult = yield departmentResponse.json();
148
161
  return departmentResult.map(result => ({
@@ -171,7 +184,6 @@ function isStartsWith(arr, value) {
171
184
 
172
185
  const SPECIAL_CITIES = ['paris ', 'lyon ', 'marseille '];
173
186
  let CURRENT_RESULT = [];
174
- let controller$1 = null;
175
187
  const filterOnCurrentResult = (searchValue) => {
176
188
  const searchRegex = new RegExp(searchValue
177
189
  .split(' ')
@@ -187,13 +199,13 @@ const searchByMunicipality = (searchValue, options) => __awaiter(void 0, void 0,
187
199
  }
188
200
  CURRENT_RESULT = [];
189
201
  const url = `${MUNICIPALITY_API_URL}?nom=${searchValue}${FIELDS}${BOOST}&limit=${(options === null || options === void 0 ? void 0 : options.limit) || 10}`;
190
- const signal = (options === null || options === void 0 ? void 0 : options.signal) || getSignal(controller$1);
202
+ const signal = (options === null || options === void 0 ? void 0 : options.signal) || getSignal();
191
203
  const cityResponse = yield customFetch(url, Object.assign(Object.assign({}, options), { signal }));
192
204
  const cityResult = yield cityResponse.json();
193
205
  // The first result is Paris, Lyon or Marseille, we want get all arrondissements
194
206
  if (cityResult.length > 0 && ['75', '13', '69'].includes(cityResult[0].codeDepartement)) {
195
207
  const url = `${MUNICIPALITY_API_URL}?nom=${searchValue}&codeDepartement=${cityResult[0].codeDepartement}${FIELDS}${BOOST}${TYPES}&limit=21`;
196
- const arrondissementsResponse = yield customFetch(url, options);
208
+ const arrondissementsResponse = yield customFetch(url);
197
209
  const arrondissementsResult = yield arrondissementsResponse.json();
198
210
  const filtredAndSortArrondissementsResult = arrondissementsResult
199
211
  .filter(item => item.codesPostaux.length === 1)
@@ -208,10 +220,9 @@ const searchByMunicipality = (searchValue, options) => __awaiter(void 0, void 0,
208
220
  return formatToMunicipalitySearchResult(filterCityResults(cityResult));
209
221
  });
210
222
 
211
- let controller = null;
212
223
  const searchByZipcode = (searchValue, options) => __awaiter(void 0, void 0, void 0, function* () {
213
224
  const url = `${MUNICIPALITY_API_URL}?codePostal=${searchValue}${FIELDS}${BOOST}${TYPES}`;
214
- const signal = (options === null || options === void 0 ? void 0 : options.signal) || getSignal(controller);
225
+ const signal = (options === null || options === void 0 ? void 0 : options.signal) || getSignal();
215
226
  const zipCodeResponse = yield customFetch(url, Object.assign(Object.assign({}, options), { signal }));
216
227
  const zipCodeResult = yield zipCodeResponse.json();
217
228
  const filtredZipCodeResult = zipCodeResult.filter(item => item.codesPostaux.length <= 1);
@@ -273,6 +284,7 @@ var searchByCountry = /*#__PURE__*/Object.freeze({
273
284
 
274
285
  const searchPlaces = (searchValue, options, searchType = ['city', 'zipcode', 'coordinates']) => __awaiter(void 0, void 0, void 0, function* () {
275
286
  if (!searchValue) {
287
+ getSignal();
276
288
  return [];
277
289
  }
278
290
  try {
@@ -299,8 +311,23 @@ const searchPlaces = (searchValue, options, searchType = ['city', 'zipcode', 'co
299
311
  return [];
300
312
  }
301
313
  });
302
- const searchDepartment = (searchValue, options) => searchByDepartment(searchValue, options);
303
- const searchAddress = (searchValue, options) => searchByAddress(searchValue, options);
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
+ });
304
331
  /* Deprecated names */
305
332
  /**
306
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;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"}
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"}
@@ -1,2 +1,2 @@
1
- export declare const getSignal: (controller: AbortController | null) => AbortSignal;
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":"AAAA,eAAO,MAAM,SAAS,eAAgB,eAAe,GAAG,IAAI,gBAO3D,CAAA"}
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
@@ -30,6 +30,15 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
30
30
  return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
31
31
  };
32
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
+ };
41
+
33
42
  const MUNICIPALITY_API_URL = 'https://geo.api.gouv.fr/communes';
34
43
  const DEPARTMENT_API_URL = 'https://geo.api.gouv.fr/departements';
35
44
  const ADDRESS_API_URL = 'https://api-adresse.data.gouv.fr/search';
@@ -38,49 +47,55 @@ const BOOST = '&boost=population';
38
47
  const TYPES = '&type=arrondissement-municipal,commune-actuelle';
39
48
 
40
49
  const DEFAULT_DEBOUNCE_TIME = 300;
41
- let getDelayedData;
42
- function customFetch(url, options = { debouncetime: DEFAULT_DEBOUNCE_TIME }) {
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;
43
68
  return __awaiter(this, void 0, void 0, function* () {
44
- clearTimeout(getDelayedData);
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;
45
73
  return new Promise((resolve, reject) => {
46
74
  getDelayedData = setTimeout(() => __awaiter(this, void 0, void 0, function* () {
47
- const fetchData = (singleUrl) => __awaiter(this, void 0, void 0, function* () {
48
- const response = yield fetch(singleUrl, { signal: options.signal });
49
- if (!response.ok) {
50
- throw new Error('Error: ' + response.status);
51
- }
52
- return response;
53
- });
54
75
  try {
55
76
  if (Array.isArray(url)) {
56
- 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)));
57
78
  resolve(responses);
58
79
  }
59
80
  else {
60
- const response = yield fetchData(url);
81
+ const response = yield fetchData(url, options === null || options === void 0 ? void 0 : options.signal);
61
82
  resolve(response);
62
83
  }
63
84
  }
64
85
  catch (error) {
86
+ if (error instanceof DOMException && error.name === 'AbortError') {
87
+ return;
88
+ }
65
89
  reject(error);
66
90
  }
67
- }), options.debouncetime);
91
+ }), debounceTime);
68
92
  });
69
93
  });
70
94
  }
71
95
 
72
- const getSignal = (controller) => {
73
- if (controller) {
74
- controller.abort();
75
- }
76
- controller = new AbortController();
77
- return controller.signal;
78
- };
79
-
80
- let controller$4 = null;
81
96
  const searchByAddress = (searchValue, options) => __awaiter(void 0, void 0, void 0, function* () {
82
97
  const url = `${ADDRESS_API_URL}/?q=${searchValue}&autocomplete=1&limit=${(options === null || options === void 0 ? void 0 : options.limit) || 10}`;
83
- const signal = (options === null || options === void 0 ? void 0 : options.signal) || getSignal(controller$4);
98
+ const signal = (options === null || options === void 0 ? void 0 : options.signal) || getSignal();
84
99
  const addressResponse = yield customFetch(url, Object.assign(Object.assign({}, options), { signal }));
85
100
  const addressResult = yield addressResponse.json();
86
101
  const formatAddressResult = addressResult.features.reduce((acc, { properties }) => {
@@ -113,10 +128,9 @@ const formatToMunicipalitySearchResult = (results) => {
113
128
  }));
114
129
  };
115
130
 
116
- let controller$3 = null;
117
131
  const searchByCoordinates = ({ latitude, longitude }, options) => __awaiter(void 0, void 0, void 0, function* () {
118
132
  const url = `${MUNICIPALITY_API_URL}?lat=${latitude}&lon=${longitude}${FIELDS}${BOOST}`;
119
- const signal = (options === null || options === void 0 ? void 0 : options.signal) || getSignal(controller$3);
133
+ const signal = (options === null || options === void 0 ? void 0 : options.signal) || getSignal();
120
134
  try {
121
135
  const gpsResponse = yield customFetch([url + TYPES, url], Object.assign(Object.assign({}, options), { signal }));
122
136
  const arrondissementsResponse = yield gpsResponse[0].json();
@@ -130,11 +144,10 @@ const searchByCoordinates = ({ latitude, longitude }, options) => __awaiter(void
130
144
  }
131
145
  });
132
146
 
133
- let controller$2 = null;
134
147
  const searchByDepartment = (searchValue, options) => __awaiter(void 0, void 0, void 0, function* () {
135
148
  if (isNaN(parseInt(searchValue))) {
136
149
  const nameDepartmentUrl = `${DEPARTMENT_API_URL}?nom=${searchValue}&fields=region,codeRegion&limit=21`;
137
- const signal = (options === null || options === void 0 ? void 0 : options.signal) || getSignal(controller$2);
150
+ const signal = (options === null || options === void 0 ? void 0 : options.signal) || getSignal();
138
151
  const departmentResponse = yield customFetch(nameDepartmentUrl, Object.assign(Object.assign({}, options), { signal }));
139
152
  const departmentResult = yield departmentResponse.json();
140
153
  return departmentResult.map(result => ({
@@ -163,7 +176,6 @@ function isStartsWith(arr, value) {
163
176
 
164
177
  const SPECIAL_CITIES = ['paris ', 'lyon ', 'marseille '];
165
178
  let CURRENT_RESULT = [];
166
- let controller$1 = null;
167
179
  const filterOnCurrentResult = (searchValue) => {
168
180
  const searchRegex = new RegExp(searchValue
169
181
  .split(' ')
@@ -179,13 +191,13 @@ const searchByMunicipality = (searchValue, options) => __awaiter(void 0, void 0,
179
191
  }
180
192
  CURRENT_RESULT = [];
181
193
  const url = `${MUNICIPALITY_API_URL}?nom=${searchValue}${FIELDS}${BOOST}&limit=${(options === null || options === void 0 ? void 0 : options.limit) || 10}`;
182
- const signal = (options === null || options === void 0 ? void 0 : options.signal) || getSignal(controller$1);
194
+ const signal = (options === null || options === void 0 ? void 0 : options.signal) || getSignal();
183
195
  const cityResponse = yield customFetch(url, Object.assign(Object.assign({}, options), { signal }));
184
196
  const cityResult = yield cityResponse.json();
185
197
  // The first result is Paris, Lyon or Marseille, we want get all arrondissements
186
198
  if (cityResult.length > 0 && ['75', '13', '69'].includes(cityResult[0].codeDepartement)) {
187
199
  const url = `${MUNICIPALITY_API_URL}?nom=${searchValue}&codeDepartement=${cityResult[0].codeDepartement}${FIELDS}${BOOST}${TYPES}&limit=21`;
188
- const arrondissementsResponse = yield customFetch(url, options);
200
+ const arrondissementsResponse = yield customFetch(url);
189
201
  const arrondissementsResult = yield arrondissementsResponse.json();
190
202
  const filtredAndSortArrondissementsResult = arrondissementsResult
191
203
  .filter(item => item.codesPostaux.length === 1)
@@ -200,10 +212,9 @@ const searchByMunicipality = (searchValue, options) => __awaiter(void 0, void 0,
200
212
  return formatToMunicipalitySearchResult(filterCityResults(cityResult));
201
213
  });
202
214
 
203
- let controller = null;
204
215
  const searchByZipcode = (searchValue, options) => __awaiter(void 0, void 0, void 0, function* () {
205
216
  const url = `${MUNICIPALITY_API_URL}?codePostal=${searchValue}${FIELDS}${BOOST}${TYPES}`;
206
- const signal = (options === null || options === void 0 ? void 0 : options.signal) || getSignal(controller);
217
+ const signal = (options === null || options === void 0 ? void 0 : options.signal) || getSignal();
207
218
  const zipCodeResponse = yield customFetch(url, Object.assign(Object.assign({}, options), { signal }));
208
219
  const zipCodeResult = yield zipCodeResponse.json();
209
220
  const filtredZipCodeResult = zipCodeResult.filter(item => item.codesPostaux.length <= 1);
@@ -265,6 +276,7 @@ var searchByCountry = /*#__PURE__*/Object.freeze({
265
276
 
266
277
  const searchPlaces = (searchValue, options, searchType = ['city', 'zipcode', 'coordinates']) => __awaiter(void 0, void 0, void 0, function* () {
267
278
  if (!searchValue) {
279
+ getSignal();
268
280
  return [];
269
281
  }
270
282
  try {
@@ -291,8 +303,23 @@ const searchPlaces = (searchValue, options, searchType = ['city', 'zipcode', 'co
291
303
  return [];
292
304
  }
293
305
  });
294
- const searchDepartment = (searchValue, options) => searchByDepartment(searchValue, options);
295
- const searchAddress = (searchValue, options) => searchByAddress(searchValue, options);
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
+ });
296
323
  /* Deprecated names */
297
324
  /**
298
325
  * @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;AAelE,eAAO,MAAM,eAAe,gBACb,MAAM,YACT,kBAAkB,KAC3B,QAAQ,mBAAmB,EAAE,CAuB/B,CAAA"}
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 +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;AAI9F,eAAO,MAAM,mBAAmB,4BACL,OAAO,YACtB,kBAAkB,KAC3B,QAAQ,wBAAwB,EAAE,CAiBpC,CAAA"}
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"}
@@ -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;AAIjB,eAAO,MAAM,kBAAkB,gBAChB,MAAM,YACT,kBAAkB,KAC3B,QAAQ,sBAAsB,EAAE,CA4BlC,CAAA"}
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 +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;AAqBrF,eAAO,MAAM,oBAAoB,gBAClB,MAAM,YACT,kBAAkB,KAC3B,QAAQ,wBAAwB,EAAE,CAqCpC,CAAA"}
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 +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;AAIrF,eAAO,MAAM,eAAe,gBACb,MAAM,YACT,kBAAkB,KAC3B,QAAQ,wBAAwB,EAAE,CAUpC,CAAA"}
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"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pretto/places",
3
- "version": "0.33.0",
3
+ "version": "0.37.0",
4
4
  "description": "",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",