@pretto/places 0.2.0 → 0.6.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/addressSearch.d.ts +1 -1
- package/dist/addressSearch.d.ts.map +1 -1
- package/dist/countrySearch.d.ts +1 -1
- package/dist/countrySearch.d.ts.map +1 -1
- package/dist/index.js +90 -40
- package/dist/module.js +90 -40
- package/dist/municipalitySearch.d.ts +8 -3
- package/dist/municipalitySearch.d.ts.map +1 -1
- package/dist/utils.d.ts +1 -1
- package/dist/utils.d.ts.map +1 -1
- package/package.json +3 -2
package/dist/addressSearch.d.ts
CHANGED
@@ -20,7 +20,7 @@ interface Options {
|
|
20
20
|
country: string;
|
21
21
|
limit: number;
|
22
22
|
}
|
23
|
-
declare type AddressSearch = (search: string, options?: Options) => Promise<AddressSearchResult[]>;
|
23
|
+
declare type AddressSearch = (search: string, options?: Options) => Promise<AddressSearchResult[] | string>;
|
24
24
|
export declare const get: AddressSearch;
|
25
25
|
export {};
|
26
26
|
//# sourceMappingURL=addressSearch.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"addressSearch.d.ts","sourceRoot":"","sources":["../src/addressSearch.ts"],"names":[],"mappings":"AAAA,UAAU,mBAAmB;IAC3B,KAAK,EAAE,MAAM,CAAA;IACb,KAAK,EAAE;QACL,IAAI,EAAE,MAAM,CAAA;QACZ,OAAO,EAAE,MAAM,CAAA;QACf,MAAM,EAAE,MAAM,CAAA;QACd,OAAO,EAAE,MAAM,CAAA;KAChB,CAAA;CACF;AAED,MAAM,WAAW,gBAAgB;IAC/B,UAAU,EAAE;QACV,KAAK,EAAE,MAAM,CAAA;QACb,QAAQ,EAAE,MAAM,CAAA;QAChB,IAAI,EAAE,MAAM,CAAA;QACZ,WAAW,EAAE,MAAM,CAAA;QACnB,MAAM,EAAE,MAAM,CAAA;KACf,CAAA;CACF;AAED,UAAU,OAAO;IACf,OAAO,EAAE,MAAM,CAAA;IACf,KAAK,EAAE,MAAM,CAAA;CACd;AAED,aAAK,aAAa,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,KAAK,OAAO,CAAC,mBAAmB,EAAE,CAAC,CAAA;
|
1
|
+
{"version":3,"file":"addressSearch.d.ts","sourceRoot":"","sources":["../src/addressSearch.ts"],"names":[],"mappings":"AAAA,UAAU,mBAAmB;IAC3B,KAAK,EAAE,MAAM,CAAA;IACb,KAAK,EAAE;QACL,IAAI,EAAE,MAAM,CAAA;QACZ,OAAO,EAAE,MAAM,CAAA;QACf,MAAM,EAAE,MAAM,CAAA;QACd,OAAO,EAAE,MAAM,CAAA;KAChB,CAAA;CACF;AAED,MAAM,WAAW,gBAAgB;IAC/B,UAAU,EAAE;QACV,KAAK,EAAE,MAAM,CAAA;QACb,QAAQ,EAAE,MAAM,CAAA;QAChB,IAAI,EAAE,MAAM,CAAA;QACZ,WAAW,EAAE,MAAM,CAAA;QACnB,MAAM,EAAE,MAAM,CAAA;KACf,CAAA;CACF;AAED,UAAU,OAAO;IACf,OAAO,EAAE,MAAM,CAAA;IACf,KAAK,EAAE,MAAM,CAAA;CACd;AAED,aAAK,aAAa,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,KAAK,OAAO,CAAC,mBAAmB,EAAE,GAAG,MAAM,CAAC,CAAA;AAEnG,eAAO,MAAM,GAAG,EAAE,aA4BjB,CAAA"}
|
package/dist/countrySearch.d.ts
CHANGED
@@ -12,7 +12,7 @@ export interface CountriesApiResult {
|
|
12
12
|
interface Options {
|
13
13
|
limit: number;
|
14
14
|
}
|
15
|
-
export declare const init: (appId: string, apiKey: string, options?: AlgoliaSearchOptions | undefined) => {
|
15
|
+
export declare const init: (appId: string, apiKey: string, options?: AlgoliaSearchOptions | undefined) => "An error occurred." | {
|
16
16
|
get(search: string, options?: Options | undefined): Promise<CountriesSearchResult[]>;
|
17
17
|
};
|
18
18
|
export {};
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"countrySearch.d.ts","sourceRoot":"","sources":["../src/countrySearch.ts"],"names":[],"mappings":"AAAA,OAAsB,EAAE,oBAAoB,EAAgB,MAAM,eAAe,CAAA;AAIjF,UAAU,qBAAqB;IAC7B,KAAK,EAAE,MAAM,CAAA;IACb,KAAK,EAAE,MAAM,CAAA;CACd;AAED,MAAM,WAAW,kBAAkB;IACjC,QAAQ,EAAE,MAAM,CAAA;IAChB,GAAG,EAAE,MAAM,CAAA;IACX,MAAM,EAAE,MAAM,CAAA;IACd,MAAM,EAAE,MAAM,CAAA;CACf;AAED,UAAU,OAAO;IACf,KAAK,EAAE,MAAM,CAAA;CACd;AAsBD,eAAO,MAAM,IAAI,UAAW,MAAM,UAAU,MAAM;gBAK1B,MAAM;
|
1
|
+
{"version":3,"file":"countrySearch.d.ts","sourceRoot":"","sources":["../src/countrySearch.ts"],"names":[],"mappings":"AAAA,OAAsB,EAAE,oBAAoB,EAAgB,MAAM,eAAe,CAAA;AAIjF,UAAU,qBAAqB;IAC7B,KAAK,EAAE,MAAM,CAAA;IACb,KAAK,EAAE,MAAM,CAAA;CACd;AAED,MAAM,WAAW,kBAAkB;IACjC,QAAQ,EAAE,MAAM,CAAA;IAChB,GAAG,EAAE,MAAM,CAAA;IACX,MAAM,EAAE,MAAM,CAAA;IACd,MAAM,EAAE,MAAM,CAAA;CACf;AAED,UAAU,OAAO;IACf,KAAK,EAAE,MAAM,CAAA;CACd;AAsBD,eAAO,MAAM,IAAI,UAAW,MAAM,UAAU,MAAM;gBAK1B,MAAM;CAS7B,CAAA"}
|
package/dist/index.js
CHANGED
@@ -46,14 +46,14 @@ const convertFirstLetterToUpperCase = (str) => {
|
|
46
46
|
return acc + curr;
|
47
47
|
}, '');
|
48
48
|
};
|
49
|
-
const getUri = (search,
|
49
|
+
const getUri = (search, departmentOnly) => {
|
50
50
|
const PLACES_API = 'https://geo.api.gouv.fr';
|
51
|
-
const QUERY_FIELDS =
|
51
|
+
const QUERY_FIELDS = `boost=population&fields=departement${departmentOnly ? '' : ',codesPostaux'}`;
|
52
52
|
const formatedSearch = encodeURIComponent(search);
|
53
53
|
const uri = {
|
54
|
-
departments: `${PLACES_API}/departements/${formatedSearch}/communes?${QUERY_FIELDS}
|
55
|
-
municipality: `${PLACES_API}/communes?nom=${formatedSearch}&${QUERY_FIELDS}
|
56
|
-
zipcode: `${PLACES_API}/communes?codePostal=${formatedSearch}&${QUERY_FIELDS}
|
54
|
+
departments: `${PLACES_API}/departements/${formatedSearch}/communes?${QUERY_FIELDS}`,
|
55
|
+
municipality: `${PLACES_API}/communes?nom=${formatedSearch}&${QUERY_FIELDS}`,
|
56
|
+
zipcode: `${PLACES_API}/communes?codePostal=${formatedSearch}&${QUERY_FIELDS}`,
|
57
57
|
};
|
58
58
|
if (isNaN(parseInt(search, 10)))
|
59
59
|
return uri.municipality;
|
@@ -63,40 +63,75 @@ const getUri = (search, limit) => {
|
|
63
63
|
let PREVIOUS_SEARCH = [];
|
64
64
|
let SEARCH_CACHE = [];
|
65
65
|
let PREVIOUS_VALUE = '';
|
66
|
-
const responseFormat = (places, country, search) => {
|
66
|
+
const responseFormat = (places, country, search, departmentOnly) => {
|
67
67
|
if (places.length === 0 || !places)
|
68
68
|
return [];
|
69
|
+
if (departmentOnly) {
|
70
|
+
return places.map(place => {
|
71
|
+
var _a, _b;
|
72
|
+
return {
|
73
|
+
label: `${place.nom}${!!((_a = place.departement) === null || _a === void 0 ? void 0 : _a.code) ? ` (${place.departement.code})` : ''}`,
|
74
|
+
value: {
|
75
|
+
city: place.nom,
|
76
|
+
country,
|
77
|
+
zipcode: ((_b = place.departement) === null || _b === void 0 ? void 0 : _b.code) || '',
|
78
|
+
},
|
79
|
+
};
|
80
|
+
});
|
81
|
+
}
|
69
82
|
if (!isNaN(parseInt(search, 10)) && search.length === 5 && places.length === 1) {
|
70
|
-
return [
|
83
|
+
return [
|
84
|
+
{
|
85
|
+
label: `${places[0].nom} (${search})`,
|
86
|
+
value: { city: places[0].nom, country, zipcode: search },
|
87
|
+
},
|
88
|
+
];
|
71
89
|
}
|
72
90
|
const allPlaces = places.map(place => {
|
73
91
|
return place.codesPostaux.reduce((acc, curr) => {
|
74
|
-
return [
|
92
|
+
return [
|
93
|
+
...acc,
|
94
|
+
{
|
95
|
+
label: `${place.nom} (${curr})`,
|
96
|
+
value: { city: place.nom, country, zipcode: curr },
|
97
|
+
},
|
98
|
+
];
|
75
99
|
}, []);
|
76
100
|
});
|
77
101
|
return flat__default["default"](allPlaces);
|
78
102
|
};
|
79
103
|
const get$2 = (search, options) => __awaiter(void 0, void 0, void 0, function* () {
|
104
|
+
const { country = 'fr', limit = 5, departmentOnly = false } = options || {};
|
80
105
|
const isNumber = !isNaN(parseInt(search, 10));
|
81
106
|
if (!search || (isNumber && search.length < 2))
|
82
107
|
return [];
|
83
|
-
if (isNumber && search.length > 2 && search.length < 5) {
|
84
|
-
return
|
108
|
+
if (isNumber && search.length > 2 && search.length < 5 && SEARCH_CACHE.length > 0) {
|
109
|
+
return SEARCH_CACHE.filter(i => i.value.zipcode.includes(search)).slice(0, limit);
|
85
110
|
}
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
const
|
92
|
-
|
111
|
+
try {
|
112
|
+
const response = yield fetch(getUri(search, departmentOnly));
|
113
|
+
if (!response.ok)
|
114
|
+
return Promise.reject(response);
|
115
|
+
const result = yield response.json();
|
116
|
+
const formatedResponse = responseFormat(result, country, search, departmentOnly);
|
117
|
+
if (isEqual__default["default"](PREVIOUS_SEARCH, formatedResponse)) {
|
118
|
+
const cleanValue = search.replace(' ', '').replace(PREVIOUS_VALUE, '');
|
119
|
+
return PREVIOUS_SEARCH.filter(i => i.label.includes(cleanValue)).slice(0, limit);
|
120
|
+
}
|
121
|
+
PREVIOUS_VALUE = search;
|
122
|
+
PREVIOUS_SEARCH = formatedResponse;
|
123
|
+
if (isNumber && search.length !== 5) {
|
124
|
+
SEARCH_CACHE = formatedResponse;
|
125
|
+
}
|
126
|
+
return formatedResponse.slice(0, limit);
|
93
127
|
}
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
128
|
+
catch (error) {
|
129
|
+
if (typeof error === 'string')
|
130
|
+
throw new Error(error);
|
131
|
+
if (error instanceof Error)
|
132
|
+
throw new Error((error === null || error === void 0 ? void 0 : error.message) || 'An error occurred.');
|
133
|
+
return 'An error occurred.';
|
98
134
|
}
|
99
|
-
return formatedResponse;
|
100
135
|
});
|
101
136
|
|
102
137
|
var municipalitySearch = /*#__PURE__*/Object.freeze({
|
@@ -107,21 +142,32 @@ var municipalitySearch = /*#__PURE__*/Object.freeze({
|
|
107
142
|
const get$1 = (search, options) => __awaiter(void 0, void 0, void 0, function* () {
|
108
143
|
if (!search)
|
109
144
|
return [];
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
145
|
+
try {
|
146
|
+
const { country = 'fr', limit = 5 } = options || {};
|
147
|
+
const format = encodeURIComponent(search);
|
148
|
+
const response = yield fetch(`https://api-adresse.data.gouv.fr/search/?q=${format}&autocomplete=1&limit=${limit}`);
|
149
|
+
if (!response.ok)
|
150
|
+
return Promise.reject(response);
|
151
|
+
const result = yield response.json();
|
152
|
+
return result.features.map(({ properties }) => {
|
153
|
+
return {
|
154
|
+
label: `${properties.label} (${properties.postcode})`,
|
155
|
+
value: {
|
156
|
+
city: properties.city,
|
157
|
+
country,
|
158
|
+
street: `${properties.housenumber} ${properties.street}`,
|
159
|
+
zipcode: properties.postcode,
|
160
|
+
},
|
161
|
+
};
|
162
|
+
});
|
163
|
+
}
|
164
|
+
catch (error) {
|
165
|
+
if (typeof error === 'string')
|
166
|
+
throw new Error(error);
|
167
|
+
if (error instanceof Error)
|
168
|
+
throw new Error((error === null || error === void 0 ? void 0 : error.message) || 'An error occurred.');
|
169
|
+
return 'An error occurred.';
|
170
|
+
}
|
125
171
|
});
|
126
172
|
|
127
173
|
var addressSearch = /*#__PURE__*/Object.freeze({
|
@@ -139,8 +185,8 @@ const get = (instance, search, options) => __awaiter(void 0, void 0, void 0, fun
|
|
139
185
|
return data.hits.reduce((acc, { codeiso2, cog, libcog, libenr }) => {
|
140
186
|
if (codeiso2 === '')
|
141
187
|
return acc;
|
142
|
-
const formatCountryName = convertFirstLetterToUpperCase(libcog.
|
143
|
-
const formatCog = cog.
|
188
|
+
const formatCountryName = convertFirstLetterToUpperCase(libcog.includes('(') ? libenr : libcog);
|
189
|
+
const formatCog = !cog.includes('X') ? `(${cog})` : '';
|
144
190
|
const label = `${formatCountryName} ${formatCog}`;
|
145
191
|
return [...acc, { label, value: codeiso2.toLowerCase() }];
|
146
192
|
}, []);
|
@@ -157,7 +203,11 @@ const init = (appId, apiKey, options) => {
|
|
157
203
|
};
|
158
204
|
}
|
159
205
|
catch (error) {
|
160
|
-
|
206
|
+
if (typeof error === 'string')
|
207
|
+
throw new Error(error);
|
208
|
+
if (error instanceof Error)
|
209
|
+
throw new Error((error === null || error === void 0 ? void 0 : error.message) || 'An error occurred.');
|
210
|
+
return 'An error occurred.';
|
161
211
|
}
|
162
212
|
};
|
163
213
|
|
package/dist/module.js
CHANGED
@@ -36,14 +36,14 @@ const convertFirstLetterToUpperCase = (str) => {
|
|
36
36
|
return acc + curr;
|
37
37
|
}, '');
|
38
38
|
};
|
39
|
-
const getUri = (search,
|
39
|
+
const getUri = (search, departmentOnly) => {
|
40
40
|
const PLACES_API = 'https://geo.api.gouv.fr';
|
41
|
-
const QUERY_FIELDS =
|
41
|
+
const QUERY_FIELDS = `boost=population&fields=departement${departmentOnly ? '' : ',codesPostaux'}`;
|
42
42
|
const formatedSearch = encodeURIComponent(search);
|
43
43
|
const uri = {
|
44
|
-
departments: `${PLACES_API}/departements/${formatedSearch}/communes?${QUERY_FIELDS}
|
45
|
-
municipality: `${PLACES_API}/communes?nom=${formatedSearch}&${QUERY_FIELDS}
|
46
|
-
zipcode: `${PLACES_API}/communes?codePostal=${formatedSearch}&${QUERY_FIELDS}
|
44
|
+
departments: `${PLACES_API}/departements/${formatedSearch}/communes?${QUERY_FIELDS}`,
|
45
|
+
municipality: `${PLACES_API}/communes?nom=${formatedSearch}&${QUERY_FIELDS}`,
|
46
|
+
zipcode: `${PLACES_API}/communes?codePostal=${formatedSearch}&${QUERY_FIELDS}`,
|
47
47
|
};
|
48
48
|
if (isNaN(parseInt(search, 10)))
|
49
49
|
return uri.municipality;
|
@@ -53,40 +53,75 @@ const getUri = (search, limit) => {
|
|
53
53
|
let PREVIOUS_SEARCH = [];
|
54
54
|
let SEARCH_CACHE = [];
|
55
55
|
let PREVIOUS_VALUE = '';
|
56
|
-
const responseFormat = (places, country, search) => {
|
56
|
+
const responseFormat = (places, country, search, departmentOnly) => {
|
57
57
|
if (places.length === 0 || !places)
|
58
58
|
return [];
|
59
|
+
if (departmentOnly) {
|
60
|
+
return places.map(place => {
|
61
|
+
var _a, _b;
|
62
|
+
return {
|
63
|
+
label: `${place.nom}${!!((_a = place.departement) === null || _a === void 0 ? void 0 : _a.code) ? ` (${place.departement.code})` : ''}`,
|
64
|
+
value: {
|
65
|
+
city: place.nom,
|
66
|
+
country,
|
67
|
+
zipcode: ((_b = place.departement) === null || _b === void 0 ? void 0 : _b.code) || '',
|
68
|
+
},
|
69
|
+
};
|
70
|
+
});
|
71
|
+
}
|
59
72
|
if (!isNaN(parseInt(search, 10)) && search.length === 5 && places.length === 1) {
|
60
|
-
return [
|
73
|
+
return [
|
74
|
+
{
|
75
|
+
label: `${places[0].nom} (${search})`,
|
76
|
+
value: { city: places[0].nom, country, zipcode: search },
|
77
|
+
},
|
78
|
+
];
|
61
79
|
}
|
62
80
|
const allPlaces = places.map(place => {
|
63
81
|
return place.codesPostaux.reduce((acc, curr) => {
|
64
|
-
return [
|
82
|
+
return [
|
83
|
+
...acc,
|
84
|
+
{
|
85
|
+
label: `${place.nom} (${curr})`,
|
86
|
+
value: { city: place.nom, country, zipcode: curr },
|
87
|
+
},
|
88
|
+
];
|
65
89
|
}, []);
|
66
90
|
});
|
67
91
|
return flat(allPlaces);
|
68
92
|
};
|
69
93
|
const get$2 = (search, options) => __awaiter(void 0, void 0, void 0, function* () {
|
94
|
+
const { country = 'fr', limit = 5, departmentOnly = false } = options || {};
|
70
95
|
const isNumber = !isNaN(parseInt(search, 10));
|
71
96
|
if (!search || (isNumber && search.length < 2))
|
72
97
|
return [];
|
73
|
-
if (isNumber && search.length > 2 && search.length < 5) {
|
74
|
-
return
|
98
|
+
if (isNumber && search.length > 2 && search.length < 5 && SEARCH_CACHE.length > 0) {
|
99
|
+
return SEARCH_CACHE.filter(i => i.value.zipcode.includes(search)).slice(0, limit);
|
75
100
|
}
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
const
|
82
|
-
|
101
|
+
try {
|
102
|
+
const response = yield fetch(getUri(search, departmentOnly));
|
103
|
+
if (!response.ok)
|
104
|
+
return Promise.reject(response);
|
105
|
+
const result = yield response.json();
|
106
|
+
const formatedResponse = responseFormat(result, country, search, departmentOnly);
|
107
|
+
if (isEqual(PREVIOUS_SEARCH, formatedResponse)) {
|
108
|
+
const cleanValue = search.replace(' ', '').replace(PREVIOUS_VALUE, '');
|
109
|
+
return PREVIOUS_SEARCH.filter(i => i.label.includes(cleanValue)).slice(0, limit);
|
110
|
+
}
|
111
|
+
PREVIOUS_VALUE = search;
|
112
|
+
PREVIOUS_SEARCH = formatedResponse;
|
113
|
+
if (isNumber && search.length !== 5) {
|
114
|
+
SEARCH_CACHE = formatedResponse;
|
115
|
+
}
|
116
|
+
return formatedResponse.slice(0, limit);
|
83
117
|
}
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
118
|
+
catch (error) {
|
119
|
+
if (typeof error === 'string')
|
120
|
+
throw new Error(error);
|
121
|
+
if (error instanceof Error)
|
122
|
+
throw new Error((error === null || error === void 0 ? void 0 : error.message) || 'An error occurred.');
|
123
|
+
return 'An error occurred.';
|
88
124
|
}
|
89
|
-
return formatedResponse;
|
90
125
|
});
|
91
126
|
|
92
127
|
var municipalitySearch = /*#__PURE__*/Object.freeze({
|
@@ -97,21 +132,32 @@ var municipalitySearch = /*#__PURE__*/Object.freeze({
|
|
97
132
|
const get$1 = (search, options) => __awaiter(void 0, void 0, void 0, function* () {
|
98
133
|
if (!search)
|
99
134
|
return [];
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
135
|
+
try {
|
136
|
+
const { country = 'fr', limit = 5 } = options || {};
|
137
|
+
const format = encodeURIComponent(search);
|
138
|
+
const response = yield fetch(`https://api-adresse.data.gouv.fr/search/?q=${format}&autocomplete=1&limit=${limit}`);
|
139
|
+
if (!response.ok)
|
140
|
+
return Promise.reject(response);
|
141
|
+
const result = yield response.json();
|
142
|
+
return result.features.map(({ properties }) => {
|
143
|
+
return {
|
144
|
+
label: `${properties.label} (${properties.postcode})`,
|
145
|
+
value: {
|
146
|
+
city: properties.city,
|
147
|
+
country,
|
148
|
+
street: `${properties.housenumber} ${properties.street}`,
|
149
|
+
zipcode: properties.postcode,
|
150
|
+
},
|
151
|
+
};
|
152
|
+
});
|
153
|
+
}
|
154
|
+
catch (error) {
|
155
|
+
if (typeof error === 'string')
|
156
|
+
throw new Error(error);
|
157
|
+
if (error instanceof Error)
|
158
|
+
throw new Error((error === null || error === void 0 ? void 0 : error.message) || 'An error occurred.');
|
159
|
+
return 'An error occurred.';
|
160
|
+
}
|
115
161
|
});
|
116
162
|
|
117
163
|
var addressSearch = /*#__PURE__*/Object.freeze({
|
@@ -129,8 +175,8 @@ const get = (instance, search, options) => __awaiter(void 0, void 0, void 0, fun
|
|
129
175
|
return data.hits.reduce((acc, { codeiso2, cog, libcog, libenr }) => {
|
130
176
|
if (codeiso2 === '')
|
131
177
|
return acc;
|
132
|
-
const formatCountryName = convertFirstLetterToUpperCase(libcog.
|
133
|
-
const formatCog = cog.
|
178
|
+
const formatCountryName = convertFirstLetterToUpperCase(libcog.includes('(') ? libenr : libcog);
|
179
|
+
const formatCog = !cog.includes('X') ? `(${cog})` : '';
|
134
180
|
const label = `${formatCountryName} ${formatCog}`;
|
135
181
|
return [...acc, { label, value: codeiso2.toLowerCase() }];
|
136
182
|
}, []);
|
@@ -147,7 +193,11 @@ const init = (appId, apiKey, options) => {
|
|
147
193
|
};
|
148
194
|
}
|
149
195
|
catch (error) {
|
150
|
-
|
196
|
+
if (typeof error === 'string')
|
197
|
+
throw new Error(error);
|
198
|
+
if (error instanceof Error)
|
199
|
+
throw new Error((error === null || error === void 0 ? void 0 : error.message) || 'An error occurred.');
|
200
|
+
return 'An error occurred.';
|
151
201
|
}
|
152
202
|
};
|
153
203
|
|
@@ -8,13 +8,18 @@ interface MunicipalitySearchResult {
|
|
8
8
|
}
|
9
9
|
export interface MunicipalityApiResult {
|
10
10
|
nom: string;
|
11
|
+
departement?: {
|
12
|
+
code: string;
|
13
|
+
nom: string;
|
14
|
+
};
|
11
15
|
codesPostaux: string[];
|
12
16
|
}
|
13
17
|
interface Options {
|
14
|
-
country
|
15
|
-
limit
|
18
|
+
country?: string;
|
19
|
+
limit?: number;
|
20
|
+
departmentOnly?: boolean;
|
16
21
|
}
|
17
|
-
declare type MunicipalitySearch = (search: string, options?: Options) => Promise<MunicipalitySearchResult[]>;
|
22
|
+
declare type MunicipalitySearch = (search: string, options?: Options) => Promise<MunicipalitySearchResult[] | string>;
|
18
23
|
export declare const get: MunicipalitySearch;
|
19
24
|
export {};
|
20
25
|
//# sourceMappingURL=municipalitySearch.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"municipalitySearch.d.ts","sourceRoot":"","sources":["../src/municipalitySearch.ts"],"names":[],"mappings":"AAKA,UAAU,wBAAwB;IAChC,KAAK,EAAE,MAAM,CAAA;IACb,KAAK,EAAE;QACL,IAAI,EAAE,MAAM,CAAA;QACZ,OAAO,EAAE,MAAM,CAAA;QACf,OAAO,EAAE,MAAM,CAAA;KAChB,CAAA;CACF;AAED,MAAM,WAAW,qBAAqB;IACpC,GAAG,EAAE,MAAM,CAAA;IACX,YAAY,EAAE,MAAM,EAAE,CAAA;CACvB;AAED,UAAU,OAAO;IACf,OAAO,EAAE,MAAM,CAAA;
|
1
|
+
{"version":3,"file":"municipalitySearch.d.ts","sourceRoot":"","sources":["../src/municipalitySearch.ts"],"names":[],"mappings":"AAKA,UAAU,wBAAwB;IAChC,KAAK,EAAE,MAAM,CAAA;IACb,KAAK,EAAE;QACL,IAAI,EAAE,MAAM,CAAA;QACZ,OAAO,EAAE,MAAM,CAAA;QACf,OAAO,EAAE,MAAM,CAAA;KAChB,CAAA;CACF;AAED,MAAM,WAAW,qBAAqB;IACpC,GAAG,EAAE,MAAM,CAAA;IACX,WAAW,CAAC,EAAE;QACZ,IAAI,EAAE,MAAM,CAAA;QACZ,GAAG,EAAE,MAAM,CAAA;KACZ,CAAA;IACD,YAAY,EAAE,MAAM,EAAE,CAAA;CACvB;AAED,UAAU,OAAO;IACf,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,cAAc,CAAC,EAAE,OAAO,CAAA;CACzB;AAED,aAAK,kBAAkB,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,KAAK,OAAO,CAAC,wBAAwB,EAAE,GAAG,MAAM,CAAC,CAAA;AAmD7G,eAAO,MAAM,GAAG,EAAE,kBAoCjB,CAAA"}
|
package/dist/utils.d.ts
CHANGED
package/dist/utils.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,6BAA6B,QAAS,MAAM,WAMxD,CAAA;AAED,eAAO,MAAM,MAAM,WAAY,MAAM,
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,6BAA6B,QAAS,MAAM,WAMxD,CAAA;AAED,eAAO,MAAM,MAAM,WAAY,MAAM,kBAAkB,OAAO,WAa7D,CAAA"}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@pretto/places",
|
3
|
-
"version": "0.
|
3
|
+
"version": "0.6.0",
|
4
4
|
"description": "",
|
5
5
|
"main": "./dist/index.js",
|
6
6
|
"types": "./dist/index.d.ts",
|
@@ -15,15 +15,16 @@
|
|
15
15
|
"dist/**/*"
|
16
16
|
],
|
17
17
|
"dependencies": {
|
18
|
-
"@types/array.prototype.flat": "^1.2.1",
|
19
18
|
"algoliasearch": "^4.13.0",
|
20
19
|
"array.prototype.flat": "^1.3.0",
|
21
20
|
"lodash.isequal": "^4.5.0"
|
22
21
|
},
|
23
22
|
"devDependencies": {
|
24
23
|
"@rollup/plugin-typescript": "^8.3.2",
|
24
|
+
"@types/array.prototype.flat": "^1.2.1",
|
25
25
|
"@types/lodash.isequal": "^4.5.5",
|
26
26
|
"deepmerge": "^4.2.2",
|
27
|
+
"eslint": "^8.14.0",
|
27
28
|
"rimraf": "^3.0.2",
|
28
29
|
"rollup": "^2.70.2",
|
29
30
|
"tslib": "^2.3.1",
|