Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
country-code-emoji
Advanced tools
convert country codes (ISO 3166-1 alpha-2) to corresponding emoji flags (unicode regional indicator symbols)
convert country codes (ISO 3166-1 alpha-2) to corresponding emoji flags (unicode regional indicator symbols)
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.
# npm
npm install country-code-emoji
# yarn
yarn add country-code-emoji
// 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 '🇺🇰'
[2.3.0] - 2021-05-23
.mjs
extension for official nodejs esm import supportFAQs
convert country codes (ISO 3166-1 alpha-2) to corresponding emoji flags (unicode regional indicator symbols)
We found that country-code-emoji demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.