forked from jan-rus/country-in-text-detector
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexamples.js
60 lines (53 loc) · 1.69 KB
/
examples.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
var countryDetector = require("./index.js");
// 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 Roumanie in French
var romania = countryDetector.detect("FR: J'ai vécu en Roumanie.");
/*
[
{ iso3166: 'RO', name: 'Romania', type: 'country', matches: [ 'Roumanie'] }
]
*/
console.log(romania);
// handles Roumanie in French
var slovakia = countryDetector.detect("FR: J'ai vécu en Slovaquie.");
/*
[
{ iso3166: 'SK', name: 'Slovakia', type: 'country', matches: [ 'Slovaquie'] }
]
*/
console.log(slovakia);
// 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' ] }
]
*/