@wuyuchentr/emoji-flag
v1.0.0
Published
Convert country codes to emoji flags ("CN" โ ๐จ๐ณ). Supports all two-letter codes. < 1 KB.
Maintainers
Readme
@wuyuchentr/emoji-flag
Convert country codes to emoji flags โ "CN" โ ๐จ๐ณ. < 1 KB, no dependencies.
Install
npm install @wuyuchentr/emoji-flagUsage
const { flag, isFlag, code } = require('@wuyuchentr/emoji-flag');
flag('CN') // โ ๐จ๐ณ
flag('US') // โ ๐บ๐ธ
flag('JP') // โ ๐ฏ๐ต
flag('GB') // โ ๐ฌ๐ง
flag('๐ด๓ ง๓ ข๓ ฅ๓ ฎ๓ ง๓ ฟ') // No โ this one you need to type directly :)
// Validate
isFlag('๐จ๐ณ') // โ true
isFlag('xx') // โ false
// Reverse
code('๐จ๐ณ') // โ "CN"API
| Function | Description |
|----------|-------------|
| flag(code) | Two-letter country code โ flag emoji |
| isFlag(str) | Check if a string is a flag emoji |
| code(emoji) | Flag emoji โ two-letter country code |
How it works
Each flag emoji is two Regional Indicator Symbols (U+1F1E6โU+1F1FF), one per letter of the ISO country code. The conversion is a simple arithmetic offset โ no lookup table needed. Any valid two-letter code (AAโZZ) will produce a visible flag on modern OS.
