country-code-emoji

WebJar for country-code-emoji

License

License

MIT
GroupId

GroupId

org.webjars.npm
ArtifactId

ArtifactId

country-code-emoji
Last Version

Last Version

1.0.0
Release Date

Release Date

Type

Type

jar
Description

Description

country-code-emoji
WebJar for country-code-emoji
Project URL

Project URL

https://www.webjars.org
Source Code Management

Source Code Management

https://github.com/thekelvinliu/country-code-emoji

Download country-code-emoji

How to add to project

<!-- https://jarcasting.com/artifacts/org.webjars.npm/country-code-emoji/ -->
<dependency>
    <groupId>org.webjars.npm</groupId>
    <artifactId>country-code-emoji</artifactId>
    <version>1.0.0</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.npm/country-code-emoji/
implementation 'org.webjars.npm:country-code-emoji:1.0.0'
// https://jarcasting.com/artifacts/org.webjars.npm/country-code-emoji/
implementation ("org.webjars.npm:country-code-emoji:1.0.0")
'org.webjars.npm:country-code-emoji:jar:1.0.0'
<dependency org="org.webjars.npm" name="country-code-emoji" rev="1.0.0">
  <artifact name="country-code-emoji" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.npm', module='country-code-emoji', version='1.0.0')
)
libraryDependencies += "org.webjars.npm" % "country-code-emoji" % "1.0.0"
[org.webjars.npm/country-code-emoji "1.0.0"]

Dependencies

There are no dependencies for this project. It is a standalone project that does not depend on any other jars.

Project Modules

There are no modules declared in this project.

country-code-emoji

convert country codes (ISO 3166-1 alpha-2) to corresponding emoji flags (unicode regional indicator symbols)

about

this is a completely dependency-free module to convert ascii letters to regional indicator symbols; for valid country codes, this results in that country's emoji flag. commonjs and es module builds are available via package.json's main and module. it relies on String.fromCodePoint internally, but does not provide any polyfills. if your environment does not support String.fromCodePoint, grab a polyfill like this one from mdn.

install

# npm
npm install country-code-emoji

# yarn
yarn add country-code-emoji

usage

// commonjs module
const { countryCodeEmoji, emojiCountryCode } = require('country-code-emoji');
countryCodeEmoji('US'); // returns 'πŸ‡ΊπŸ‡Έ'
emojiCountryCode('πŸ‡ΊπŸ‡Έ'); // returns 'US'

// es module
import { countryCodeEmoji, emojiCountryCode } from 'country-code-emoji';
['AE', 'CN', 'GB'].map(countryCodeEmoji); // returns ['πŸ‡¦πŸ‡ͺ', 'πŸ‡¨πŸ‡³', 'πŸ‡¬πŸ‡§']
['πŸ‡¦πŸ‡ͺ', 'πŸ‡¨πŸ‡³', 'πŸ‡¬πŸ‡§'].map(emojiCountryCode); // returns ['AE', 'CN', 'GB']

this module exports a pair of functions to convert country codes to/from flag emojis. the first is countryCodeEmoji(cc). it accepts a two-character (case-insensitive) country code and throws a TypeError if anything else is passed. more specifically, cc is expected to be a ISO 3166-1 alpha-2 country code. to keep things simple, if cc a two letter string, but not an actual ISO 3166-1 alpha-2 code, the regional indicator symbols corresponding to the letters in cc are returned. the second is emojiCountryCode(flag), which accepts a flag emoji and similarly throws a TypeError if anything else is passed.

// default export is countryCodeEmoji
import flag from 'country-code-emoji';

flag(); // throws TypeError
['Us', 'uS', 'us'].every(e => flag(e) === flag('US')); // returns true
flag('UK'); // returns 'πŸ‡ΊπŸ‡°'

Versions

Version
1.0.0