@pretto/places 0.2.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 +26 -0
- package/dist/addressSearch.d.ts.map +1 -0
- package/dist/countrySearch.d.ts +19 -0
- package/dist/countrySearch.d.ts.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +171 -0
- package/dist/module.js +159 -0
- package/dist/municipalitySearch.d.ts +20 -0
- package/dist/municipalitySearch.d.ts.map +1 -0
- package/dist/utils.d.ts +3 -0
- package/dist/utils.d.ts.map +1 -0
- package/package.json +32 -0
@@ -0,0 +1,26 @@
|
|
1
|
+
interface AddressSearchResult {
|
2
|
+
label: string;
|
3
|
+
value: {
|
4
|
+
city: string;
|
5
|
+
country: string;
|
6
|
+
street: string;
|
7
|
+
zipcode: string;
|
8
|
+
};
|
9
|
+
}
|
10
|
+
export interface AddressApiResult {
|
11
|
+
properties: {
|
12
|
+
label: string;
|
13
|
+
postcode: string;
|
14
|
+
city: string;
|
15
|
+
housenumber: string;
|
16
|
+
street: string;
|
17
|
+
};
|
18
|
+
}
|
19
|
+
interface Options {
|
20
|
+
country: string;
|
21
|
+
limit: number;
|
22
|
+
}
|
23
|
+
declare type AddressSearch = (search: string, options?: Options) => Promise<AddressSearchResult[]>;
|
24
|
+
export declare const get: AddressSearch;
|
25
|
+
export {};
|
26
|
+
//# sourceMappingURL=addressSearch.d.ts.map
|
@@ -0,0 +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;AAE1F,eAAO,MAAM,GAAG,EAAE,aAmBjB,CAAA"}
|
@@ -0,0 +1,19 @@
|
|
1
|
+
import { AlgoliaSearchOptions } from 'algoliasearch';
|
2
|
+
interface CountriesSearchResult {
|
3
|
+
label: string;
|
4
|
+
value: string;
|
5
|
+
}
|
6
|
+
export interface CountriesApiResult {
|
7
|
+
codeiso2: string;
|
8
|
+
cog: string;
|
9
|
+
libcog: string;
|
10
|
+
libenr: string;
|
11
|
+
}
|
12
|
+
interface Options {
|
13
|
+
limit: number;
|
14
|
+
}
|
15
|
+
export declare const init: (appId: string, apiKey: string, options?: AlgoliaSearchOptions | undefined) => {
|
16
|
+
get(search: string, options?: Options | undefined): Promise<CountriesSearchResult[]>;
|
17
|
+
};
|
18
|
+
export {};
|
19
|
+
//# sourceMappingURL=countrySearch.d.ts.map
|
@@ -0,0 +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;CAO7B,CAAA"}
|
package/dist/index.d.ts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,kBAAkB,MAAM,sBAAsB,CAAA;AAC1D,OAAO,KAAK,aAAa,MAAM,iBAAiB,CAAA;AAChD,OAAO,KAAK,aAAa,MAAM,iBAAiB,CAAA"}
|
package/dist/index.js
ADDED
@@ -0,0 +1,171 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
4
|
+
|
5
|
+
var flat = require('array.prototype.flat');
|
6
|
+
var isEqual = require('lodash.isequal');
|
7
|
+
var algoliasearch = require('algoliasearch');
|
8
|
+
|
9
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
10
|
+
|
11
|
+
var flat__default = /*#__PURE__*/_interopDefaultLegacy(flat);
|
12
|
+
var isEqual__default = /*#__PURE__*/_interopDefaultLegacy(isEqual);
|
13
|
+
var algoliasearch__default = /*#__PURE__*/_interopDefaultLegacy(algoliasearch);
|
14
|
+
|
15
|
+
/*! *****************************************************************************
|
16
|
+
Copyright (c) Microsoft Corporation.
|
17
|
+
|
18
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
19
|
+
purpose with or without fee is hereby granted.
|
20
|
+
|
21
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
22
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
23
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
24
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
25
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
26
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
27
|
+
PERFORMANCE OF THIS SOFTWARE.
|
28
|
+
***************************************************************************** */
|
29
|
+
|
30
|
+
function __awaiter(thisArg, _arguments, P, generator) {
|
31
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
32
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
33
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
34
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
35
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
36
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
37
|
+
});
|
38
|
+
}
|
39
|
+
|
40
|
+
const convertFirstLetterToUpperCase = (str) => {
|
41
|
+
return [...str.toLowerCase()].reduce((acc, curr, idx, array) => {
|
42
|
+
if (idx === 0)
|
43
|
+
return curr.toUpperCase();
|
44
|
+
if ([' ', '-', '('].indexOf(array[idx - 1]) !== -1)
|
45
|
+
return acc + curr.toUpperCase();
|
46
|
+
return acc + curr;
|
47
|
+
}, '');
|
48
|
+
};
|
49
|
+
const getUri = (search, limit) => {
|
50
|
+
const PLACES_API = 'https://geo.api.gouv.fr';
|
51
|
+
const QUERY_FIELDS = 'fields=departement,codesPostaux&boost=population';
|
52
|
+
const formatedSearch = encodeURIComponent(search);
|
53
|
+
const uri = {
|
54
|
+
departments: `${PLACES_API}/departements/${formatedSearch}/communes?${QUERY_FIELDS}&limit=${limit}`,
|
55
|
+
municipality: `${PLACES_API}/communes?nom=${formatedSearch}&${QUERY_FIELDS}&limit=${limit}`,
|
56
|
+
zipcode: `${PLACES_API}/communes?codePostal=${formatedSearch}&${QUERY_FIELDS}&limit=${limit}`,
|
57
|
+
};
|
58
|
+
if (isNaN(parseInt(search, 10)))
|
59
|
+
return uri.municipality;
|
60
|
+
return search.length === 5 ? uri.zipcode : uri.departments;
|
61
|
+
};
|
62
|
+
|
63
|
+
let PREVIOUS_SEARCH = [];
|
64
|
+
let SEARCH_CACHE = [];
|
65
|
+
let PREVIOUS_VALUE = '';
|
66
|
+
const responseFormat = (places, country, search) => {
|
67
|
+
if (places.length === 0 || !places)
|
68
|
+
return [];
|
69
|
+
if (!isNaN(parseInt(search, 10)) && search.length === 5 && places.length === 1) {
|
70
|
+
return [{ label: `${places[0].nom} (${search})`, value: { city: places[0].nom, country, zipcode: search } }];
|
71
|
+
}
|
72
|
+
const allPlaces = places.map(place => {
|
73
|
+
return place.codesPostaux.reduce((acc, curr) => {
|
74
|
+
return [...acc, { label: `${place.nom} (${curr})`, value: { city: place.nom, country, zipcode: curr } }];
|
75
|
+
}, []);
|
76
|
+
});
|
77
|
+
return flat__default["default"](allPlaces);
|
78
|
+
};
|
79
|
+
const get$2 = (search, options) => __awaiter(void 0, void 0, void 0, function* () {
|
80
|
+
const isNumber = !isNaN(parseInt(search, 10));
|
81
|
+
if (!search || (isNumber && search.length < 2))
|
82
|
+
return [];
|
83
|
+
if (isNumber && search.length > 2 && search.length < 5) {
|
84
|
+
return Array.from(SEARCH_CACHE).filter(i => i.value.zipcode.indexOf(search) !== -1);
|
85
|
+
}
|
86
|
+
const { country = 'fr', limit = 5 } = options || {};
|
87
|
+
const response = yield fetch(getUri(search, limit));
|
88
|
+
const result = yield response.json();
|
89
|
+
const formatedResponse = responseFormat(result, country, search);
|
90
|
+
if (isEqual__default["default"](PREVIOUS_SEARCH, formatedResponse)) {
|
91
|
+
const cleanValue = search.replace(' ', '').replace(PREVIOUS_VALUE, '');
|
92
|
+
return Array.from(PREVIOUS_SEARCH).filter(i => i.label.indexOf(cleanValue) !== -1);
|
93
|
+
}
|
94
|
+
PREVIOUS_VALUE = search;
|
95
|
+
PREVIOUS_SEARCH = formatedResponse;
|
96
|
+
if (isNumber && search.length !== 5) {
|
97
|
+
SEARCH_CACHE = formatedResponse;
|
98
|
+
}
|
99
|
+
return formatedResponse;
|
100
|
+
});
|
101
|
+
|
102
|
+
var municipalitySearch = /*#__PURE__*/Object.freeze({
|
103
|
+
__proto__: null,
|
104
|
+
get: get$2
|
105
|
+
});
|
106
|
+
|
107
|
+
const get$1 = (search, options) => __awaiter(void 0, void 0, void 0, function* () {
|
108
|
+
if (!search)
|
109
|
+
return [];
|
110
|
+
const { country = 'fr', limit = 5 } = options || {};
|
111
|
+
const format = encodeURIComponent(search);
|
112
|
+
const response = yield fetch(`https://api-adresse.data.gouv.fr/search/?q=${format}&autocomplete=1&limit=${limit}`);
|
113
|
+
const result = yield response.json();
|
114
|
+
return result.features.map(({ properties }) => {
|
115
|
+
return {
|
116
|
+
label: `${properties.label} (${properties.postcode})`,
|
117
|
+
value: {
|
118
|
+
city: properties.city,
|
119
|
+
country,
|
120
|
+
street: `${properties.housenumber} ${properties.street}`,
|
121
|
+
zipcode: properties.postcode,
|
122
|
+
},
|
123
|
+
};
|
124
|
+
});
|
125
|
+
});
|
126
|
+
|
127
|
+
var addressSearch = /*#__PURE__*/Object.freeze({
|
128
|
+
__proto__: null,
|
129
|
+
get: get$1
|
130
|
+
});
|
131
|
+
|
132
|
+
const get = (instance, search, options) => __awaiter(void 0, void 0, void 0, function* () {
|
133
|
+
if (!search)
|
134
|
+
return [];
|
135
|
+
const { limit = 5 } = options || {};
|
136
|
+
const data = yield instance.initIndex('Countries').search(search, {
|
137
|
+
hitsPerPage: limit,
|
138
|
+
});
|
139
|
+
return data.hits.reduce((acc, { codeiso2, cog, libcog, libenr }) => {
|
140
|
+
if (codeiso2 === '')
|
141
|
+
return acc;
|
142
|
+
const formatCountryName = convertFirstLetterToUpperCase(libcog.indexOf('(') !== -1 ? libenr : libcog);
|
143
|
+
const formatCog = cog.indexOf('X') !== -1 ? `(${cog})` : '';
|
144
|
+
const label = `${formatCountryName} ${formatCog}`;
|
145
|
+
return [...acc, { label, value: codeiso2.toLowerCase() }];
|
146
|
+
}, []);
|
147
|
+
});
|
148
|
+
const init = (appId, apiKey, options) => {
|
149
|
+
try {
|
150
|
+
const ALGOLIA_COUNTRIES_API = algoliasearch__default["default"](appId, apiKey, options);
|
151
|
+
return {
|
152
|
+
get(search, options) {
|
153
|
+
return __awaiter(this, void 0, void 0, function* () {
|
154
|
+
return yield get(ALGOLIA_COUNTRIES_API, search, options);
|
155
|
+
});
|
156
|
+
},
|
157
|
+
};
|
158
|
+
}
|
159
|
+
catch (error) {
|
160
|
+
throw new Error((error === null || error === void 0 ? void 0 : error.message) || 'Invalid Application-ID or API key');
|
161
|
+
}
|
162
|
+
};
|
163
|
+
|
164
|
+
var countrySearch = /*#__PURE__*/Object.freeze({
|
165
|
+
__proto__: null,
|
166
|
+
init: init
|
167
|
+
});
|
168
|
+
|
169
|
+
exports.addressSearch = addressSearch;
|
170
|
+
exports.countrySearch = countrySearch;
|
171
|
+
exports.municipalitySearch = municipalitySearch;
|
package/dist/module.js
ADDED
@@ -0,0 +1,159 @@
|
|
1
|
+
import flat from 'array.prototype.flat';
|
2
|
+
import isEqual from 'lodash.isequal';
|
3
|
+
import algoliasearch from 'algoliasearch';
|
4
|
+
|
5
|
+
/*! *****************************************************************************
|
6
|
+
Copyright (c) Microsoft Corporation.
|
7
|
+
|
8
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
9
|
+
purpose with or without fee is hereby granted.
|
10
|
+
|
11
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
12
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
13
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
14
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
15
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
16
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
17
|
+
PERFORMANCE OF THIS SOFTWARE.
|
18
|
+
***************************************************************************** */
|
19
|
+
|
20
|
+
function __awaiter(thisArg, _arguments, P, generator) {
|
21
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
22
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
23
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
24
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
25
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
26
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
27
|
+
});
|
28
|
+
}
|
29
|
+
|
30
|
+
const convertFirstLetterToUpperCase = (str) => {
|
31
|
+
return [...str.toLowerCase()].reduce((acc, curr, idx, array) => {
|
32
|
+
if (idx === 0)
|
33
|
+
return curr.toUpperCase();
|
34
|
+
if ([' ', '-', '('].indexOf(array[idx - 1]) !== -1)
|
35
|
+
return acc + curr.toUpperCase();
|
36
|
+
return acc + curr;
|
37
|
+
}, '');
|
38
|
+
};
|
39
|
+
const getUri = (search, limit) => {
|
40
|
+
const PLACES_API = 'https://geo.api.gouv.fr';
|
41
|
+
const QUERY_FIELDS = 'fields=departement,codesPostaux&boost=population';
|
42
|
+
const formatedSearch = encodeURIComponent(search);
|
43
|
+
const uri = {
|
44
|
+
departments: `${PLACES_API}/departements/${formatedSearch}/communes?${QUERY_FIELDS}&limit=${limit}`,
|
45
|
+
municipality: `${PLACES_API}/communes?nom=${formatedSearch}&${QUERY_FIELDS}&limit=${limit}`,
|
46
|
+
zipcode: `${PLACES_API}/communes?codePostal=${formatedSearch}&${QUERY_FIELDS}&limit=${limit}`,
|
47
|
+
};
|
48
|
+
if (isNaN(parseInt(search, 10)))
|
49
|
+
return uri.municipality;
|
50
|
+
return search.length === 5 ? uri.zipcode : uri.departments;
|
51
|
+
};
|
52
|
+
|
53
|
+
let PREVIOUS_SEARCH = [];
|
54
|
+
let SEARCH_CACHE = [];
|
55
|
+
let PREVIOUS_VALUE = '';
|
56
|
+
const responseFormat = (places, country, search) => {
|
57
|
+
if (places.length === 0 || !places)
|
58
|
+
return [];
|
59
|
+
if (!isNaN(parseInt(search, 10)) && search.length === 5 && places.length === 1) {
|
60
|
+
return [{ label: `${places[0].nom} (${search})`, value: { city: places[0].nom, country, zipcode: search } }];
|
61
|
+
}
|
62
|
+
const allPlaces = places.map(place => {
|
63
|
+
return place.codesPostaux.reduce((acc, curr) => {
|
64
|
+
return [...acc, { label: `${place.nom} (${curr})`, value: { city: place.nom, country, zipcode: curr } }];
|
65
|
+
}, []);
|
66
|
+
});
|
67
|
+
return flat(allPlaces);
|
68
|
+
};
|
69
|
+
const get$2 = (search, options) => __awaiter(void 0, void 0, void 0, function* () {
|
70
|
+
const isNumber = !isNaN(parseInt(search, 10));
|
71
|
+
if (!search || (isNumber && search.length < 2))
|
72
|
+
return [];
|
73
|
+
if (isNumber && search.length > 2 && search.length < 5) {
|
74
|
+
return Array.from(SEARCH_CACHE).filter(i => i.value.zipcode.indexOf(search) !== -1);
|
75
|
+
}
|
76
|
+
const { country = 'fr', limit = 5 } = options || {};
|
77
|
+
const response = yield fetch(getUri(search, limit));
|
78
|
+
const result = yield response.json();
|
79
|
+
const formatedResponse = responseFormat(result, country, search);
|
80
|
+
if (isEqual(PREVIOUS_SEARCH, formatedResponse)) {
|
81
|
+
const cleanValue = search.replace(' ', '').replace(PREVIOUS_VALUE, '');
|
82
|
+
return Array.from(PREVIOUS_SEARCH).filter(i => i.label.indexOf(cleanValue) !== -1);
|
83
|
+
}
|
84
|
+
PREVIOUS_VALUE = search;
|
85
|
+
PREVIOUS_SEARCH = formatedResponse;
|
86
|
+
if (isNumber && search.length !== 5) {
|
87
|
+
SEARCH_CACHE = formatedResponse;
|
88
|
+
}
|
89
|
+
return formatedResponse;
|
90
|
+
});
|
91
|
+
|
92
|
+
var municipalitySearch = /*#__PURE__*/Object.freeze({
|
93
|
+
__proto__: null,
|
94
|
+
get: get$2
|
95
|
+
});
|
96
|
+
|
97
|
+
const get$1 = (search, options) => __awaiter(void 0, void 0, void 0, function* () {
|
98
|
+
if (!search)
|
99
|
+
return [];
|
100
|
+
const { country = 'fr', limit = 5 } = options || {};
|
101
|
+
const format = encodeURIComponent(search);
|
102
|
+
const response = yield fetch(`https://api-adresse.data.gouv.fr/search/?q=${format}&autocomplete=1&limit=${limit}`);
|
103
|
+
const result = yield response.json();
|
104
|
+
return result.features.map(({ properties }) => {
|
105
|
+
return {
|
106
|
+
label: `${properties.label} (${properties.postcode})`,
|
107
|
+
value: {
|
108
|
+
city: properties.city,
|
109
|
+
country,
|
110
|
+
street: `${properties.housenumber} ${properties.street}`,
|
111
|
+
zipcode: properties.postcode,
|
112
|
+
},
|
113
|
+
};
|
114
|
+
});
|
115
|
+
});
|
116
|
+
|
117
|
+
var addressSearch = /*#__PURE__*/Object.freeze({
|
118
|
+
__proto__: null,
|
119
|
+
get: get$1
|
120
|
+
});
|
121
|
+
|
122
|
+
const get = (instance, search, options) => __awaiter(void 0, void 0, void 0, function* () {
|
123
|
+
if (!search)
|
124
|
+
return [];
|
125
|
+
const { limit = 5 } = options || {};
|
126
|
+
const data = yield instance.initIndex('Countries').search(search, {
|
127
|
+
hitsPerPage: limit,
|
128
|
+
});
|
129
|
+
return data.hits.reduce((acc, { codeiso2, cog, libcog, libenr }) => {
|
130
|
+
if (codeiso2 === '')
|
131
|
+
return acc;
|
132
|
+
const formatCountryName = convertFirstLetterToUpperCase(libcog.indexOf('(') !== -1 ? libenr : libcog);
|
133
|
+
const formatCog = cog.indexOf('X') !== -1 ? `(${cog})` : '';
|
134
|
+
const label = `${formatCountryName} ${formatCog}`;
|
135
|
+
return [...acc, { label, value: codeiso2.toLowerCase() }];
|
136
|
+
}, []);
|
137
|
+
});
|
138
|
+
const init = (appId, apiKey, options) => {
|
139
|
+
try {
|
140
|
+
const ALGOLIA_COUNTRIES_API = algoliasearch(appId, apiKey, options);
|
141
|
+
return {
|
142
|
+
get(search, options) {
|
143
|
+
return __awaiter(this, void 0, void 0, function* () {
|
144
|
+
return yield get(ALGOLIA_COUNTRIES_API, search, options);
|
145
|
+
});
|
146
|
+
},
|
147
|
+
};
|
148
|
+
}
|
149
|
+
catch (error) {
|
150
|
+
throw new Error((error === null || error === void 0 ? void 0 : error.message) || 'Invalid Application-ID or API key');
|
151
|
+
}
|
152
|
+
};
|
153
|
+
|
154
|
+
var countrySearch = /*#__PURE__*/Object.freeze({
|
155
|
+
__proto__: null,
|
156
|
+
init: init
|
157
|
+
});
|
158
|
+
|
159
|
+
export { addressSearch, countrySearch, municipalitySearch };
|
@@ -0,0 +1,20 @@
|
|
1
|
+
interface MunicipalitySearchResult {
|
2
|
+
label: string;
|
3
|
+
value: {
|
4
|
+
city: string;
|
5
|
+
country: string;
|
6
|
+
zipcode: string;
|
7
|
+
};
|
8
|
+
}
|
9
|
+
export interface MunicipalityApiResult {
|
10
|
+
nom: string;
|
11
|
+
codesPostaux: string[];
|
12
|
+
}
|
13
|
+
interface Options {
|
14
|
+
country: string;
|
15
|
+
limit: number;
|
16
|
+
}
|
17
|
+
declare type MunicipalitySearch = (search: string, options?: Options) => Promise<MunicipalitySearchResult[]>;
|
18
|
+
export declare const get: MunicipalitySearch;
|
19
|
+
export {};
|
20
|
+
//# sourceMappingURL=municipalitySearch.d.ts.map
|
@@ -0,0 +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;IACf,KAAK,EAAE,MAAM,CAAA;CACd;AAED,aAAK,kBAAkB,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,KAAK,OAAO,CAAC,wBAAwB,EAAE,CAAC,CAAA;AA0BpG,eAAO,MAAM,GAAG,EAAE,kBA6BjB,CAAA"}
|
package/dist/utils.d.ts
ADDED
@@ -0,0 +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,SAAS,MAAM,WAanD,CAAA"}
|
package/package.json
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
{
|
2
|
+
"name": "@pretto/places",
|
3
|
+
"version": "0.2.0",
|
4
|
+
"description": "",
|
5
|
+
"main": "./dist/index.js",
|
6
|
+
"types": "./dist/index.d.ts",
|
7
|
+
"module": "./dist/module.js",
|
8
|
+
"scripts": {
|
9
|
+
"build": "rimraf dist && rollup --config rollup.config.ts --configPlugin typescript",
|
10
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
11
|
+
},
|
12
|
+
"author": "Pretto",
|
13
|
+
"license": "ISC",
|
14
|
+
"files": [
|
15
|
+
"dist/**/*"
|
16
|
+
],
|
17
|
+
"dependencies": {
|
18
|
+
"@types/array.prototype.flat": "^1.2.1",
|
19
|
+
"algoliasearch": "^4.13.0",
|
20
|
+
"array.prototype.flat": "^1.3.0",
|
21
|
+
"lodash.isequal": "^4.5.0"
|
22
|
+
},
|
23
|
+
"devDependencies": {
|
24
|
+
"@rollup/plugin-typescript": "^8.3.2",
|
25
|
+
"@types/lodash.isequal": "^4.5.5",
|
26
|
+
"deepmerge": "^4.2.2",
|
27
|
+
"rimraf": "^3.0.2",
|
28
|
+
"rollup": "^2.70.2",
|
29
|
+
"tslib": "^2.3.1",
|
30
|
+
"typescript": "^4.6.3"
|
31
|
+
}
|
32
|
+
}
|