i18n-iso-countries
Advanced tools
Comparing version 1.8.0 to 1.8.1
15
index.js
@@ -216,2 +216,17 @@ var pad = require("pad"); | ||
/* | ||
* @param name name | ||
* @param lang language for country name | ||
* @return ISO 3166-1 alpha-3 or undefined | ||
*/ | ||
exports.getAlpha3Code = function(name, lang) { | ||
"use strict"; | ||
var alpha2 = this.getAlpha2Code(name, lang); | ||
if (alpha2) { | ||
return this.toAlpha3(alpha2); | ||
} else { | ||
return undefined; | ||
} | ||
}; | ||
/* | ||
* @return Array of alpha-3 codes | ||
@@ -218,0 +233,0 @@ */ |
{ | ||
"name": "i18n-iso-countries", | ||
"version": "1.8.0", | ||
"version": "1.8.1", | ||
"description": "i18n for ISO 3166-1 country codes", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -54,2 +54,5 @@ [](http://travis-ci.org/michaelwittig/node-i18n-iso-countries) | ||
// United States of America => US | ||
console.log("United States of America => " + countries.getAlpha3Code('United States of America', 'en')); | ||
// United States of America => USA | ||
````` | ||
@@ -56,0 +59,0 @@ |
@@ -135,2 +135,10 @@ var assert = require("assert-plus"), | ||
}); | ||
describe("getAlpha3Code", function() { | ||
it("missing name", function() { | ||
assert.equal(i18niso.getAlpha3Code("XXX", "de"), undefined); | ||
}); | ||
it("missing land", function() { | ||
assert.equal(i18niso.getAlpha3Code("Deutschland", "xx"), undefined); | ||
}); | ||
}); | ||
describe("completeness", function () { | ||
@@ -183,2 +191,10 @@ i18niso.langs().forEach(function(lang) { | ||
}); | ||
describe("get Alpha-3 code", function() { | ||
it("nameToAlpha3 United States of America => USA", function() { | ||
assert.equal(i18niso.getAlpha3Code("United States of America", lang), "USA"); | ||
}); | ||
it("nameToAlpha3 Brazil => BRA", function() { | ||
assert.equal(i18niso.getAlpha3Code("Brazil", lang), "BRA"); | ||
}); | ||
}); | ||
describe("get name", function () { | ||
@@ -212,2 +228,10 @@ it("for de", function () { | ||
}); | ||
describe("get Alpha-3 code", function() { | ||
it("nameToAlpha3 Brazylia => BRA", function() { | ||
assert.equal(i18niso.getAlpha3Code("Brazylia", lang), "BRA"); | ||
}); | ||
it("nameToAlpha3 Stany Zjednoczone => USA", function() { | ||
assert.equal(i18niso.getAlpha3Code("Stany Zjednoczone", lang), "USA"); | ||
}); | ||
}); | ||
describe("get name", function () { | ||
@@ -214,0 +238,0 @@ it("for af => Afganistan", function () { |
143395
5281
142