https://github.com/fluidsonic/fluid-country
Kotlin multiplatform country library (alpha)
https://github.com/fluidsonic/fluid-country
country country-codes kotlin kotlin-multiplaform
Last synced: about 2 months ago
JSON representation
Kotlin multiplatform country library (alpha)
- Host: GitHub
- URL: https://github.com/fluidsonic/fluid-country
- Owner: fluidsonic
- License: apache-2.0
- Created: 2020-08-22T19:02:34.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2023-06-24T03:29:06.000Z (almost 2 years ago)
- Last Synced: 2025-03-27T19:41:38.544Z (2 months ago)
- Topics: country, country-codes, kotlin, kotlin-multiplaform
- Language: Kotlin
- Homepage:
- Size: 247 KB
- Stars: 12
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- kmp-awesome - fluid-country - country library (Libraries / 🔧 Utils)
README
fluid-country
=============[](https://search.maven.org/artifact/io.fluidsonic.country/fluid-country)
[](https://github.com/fluidsonic/fluid-country/actions?workflow=Tests)
[-blue.svg)](https://github.com/JetBrains/kotlin/releases/v1.8.22)
[](https://kotlinlang.slack.com/messages/C7UDFSVT2/)Kotlin multiplatform country library.
This is most useful in combination with [fluid-i18n](https://github.com/fluidsonic/fluid-i18n) for retrieving internationalized information about a country.
Installation
------------`build.gradle.kts`:
```kotlin
dependencies {
implementation("io.fluidsonic.country:fluid-country:0.13.0")
}
```Usage
-----```kotlin
println(Country.fromCode("US")) // US
```### `class Country`
A class with information about a specific country defined by [ISO 3166-1](https://www.iso.org/obp/ui/).
```kotlin
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
``````kotlin
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`).
```kotlin
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
``````kotlin
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
``````kotlin
val code = CountryCode.parseOrNull("ABC123") // null if code has invalid format (not two latin letters)
println(code) // null
```License
-------Apache 2.0