Skip to content
This repository was archived by the owner on Feb 2, 2023. It is now read-only.

Commit fd73e14

Browse files
feat(suggestion): expose suburb field from API in suggestion (#469)
* feat(suggestion): add suburb field in suggestion the places API sometimes returns a suburb field but this field was not exposed in suggestion. it is now exposed. fixes #337 * doc(suggestion): document suburb field add documentation about the newly exposed suburb field in the suggestion object
1 parent e805372 commit fd73e14

File tree

3 files changed

+63
-0
lines changed

3 files changed

+63
-0
lines changed

docs/source/documentation.html.md.erb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,21 @@ Examples:
605605
</tr>
606606
<tr>
607607
<td markdown="1">
608+
<div class="api-entry" id="api-suggestion-suburb"><code>suburb</code></div>
609+
610+
Type: **string**
611+
</td>
612+
<td markdown="1">
613+
Suburb name.
614+
615+
Examples:
616+
617+
- Angelino heights
618+
- Harbor City
619+
</td>
620+
</tr>
621+
<tr>
622+
<td markdown="1">
608623
<div class="api-entry" id="api-suggestion-latlng"><code>latlng</code></div>
609624

610625
Type: **Object**

src/formatHit.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ export default function formatHit({
4646
? hit.administrative[0]
4747
: undefined;
4848
const city = hit.city && hit.city[0] !== name ? hit.city[0] : undefined;
49+
const suburb = hit.suburb && hit.suburb[0] !== name
50+
? hit.suburb[0]
51+
: undefined;
4952

5053
const highlight = {
5154
name: getBestHighlightedForm(hit._highlightResult.locale_names),
@@ -56,12 +59,16 @@ export default function formatHit({
5659
? getBestHighlightedForm(hit._highlightResult.administrative)
5760
: undefined,
5861
country: country ? hit._highlightResult.country.value : undefined,
62+
suburb: suburb
63+
? getBestHighlightedForm(hit._highlightResult.suburb)
64+
: undefined,
5965
};
6066

6167
const suggestion = {
6268
name,
6369
administrative,
6470
city,
71+
suburb,
6572
country,
6673
countryCode: findCountryCode(hit._tags),
6774
type: findType(hit._tags),

src/formatHit.test.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,46 @@ describe('formatHit', () => {
3737
highlight: { administrative: undefined, name: 'Île-de-France' },
3838
},
3939
}),
40+
getTestCase({
41+
name: 'no suburb',
42+
hit: { suburb: undefined },
43+
expected: {
44+
suburb: undefined,
45+
highlight: { suburb: undefined },
46+
},
47+
}),
48+
getTestCase({
49+
name: 'suburb[0] === locale_names[0]',
50+
hit: {
51+
suburb: ['Harbor City'],
52+
locale_names: ['Harbor City'],
53+
_highlightResult: {
54+
locale_names: [{ value: 'Harbor City' }],
55+
suburb: [{ value: 'Harbor City' }],
56+
},
57+
},
58+
expected: {
59+
suburb: undefined,
60+
name: 'Harbor City',
61+
highlight: { suburb: undefined, name: 'Harbor City' },
62+
},
63+
}),
64+
getTestCase({
65+
name: 'suburb[0] !== locale_names[0]',
66+
hit: {
67+
suburb: ['Harbor City'],
68+
locale_names: ['237th Street'],
69+
_highlightResult: {
70+
locale_names: [{ value: '237th Street' }],
71+
suburb: [{ value: 'Harbor City' }],
72+
},
73+
},
74+
expected: {
75+
suburb: 'Harbor City',
76+
name: '237th Street',
77+
highlight: { suburb: 'Harbor City', name: '237th Street' },
78+
},
79+
}),
4080
getTestCase({
4181
name: 'locale_names[1] is matching',
4282
hit: {
@@ -156,6 +196,7 @@ describe('formatHit', () => {
156196
name: output.name,
157197
administrative: output.administrative,
158198
city: output.city,
199+
suburb: output.suburb,
159200
country: output.country,
160201
countryCode: output.countryCode,
161202
type: output.type,

0 commit comments

Comments
 (0)