Socket
Socket
Sign inDemoInstall

country-locale-map

Package Overview
Dependencies
Maintainers
1
Versions
76
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

country-locale-map - npm Package Compare versions

Comparing version 1.2.5 to 1.3.0

100

index.js
const fs = require('fs');
const fuzz = require('fuzzball');
function CLM() {

@@ -11,3 +12,5 @@ var clm = {};

var countryByName = {};
var countryNames = [];
for(let i=0; i<countries.length; ++i) {

@@ -18,2 +21,3 @@ countryByAlpha2Code[countries[i]['alpha2']] = countries[i];

countryByName[countries[i]['name']] = countries[i];
countryNames.push(countries[i]['name']);
}

@@ -141,42 +145,92 @@

/* get values by numeric */
clm.getAlpha2ByName = function(name) {
if(countryByName[name])
/* get values by country name */
clm.getAlpha2ByName = function(name, fuzzy) {
if(countryByName[name]) {
return countryByName[name].alpha2;
else
return undefined;
} else if(fuzzy) {
let match = getClosestMatch(name);
if(match) {
return countryByName[match].alpha2;
}
}
return undefined;
};
clm.getAlpha3ByName = function(name) {
if(countryByName[name])
clm.getAlpha3ByName = function(name, fuzzy) {
if(countryByName[name]) {
return countryByName[name].alpha3;
else
return undefined;
} else if(fuzzy) {
let match = getClosestMatch(name);
if(match) {
return countryByName[match].alpha3;
}
}
return undefined;
};
clm.getLocaleByName = function(name) {
if(countryByName[name])
clm.getLocaleByName = function(name, fuzzy) {
if(countryByName[name]) {
return countryByName[name].default_locale;
else
return undefined;
} else if(fuzzy) {
let match = getClosestMatch(name);
if(match) {
return countryByName[match].default_locale;
}
}
return undefined;
};
clm.getNumericByName = function(name) {
if(countryByName[name])
clm.getNumericByName = function(name, fuzzy) {
if(countryByName[name]) {
return countryByName[name].numeric;
else
return undefined;
} else if(fuzzy) {
let match = getClosestMatch(name);
if(match) {
return countryByName[match].numeric;
}
}
return undefined;
};
clm.getCurrencyByName = function(name) {
if(countryByName[name])
clm.getCurrencyByName = function(name, fuzzy) {
if(countryByName[name]) {
return countryByName[name].currency;
else
return undefined;
} else if(fuzzy) {
let match = getClosestMatch(name);
if(match) {
return countryByName[match].currency;
}
}
return undefined;
};
clm.getCountryByName = function(name) {
return countryByName[name];
clm.getCountryByName = function(name, fuzzy) {
if(countryByName[name]) {
return countryByName[name];
} else if(fuzzy) {
let match = getClosestMatch(name);
if(match) {
return countryByName[match];
}
}
return undefined;
};
function getClosestMatch(name) {
let result = fuzz.extract(name, countryNames);
if(result[0][1] >= 60) {
return result[0][0];
}
return undefined;
}
return clm;

@@ -183,0 +237,0 @@

{
"name": "country-locale-map",
"version": "1.2.5",
"version": "1.3.0",
"description": "Provides mapping between country codes and provides default country locals",

@@ -25,3 +25,5 @@ "main": "index.js",

"license": "ISC",
"dependencies": {},
"dependencies": {
"fuzzball": "^1.3.0"
},
"devDependencies": {

@@ -28,0 +30,0 @@ "chai": "^4.2.0",

@@ -187,3 +187,3 @@ # Country Locale Map [![Build Status](https://travis-ci.com/atnmorrison/country-locale-map.svg?branch=master)](https://travis-ci.com/atnmorrison/country-locale-map)

### Name
- getAlpha2ByName(country)
- getAlpha2ByName(country, fuzzy)

@@ -223,3 +223,27 @@ ```javascript

/*returns
{
"name":"Canada",
"alpha2":"CA",
"alpha3":"CAN",
"numeric":"124",
"locales":["en_CA","fr_CA"],
"default_locale":"en_CA",
"currency":"CAD",
"languages":["en","fr"],
"capital":"Ottawa",
"emoji":"🇨🇦",
"emojiU":"U+1F1E8 U+1F1E6"
}
*/
```
if true is passed for fuzzy these functions will do a fuzzy match if it can't find an exact match eg:
```javascript
clm.getCountryByName('Candaa', true);
/*returns

@@ -243,5 +267,3 @@

```

@@ -149,2 +149,43 @@ /* eslint-env node, mocha */

it('getAlpha3ByName should return CAN if passed in Canaad', function(){
let result = clm.getAlpha3ByName('Canaad', true);
expect(result).to.equal('CAN');
});
it('getNumericByName should return 124 if passed in Canaad', function(){
let result = clm.getNumericByName('Canaad', true);
expect(result).to.equal('124');
});
it('getAlpha2ByName should return CA if passed in aCnaad', function(){
let result = clm.getAlpha2ByName('aCnada', true);
expect(result).to.equal('CA');
});
it('getLocaleByName should return en_CA if passed in Cnaada', function(){
let result = clm.getLocaleByName('Cnaada', true);
expect(result).to.equal('en_CA');
});
it('getCurrencyByName should return CAD if passed in Canaa', function(){
let result = clm.getCurrencyByName('Canaa', true);
expect(result).to.equal('CAD');
});
it('getCountryByName should return object if passed Caada', function(){
let result = clm.getCountryByName('Caada', true);
expect(result.alpha3).to.equal('CAN');
expect(result.alpha2).to.equal('CA');
expect(result.name).to.equal('Canada');
expect(result.numeric).to.equal('124');
expect(result.currency).to.equal('CAD');
expect(result.capital).to.equal('Ottawa');
expect(result.emoji).to.equal('🇨🇦');
});
it('getCountryByAlpha3 should return object if passed USA', function(){

@@ -151,0 +192,0 @@ let result = clm.getCountryByAlpha3('USA');

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc