ben-willis / address-formatter-scala   1.1.0

MIT License GitHub

Universal international address formatter in Scala

Scala versions: 2.13 2.12

Scala Address Formatter

Build Maven Central

This library can compose structured address data in to a format that users expect using the amazing work of OpenCage Data who collected so many international formats of postal addresses.

This library can format almost anything that comes out of Open Street Maps' Nominatim API in the address field. Other compatible sources of data might be used as well.

It can automatically detect the country's formatting customs, but allows you to pick a specific country format.

The formatting specification for the whole world is part of the distribution package, there is currently no plan to prepare smaller builds with limited area coverage.

Installation and Usage

libraryDependencies += "io.github.ben-willis" %% "address-formatter" % "1.0.0"
val addressFormatter = new AddressFormatter()

val address = Map(
  "house_number" -> "221b",
  "road" -> "Baker Street",
  "city" -> "London",
  "postal_code" -> "NW1 6XE",
  "country_code" -> "gb"
)

/*
 * Expected output is:
 * 
 * 221b Baker Street
 * London NW1 6XE
*/
addressFormatter.format(address)

Development and Tests

Test cases are from the OpenCage address-formatting repo.

sbt test

Acknowledgements

Big thanks to the PHP, Perl and Javascript implementations of the address formatter.