
Library offers ISO 3166-1 based country information retrieval. Integrates with internationalization library for enhanced functionality. Handles country codes with validation and format checks.
Kotlin multiplatform country library.
This is most useful in combination with fluid-i18n for retrieving internationalized information about a country.
build.gradle.kts:
dependencies {
implementation("io.fluidsonic.country:fluid-country:0.13.0")
}println(Country.fromCode("US")) // USA 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) // 840val 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) // nullAn 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-1val 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-1val code = CountryCode.parseOrNull("ABC123") // null if code has invalid format (not two latin letters)
println(code) // nullApache 2.0
Kotlin multiplatform country library.
This is most useful in combination with fluid-i18n for retrieving internationalized information about a country.
build.gradle.kts:
dependencies {
implementation("io.fluidsonic.country:fluid-country:0.13.0")
}println(Country.fromCode("US")) // USA 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) // 840val 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) // nullAn 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-1val 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-1val code = CountryCode.parseOrNull("ABC123") // null if code has invalid format (not two latin letters)
println(code) // nullApache 2.0