@pretto/places 0.6.0 → 0.9.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/README.md +145 -0
- package/dist/addressSearch.d.ts.map +1 -1
- package/dist/index.js +15 -10
- package/dist/module.js +15 -10
- package/package.json +1 -1
package/README.md
ADDED
@@ -0,0 +1,145 @@
|
|
1
|
+
# @pretto/places
|
2
|
+
|
3
|
+
[](https://www.npmjs.com/package/@pretto/places)
|
4
|
+
|
5
|
+
Allows you to search for an address, a postcode or a French department.
|
6
|
+
You can also search a country.
|
7
|
+
|
8
|
+
## FAQ
|
9
|
+
|
10
|
+
### How to implement the library?
|
11
|
+
|
12
|
+
```sh
|
13
|
+
yarn add @pretto/places
|
14
|
+
```
|
15
|
+
|
16
|
+
For municipality and zipcode
|
17
|
+
|
18
|
+
```jsx
|
19
|
+
import { municipalitySearch } from '@pretto/places'
|
20
|
+
|
21
|
+
const result = await municipalitySearch.get("paris", { limit: 21 })
|
22
|
+
|
23
|
+
// expected result : Paris (75001), Paris (75002), Paris (75003), ..., Paris (75020)
|
24
|
+
// result object format :
|
25
|
+
[
|
26
|
+
{
|
27
|
+
"label": "Paris (75001)",
|
28
|
+
"value": {
|
29
|
+
"city": "Paris",
|
30
|
+
"country": "fr",
|
31
|
+
"zipcode": "75001"
|
32
|
+
}
|
33
|
+
},
|
34
|
+
{
|
35
|
+
"label": "Paris (75002)",
|
36
|
+
"value": {
|
37
|
+
"city": "Paris",
|
38
|
+
"country": "fr",
|
39
|
+
"zipcode": "75002"
|
40
|
+
}
|
41
|
+
},
|
42
|
+
...
|
43
|
+
]
|
44
|
+
```
|
45
|
+
|
46
|
+
For department only
|
47
|
+
|
48
|
+
```jsx
|
49
|
+
import { municipalitySearch } from '@pretto/places'
|
50
|
+
|
51
|
+
const result = await municipalitySearch.get("paris", { departmentOnly: true, limit: 21 })
|
52
|
+
|
53
|
+
// expected result : Paris (75), Parisot(81), Parisot (82), Cormeilles-en-Parisis (95), ...
|
54
|
+
// result object format :
|
55
|
+
[
|
56
|
+
{
|
57
|
+
"label": "Paris (75)",
|
58
|
+
"value": {
|
59
|
+
"city": "Paris",
|
60
|
+
"country": "fr",
|
61
|
+
"zipcode": "75"
|
62
|
+
}
|
63
|
+
},
|
64
|
+
{
|
65
|
+
"label": "Parisot (81)",
|
66
|
+
"value": {
|
67
|
+
"city": "Parisot",
|
68
|
+
"country": "fr",
|
69
|
+
"zipcode": "81"
|
70
|
+
}
|
71
|
+
},
|
72
|
+
...
|
73
|
+
]
|
74
|
+
```
|
75
|
+
|
76
|
+
For Address (France only)
|
77
|
+
|
78
|
+
```jsx
|
79
|
+
import { addressSearch } from '@pretto/places'
|
80
|
+
|
81
|
+
const result = await addressSearch.get("55 rue de paradis", { limit: 10 })
|
82
|
+
|
83
|
+
// expected result : 55 Rue de Paradis 75010 Paris (75010), 55 Rue de Paradis 51160 Hautvillers (51160)...
|
84
|
+
// result object format :
|
85
|
+
[
|
86
|
+
{
|
87
|
+
"label": "55 Rue de Paradis 75010 Paris (75010)",
|
88
|
+
"value": {
|
89
|
+
"city": "Paris",
|
90
|
+
"country": "fr",
|
91
|
+
"street": "55 Rue de Paradis",
|
92
|
+
"zipcode": "75010"
|
93
|
+
}
|
94
|
+
},
|
95
|
+
{
|
96
|
+
"label": "55 Rue de Paradis 51160 Hautvillers (51160)",
|
97
|
+
"value": {
|
98
|
+
"city": "Hautvillers",
|
99
|
+
"country": "fr",
|
100
|
+
"street": "55 Rue de Paradis",
|
101
|
+
"zipcode": "51160"
|
102
|
+
}
|
103
|
+
},
|
104
|
+
...
|
105
|
+
]
|
106
|
+
```
|
107
|
+
|
108
|
+
For country
|
109
|
+
|
110
|
+
```jsx
|
111
|
+
import { countrySearch } from '@pretto/places'
|
112
|
+
|
113
|
+
const countriesApi = countrySearch.init(ALGOLIA_COUNTRIES_APP_ID, ALGOLIA_COUNTRIES_API_KEY)
|
114
|
+
const results = await countriesApi.get("al", { limit: 10 })
|
115
|
+
|
116
|
+
// expected result : Allemagne (99109), Albanie (99125), Algerie (99352)
|
117
|
+
// result object format :
|
118
|
+
[
|
119
|
+
{
|
120
|
+
"label": "Allemagne (99109)",
|
121
|
+
"value": "de"
|
122
|
+
},
|
123
|
+
{
|
124
|
+
"label": "Albanie (99125)",
|
125
|
+
"value": "al"
|
126
|
+
},
|
127
|
+
{
|
128
|
+
"label": "Algerie (99352)",
|
129
|
+
"value": "dz"
|
130
|
+
}
|
131
|
+
]
|
132
|
+
```
|
133
|
+
|
134
|
+
### How to publish a new version?
|
135
|
+
|
136
|
+
When a branch is merged into master, it will automatically deploy a new version to npm.
|
137
|
+
|
138
|
+
### How it works?
|
139
|
+
|
140
|
+
This library is based on the API of data.gouv.
|
141
|
+
These data are quite precise and are regularly updated:
|
142
|
+

|
143
|
+
|
144
|
+
- https://adresse.data.gouv.fr/
|
145
|
+
- https://api.gouv.fr/
|
@@ -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,GAAG,MAAM,CAAC,CAAA;AAEnG,eAAO,MAAM,GAAG,EAAE,
|
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,aAiCjB,CAAA"}
|
package/dist/index.js
CHANGED
@@ -149,17 +149,22 @@ const get$1 = (search, options) => __awaiter(void 0, void 0, void 0, function* (
|
|
149
149
|
if (!response.ok)
|
150
150
|
return Promise.reject(response);
|
151
151
|
const result = yield response.json();
|
152
|
-
return result.features.
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
152
|
+
return result.features.reduce((acc, { properties }) => {
|
153
|
+
if (!properties.street)
|
154
|
+
return acc;
|
155
|
+
return [
|
156
|
+
...acc,
|
157
|
+
{
|
158
|
+
label: `${properties.label} (${properties.postcode})`,
|
159
|
+
value: {
|
160
|
+
city: properties.city,
|
161
|
+
country,
|
162
|
+
street: `${properties.housenumber || ''} ${properties.street}`,
|
163
|
+
zipcode: properties.postcode,
|
164
|
+
},
|
160
165
|
},
|
161
|
-
|
162
|
-
});
|
166
|
+
];
|
167
|
+
}, []);
|
163
168
|
}
|
164
169
|
catch (error) {
|
165
170
|
if (typeof error === 'string')
|
package/dist/module.js
CHANGED
@@ -139,17 +139,22 @@ const get$1 = (search, options) => __awaiter(void 0, void 0, void 0, function* (
|
|
139
139
|
if (!response.ok)
|
140
140
|
return Promise.reject(response);
|
141
141
|
const result = yield response.json();
|
142
|
-
return result.features.
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
142
|
+
return result.features.reduce((acc, { properties }) => {
|
143
|
+
if (!properties.street)
|
144
|
+
return acc;
|
145
|
+
return [
|
146
|
+
...acc,
|
147
|
+
{
|
148
|
+
label: `${properties.label} (${properties.postcode})`,
|
149
|
+
value: {
|
150
|
+
city: properties.city,
|
151
|
+
country,
|
152
|
+
street: `${properties.housenumber || ''} ${properties.street}`,
|
153
|
+
zipcode: properties.postcode,
|
154
|
+
},
|
150
155
|
},
|
151
|
-
|
152
|
-
});
|
156
|
+
];
|
157
|
+
}, []);
|
153
158
|
}
|
154
159
|
catch (error) {
|
155
160
|
if (typeof error === 'string')
|