Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add option to format results #256

Merged
merged 3 commits into from
Jan 7, 2021

Conversation

mrsimpson
Copy link
Contributor

@mrsimpson mrsimpson commented Dec 10, 2020

Motivation

Some search providers, especially OSM, return the address search results in a not very common order.
E. g. the house number is returned in the first position of the label, which is very uncommon in German.

Changes done

This PR introduces a callback function which is executed in order to manipulate the search result label.

Caveats

As the query is currently not available in the result list, it could not be propagated to the callback function.
Adding this would have increased the PR which I wanted to avoid.

How it looks like

Before

Provider OSM
without-callback

Afterwards

with callback injected

resultFormat: (result)=>{
          if(result.label.match(/^\d+,/)){
            // swap house no and street
            const components = result.label.split(',').map(s=>s.trim())
            const houseNo = components[0]
            components[0] = components[1]
            components[1] = houseNo
            return `${components.slice(0,2).join(' ')}, ${components.slice(2, components.length).join(',  ')}`
          }
          return result.label
          },

with-callback

@mrsimpson mrsimpson changed the title callback for formating results Callback for formating results Dec 10, 2020
@mrsimpson mrsimpson changed the title Callback for formating results Callback for formatting results Dec 10, 2020
@mrsimpson
Copy link
Contributor Author

@smeijer any chance to get this merged? I tried to keep the diff as small as possible.

@smeijer smeijer changed the title Callback for formatting results feat: add option to format results Jan 7, 2021
@smeijer smeijer merged commit bb49459 into smeijer:develop Jan 7, 2021
@smeijer
Copy link
Owner

smeijer commented Jan 7, 2021

Thanks! Looking great.

@smeijer
Copy link
Owner

smeijer commented Jan 7, 2021

published as 3.2.0, thanks again! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants