Converts between country names, ISO 3166-1 codes and flag emojis.

Overview

country-emoji

crate.io

Converts between country names, ISO 3166-1 codes and flag emojis.

Usage

use country_emoji::{flag, code, name, countries};

flag("CL")
 // ~> 🇨🇱

code("🇨🇦")
 // ~> CA

name("🇶🇦")
 // ~> Qatar

// can extract name from string…
flag("Taiwan number one!")
 // ~> 🇹🇼

// …but only if there"s no ambiguity
flag("Congo and Burma")
 // ~> undefined

flag("Republic of Tanzania")
 // ~> 🇹🇿

flag("Tanzania, United Republic of")
 // ~> 🇹🇿

code("Australia")
 // ~> AU

code("UAE")
 // ~> AE

name("AE")
 // ~> United Arab Emirates

code("UK")
 // ~> GB

Don't want Rust?

Check out the following:

Bugs and feedback

If you discover a bug please report it here. Express gratitude here.

Mail me at [email protected], or on twitter @leodutra.

Credits

This library is based on the work of two existing library:

Thanks guys for your work!

License

MIT @ Leo Dutra

You might also like...
An API for getting questions from http://either.io implemented fully in Rust, using reqwest and some regex magic. Provides asynchronous and blocking clients respectively.

eithers_rust An API for getting questions from http://either.io implemented fully in Rust, using reqwest and some regex magic. Provides asynchronous a

Safe, efficient, and ergonomic bindings to Wolfram LibraryLink and the Wolfram Language

wolfram-library-link Bindings to the Wolfram LibraryLink interface, making it possible to call Rust code from the Wolfram Language. This library is us

This blog provides detailed status updates and useful information about Theseus OS and its development

The Theseus OS Blog This blog provides detailed status updates and useful information about Theseus OS and its development. Attribution This blog was

Omeglib, a portmanteau of "omegle" and "library", is a crate for interacting with omegle, simply and asynchronously

Omeglib, a portmanteau of "omegle" and "library", is a crate for interacting with omegle, simply and asynchronously. It is intended to suit one's every requirement regarding chat on omegle.

Fast and simple datetime, date, time and duration parsing for rust.

speedate Fast and simple datetime, date, time and duration parsing for rust. speedate is a lax† RFC 3339 date and time parser, in other words, it pars

In this repository you can find modules with code and comments that explain rust syntax and all about Rust lang.
In this repository you can find modules with code and comments that explain rust syntax and all about Rust lang.

Learn Rust What is this? In this repository you can find modules with code and comments that explain rust syntax and all about Rust lang. This is usef

A tool and library to losslessly join multiple .mp4 files shot with same camera and settings

mp4-merge A tool and library to losslessly join multiple .mp4 files shot with same camera and settings. This is useful to merge multiple files that ar

A tray application for Windows that gives you push notifications and instant downloads of new posts, messages and stories posted by models you subscribe to on Onlyfans.

OF-notifier A tray application for Windows that gives you push notifications and instant downloads of new posts, messages and stories posted by models

A simpler and 5x faster alternative to HashMap in Rust, which doesn't use hashing and doesn't use heap

At least 5x faster alternative of HashMap, for very small maps. It is also faster than FxHashMap, hashbrown, ArrayMap, and nohash-hasher. The smaller

Comments
  • code_to_flag behaves weirdly with lowercase country codes

    code_to_flag behaves weirdly with lowercase country codes

    Hey 🙂 Thank you very much for providing this useful library! I noticed some unintuitive behaviour in the code_to_flag function, when supplying a country code in lowercase:

    let correct = country_emoji::code_to_flag("DE"); // as_bytes returns [240, 159, 135, 169, 240, 159, 135, 170]
    let incorrect = country_emoji::code_to_flag("de"); // as_bytes returns [240, 159, 136, 137, 240, 159, 136, 138]
    

    I guess this happens because code_to_flag, unlike most other functions, doesn't use .to_uppercase() to normalize the input.

    Expected behaviour

    I'd either expect all methods to return None for lowercase codes, or the code_to_flag function to return the correct flag even when supplying a lowercase country code.

    I'm happy to work on a fix for the problem if you don't have the time, but I'd need to know which behaviour you'd prefer.

    opened by juliuste 2
Owner
Leo Dutra
Leo Dutra
🚀simple server that returns error codes with their respective messages and debug information, written in rust 🦀

ErrorServer ?? A simple & lightweight server that returns a HTML page of the error code with its respective message and debug information, written in

Jakob 2 Dec 15, 2022
derive(Code) simplifies error handling by providing an easy-to-use enumeration of error codes

enum-code Introduction enum-code is a derive macro for enum types. This library generates code that associates error codes with error types. It can be

Bay 5 Jun 14, 2023
example codes for CIS198 https://cis198-2016s.github.io/

CIS198: RUST 编程语言 学习背景 rust 和 c/c++/Java/Python/golang 不太一样 rust 学习曲线比较陡峭 rust 有很多颠覆认知的特性: 所有权,生命周期,借用检测 cargo 工具 函数式+命令式支持 视频讲解见 B站 课程大纲 Timeline Lec

Jinghui Hu 3 Apr 9, 2024
A library for transcoding between bytes in Astro Notation Format and Native Rust data types.

Rust Astro Notation A library for transcoding between hexadecimal strings in Astro Notation Format and Native Rust data types. Usage In your Cargo.tom

Stelar Software 1 Feb 4, 2022
A simple programming language for something between C and Rust.

inuc inuc is a systems programming language that is something between C and Rust. Features : [] Strong , static typing (type inference not a priority

Sagnik Chatterjee 1 Feb 7, 2022
List public items (public API) of Rust library crates. Enables diffing public API between releases.

cargo wrapper for this library You probably want the cargo wrapper to this library. See https://github.com/Enselic/cargo-public-items. public_items Li

Martin Nordholts 20 Dec 26, 2022
A fast rendezvous in rust where data can optionally be swapped between the two threads.

rendezvous_swap A rendezvous is an execution barrier between a pair of threads, but this crate also provides the option of swapping data at the synchr

Erik 5 Mar 17, 2023
The Fast Vector Similarity Library is designed to provide efficient computation of various similarity measures between vectors.

Fast Vector Similarity Library Introduction The Fast Vector Similarity Library is designed to provide efficient computation of various similarity meas

Jeff Emanuel 243 Sep 6, 2023
memchr vs stringzilla - up to 7x throughput difference between two SIMD-accelerated substring search libraries in Rust

memchr vs stringzilla Rust Substring Search Benchmarks Substring search is one of the most common operations in text processing, and one of the slowes

Ash Vardanian 38 Mar 5, 2024