Product
Introducing SSO
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
country-in-text-detector
Advanced tools
Readme
This module detects countries that appear/are mentioned in given text. It uses names of countries and almost 500 large cities and returns ISO 3166-1 code of country, its name and list of matches found in the text. Module can recognise international and local names, some of them in more language mutations, such as EN, ES, FR, DE, CZ.
Handles special characters, flags and emojis, so you can analyse any text without need of preprocessing.
npm install --save country-in-text-detector
You can also find these examples in examples.js file.
var countryDetector = require("country-in-text-detector");
// handles countries in text, result is array of matches (objects)
var result = countryDetector.detect("Hello, I come from Germany!");
/*
[
{ iso3166: 'DE', name: 'Germany', type: 'country', matches: [ 'Germany' ] }
]
*/
// handles large cities in text
var cities = countryDetector.detect("I just moved from Austin, TX to NYC.");
/*
[
{ iso3166: 'US-NY', name: 'New York City', countryName: 'New York', type: 'city', matches: [ 'NYC' ] },
{ iso3166: 'US-TX', name: 'Austin', countryName: 'Texas', type: 'city', matches: [ 'Austin, TX' ] }
]
*/
// handles local/international names
var local = countryDetector.detect("RU: Я родился в России. EN: I was born in Russia.");
/*
[
{ iso3166: 'RU', name: 'Russia', type: 'country', matches: [ 'России', 'Russia' ] }
]
*/
// handles frequent language mutations
var mutations = countryDetector.detect("FR: J'ai vécu en Italie. EN: I lived in Italy.");
/*
[
{ iso3166: 'IT', name: 'Italy', type: 'country', matches: [ 'Italie', 'Italy' ] }
]
*/
// handles special characters and emojis
var special = countryDetector.detect("Adoro❤️ o 🇧🇷Rio~de~Janeiro💃🏼 !");
/*
[
{ iso3166: 'BR', name: 'Rio de Janeiro', countryName: 'Brazil', type: 'city', matches: [ 'Rio~de~Janeiro' ] }
]
*/
FAQs
Module for detection of countries in given text. Detects countries by international and local name, some of them in more language mutations. Uses also names of large cities to derive related countries.
The npm package country-in-text-detector receives a total of 460 weekly downloads. As such, country-in-text-detector popularity was classified as not popular.
We found that country-in-text-detector 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.
Product
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.