fluid-country
Kotlin multiplatform country library.
This is most useful in combination with fluid-i18n for retrieving internationalized information about a country.
Installation
build.gradle.kts
:
dependencies {
implementation("io.fluidsonic.country:fluid-country:0.9.3")
}
Usage
println(Country.fromCode("US")) // US
class Country
A class with information about a specific country defined by ISO 3166-1.
val country = Country.forCode("US") // throws if code is invalid (not defined by ISO 3166-1) or has an invalid format (not two latin letters)
println(country.code) // US
println(country.code(CountryCode.Format.iso3166_alpha3)) // USA
println(country.numericCode) // 840
val country = Country.forCodeOrNull("ABC123") // null if code is invalid (not defined by ISO 3166-1) or has an invalid format (not two latin letters)
println(country) // null
class CountryCode
An inline class for ISO 3166-1 alpha-2 country codes (e.g. US
or DE
).
val code = CountryCode.parse("US") // throws if code has invalid format (not two latin letters)
println(code.toString()) // US
println(code.isValid()) // true - 'US' is defined by ISO 3166-1
val code = CountryCode.parse("aa") // throws if code has invalid format (not two latin letters)
println(code.toString()) // AA
println(code.isValid()) // false - 'AA' is not defined by ISO 3166-1
val code = CountryCode.parseOrNull("ABC123") // null if code has invalid format (not two latin letters)
println(code) // null
License
Apache 2.0