country-query
Advanced tools
Comparing version 0.1.1 to 0.2.0
@@ -41,3 +41,3 @@ var _ = require('lodash') | ||
* @param {mixed} value The value to search for. | ||
* @return {[type]} [description] | ||
* @return {mixed} null, a country object or array of coutnry objects. | ||
*/ | ||
@@ -65,2 +65,142 @@ find: function(by, value) { | ||
} | ||
/** | ||
* Find country by its area. | ||
* @param {number} area | ||
* @return {mixed} See #find() | ||
*/ | ||
, findByArea: function(area) { return this.find('area', area) } | ||
/** | ||
* Find country by alternative spellings of its name. | ||
* @param {string} altSpelling | ||
* @return {mixed} See #find() | ||
*/ | ||
, findByAltSpelling: function(altSpelling) { return this.find('altSpellings', altSpelling) } | ||
/** | ||
* Find country by countries that it borders | ||
* @param {string} borders | ||
* @return {mixed} See #find() | ||
*/ | ||
, findByBorders: function(borders) { return this.find('borders', borders) } | ||
/** | ||
* Find country by telephone calling code | ||
* @param {string} callingCode | ||
* @return {mixed} See #find() | ||
*/ | ||
, findByCallingCode: function(callingCode) { return this.find('callingCode', callingCode) } | ||
/** | ||
* Find country by its capital city. | ||
* @param {string} capital | ||
* @return {mixed} See #find() | ||
*/ | ||
, findByCapital: function(capital) { return this.find('capital', capital) } | ||
/** | ||
* Find country by 2-letter country code. | ||
* @param {string} cca2 | ||
* @return {mixed} See #find() | ||
*/ | ||
, findByCca2: function(cca2) { return this.find('cca2', cca2) } | ||
/** | ||
* Find country by 3-letter country code. | ||
* @param {string} cca3 | ||
* @return {mixed} See #find() | ||
*/ | ||
, findByCca3: function(cca3) { return this.find('cca3', cca3) } | ||
/** | ||
* Find country by numeric country code. | ||
* @param {string} ccn3 | ||
* @return {mixed} See #find() | ||
*/ | ||
, findByCcn3: function(ccn3) { return this.find('ccn3', ccn3) } | ||
/** | ||
* Find country by currency. | ||
* @param {string} currency | ||
* @return {mixed} See #find() | ||
*/ | ||
, findByCurrency: function(currency) { return this.find('currency', currency) } | ||
/** | ||
* Find country by the demonym used for its citizens. | ||
* @param {string} demonym | ||
* @return {mixed} See #find() | ||
*/ | ||
, findByDemonym: function(demonym) { return this.find('demonym', demonym) } | ||
/** | ||
* Find country by whether or not it is landlocked. | ||
* @param {bool} landlocked | ||
* @return {mixed} See #find() | ||
*/ | ||
, findByLandlocked: function(landlocked) { return this.find('landlocked', landlocked) } | ||
/** | ||
* Find country by its language. | ||
* @param {string} language | ||
* @return {mixed} See #find() | ||
*/ | ||
, findByLanguage: function(language) { return this.find('languages', language) } | ||
/** | ||
* Find country by its common name. | ||
* @param {string} name | ||
* @return {mixed} See #find() | ||
*/ | ||
, findByNameCommon: function(name) { return this.find('name.common', name) } | ||
/** | ||
* Find country by its native name | ||
* @param {string} name | ||
* @return {mixed} See #find() | ||
*/ | ||
, findByNameNative: function(name) { return this.find('name.native', name) } | ||
/** | ||
* Find country by its official name. | ||
* @param {string} name | ||
* @return {mixed} See #find() | ||
*/ | ||
, findByNameOfficial: function(name) { return this.find('name.official', name) } | ||
/** | ||
* Find country by the region it is located in. | ||
* @param {string} region | ||
* @return {mixed} See #find() | ||
*/ | ||
, findByRegion: function(region) { return this.find('region', region) } | ||
/** | ||
* Find country by 'relevance'. | ||
* @param {string} relevance | ||
* @return {mixed} See #find() | ||
*/ | ||
, findByRelevance: function(relevance) { return this.find('relevance', relevance) } | ||
/** | ||
* Find country by subregion it is located in. | ||
* @param {string} subregion | ||
* @return {mixed} See #find() | ||
*/ | ||
, findBySubregion: function(subregion) { return this.find('subregion', subregion) } | ||
/** | ||
* Find country by top level domain. | ||
* @param {string} tld | ||
* @return {mixed} See #find() | ||
*/ | ||
, findByTld: function(tld) { return this.find('tld', tld) } | ||
/** | ||
* Find country by translations of its name. | ||
* @param {string} translation | ||
* @return {mixed} See #find() | ||
*/ | ||
, findByTranslation: function(translation) { return this.find('translations', translation) } | ||
}; | ||
@@ -67,0 +207,0 @@ |
{ | ||
"name": "country-query", | ||
"version": "0.1.1", | ||
"version": "0.2.0", | ||
"description": "A javascript query API for world-countries data", | ||
@@ -5,0 +5,0 @@ "repository": { |
120
README.md
@@ -95,2 +95,122 @@ # country-query | ||
### findByArea(area) | ||
Find country by its area. | ||
Return value is the same as [find](#findby-value). | ||
### findByAltSpelling(altSpelling) | ||
Find country by alternative spellings of its name. | ||
Return value is the same as [find](#findby-value). | ||
### findByBorders(borders) | ||
Find country by countries that it borders | ||
Return value is the same as [find](#findby-value). | ||
### findByCallingCode(callingCode) | ||
Find country by telephone calling code. | ||
Return value is the same as [find](#findby-value). | ||
### findByCapital(capital) | ||
Find country by its capital city. | ||
Return value is the same as [find](#findby-value). | ||
### findByCca2(cca2) | ||
Find country by 2-letter country code. | ||
Return value is the same as [find](#findby-value). | ||
### findByCca3(cca3) | ||
Find country by 3-letter country code. | ||
Return value is the same as [find](#findby-value). | ||
### findByCcn3(ccn3) | ||
Find country by numeric country code. | ||
Return value is the same as [find](#findby-value). | ||
### findByCurrency(currency) | ||
Find country by currency. | ||
Return value is the same as [find](#findby-value). | ||
### findByDemonym(demonym) | ||
Find country by the demonym used for its citizens. | ||
Return value is the same as [find](#findby-value). | ||
### findByLandlocked(landlocked) | ||
Find country by whether or not it is landlocked. | ||
Return value is the same as [find](#findby-value). | ||
### findByLanguage(language) | ||
Find country by its language. | ||
Return value is the same as [find](#findby-value). | ||
### findByNameCommon(name) | ||
Find country by its common name. | ||
Return value is the same as [find](#findby-value). | ||
### findByNameNative(name) | ||
Find country by its native name. | ||
Return value is the same as [find](#findby-value). | ||
### findByNameOfficial(name) | ||
Find country by its official name. | ||
Return value is the same as [find](#findby-value). | ||
### findByRegion(region) | ||
Find country by the region it is located in. | ||
Return value is the same as [find](#findby-value). | ||
### findByRelevance(relevance) | ||
Find country by 'relevance'. | ||
Return value is the same as [find](#findby-value). | ||
### findBySubregion(subregion) | ||
Find country by subregion it is located in. | ||
Return value is the same as [find](#findby-value). | ||
### findByTld(tld) | ||
Find country by top level domain. | ||
Return value is the same as [find](#findby-value). | ||
### findByTranslation(translation) | ||
Find country by translations of its name. | ||
Return value is the same as [find](#findby-value). | ||
## Thanks | ||
@@ -97,0 +217,0 @@ |
var expect = require('chai').expect | ||
var CountryQuery = require('../lib/country-query.js') | ||
describe('CountryQuery', function(){ | ||
describe('#find()', function(){ | ||
describe('CountryQuery', function() { | ||
describe('#find()', function() { | ||
it('should return an object when finding by uniquely identifiable string properties', function(){ | ||
@@ -52,3 +52,3 @@ expect(CountryQuery.find('cca2', 'AW')).to.have.property('cca3', 'ABW') | ||
it('should return an array when finding by non-uniquely identifiable properties that contain maps', function() { | ||
var austBavCountries= CountryQuery.find('languages', 'Austro-Bavarian German'), | ||
var austBavCountries = CountryQuery.find('languages', 'Austro-Bavarian German'), | ||
austria = CountryQuery.find('cca2', 'AT'), | ||
@@ -62,15 +62,72 @@ italy = CountryQuery.find('cca2', 'IT') | ||
it('should return null for searches that return nothing', function() { | ||
expect(CountryQuery.find('cca2', 'XX')).to.be.null | ||
expect(CountryQuery.find('ccn3', '000')).to.be.null | ||
expect(CountryQuery.find('cca3', 'XXX')).to.be.null | ||
expect(CountryQuery.find('capital', 'XXXXX')).to.be.null | ||
expect(CountryQuery.find('demonym', 'XXXXXXX')).to.be.null | ||
var nullTests = | ||
[ {field: 'cca2', value: 'XX'} | ||
, {field: 'ccn3', value: '000'} | ||
, {field: 'cca3', value: 'XXX'} | ||
, {field: 'capital', value: 'XXXXX'} | ||
, {field: 'demonym', value: 'XXXXXXX'} | ||
] | ||
nullTests.forEach(function(test) { | ||
expect(CountryQuery.find(test.field, test.value)).to.be.null | ||
}) | ||
}) | ||
it('should return null for non-existent properties', function() { | ||
expect(CountryQuery.find('cant-find-me', 'XX')).to.be.null | ||
expect(CountryQuery.find('', 'XX')).to.be.null | ||
expect(CountryQuery.find(null, 'XX')).to.be.null | ||
var nullTests = | ||
[ {field: 'cant-find-me', value: 'XX'} | ||
, {field: '', value: 'XX'} | ||
, {field: null, value: 'XX'} | ||
] | ||
nullTests.forEach(function(test) { | ||
expect(CountryQuery.find(test.field, test.value)).to.be.null | ||
}) | ||
}) | ||
}) | ||
describe('#findByX()', function() { | ||
it('should behave the same as the equivalent plain find', function() { | ||
var findSingleTests = | ||
[ {field: 'altSpellings', value: 'Oesterreich' , findFunc: 'findByAltSpelling', expectCca3: 'AUT'} | ||
, {field: 'area', value: 6 , findFunc: 'findByArea', expectCca3: 'GIB'} | ||
, {field: 'callingCode', value: '355' , findFunc: 'findByCallingCode', expectCca3: 'ALB'} | ||
, {field: 'capital', value: 'Guatemala City' , findFunc: 'findByCapital', expectCca3: 'GTM'} | ||
, {field: 'cca2', value: 'PL' , findFunc: 'findByCca2', expectCca3: 'POL'} | ||
, {field: 'cca3', value: 'GNQ' , findFunc: 'findByCca3', expectCca3: 'GNQ'} | ||
, {field: 'ccn3', value: '056' , findFunc: 'findByCcn3', expectCca3: 'BEL'} | ||
, {field: 'demonym', value: 'Qatari' , findFunc: 'findByDemonym', expectCca3: 'QAT'} | ||
, {field: 'languages', value: 'Azerbaijani' , findFunc: 'findByLanguage', expectCca3: 'AZE'} | ||
, {field: 'name.common', value: 'Argentina' , findFunc: 'findByNameCommon', expectCca3: 'ARG'} | ||
, {field: 'name.official', value: 'Argentine Republic' , findFunc: 'findByNameOfficial', expectCca3: 'ARG'} | ||
, {field: 'name.native', value: "Rep\u00fablica Argentina" , findFunc: 'findByNameNative', expectCca3: 'ARG'} | ||
, {field: 'tld', value: '.ao' , findFunc: 'findByTld', expectCca3: 'AGO'} | ||
, {field: 'translations', value: 'Prinsdom Andorra' , findFunc: 'findByTranslation', expectCca3: 'AND'} | ||
] | ||
findSingleTests.forEach(function(test) { | ||
var findByXResult = CountryQuery[test.findFunc].call(CountryQuery, test.value) | ||
, findResult = CountryQuery.find(test.field, test.value) | ||
expect(findByXResult).to.deep.equal(findResult) | ||
expect(findByXResult).to.have.property('cca3', test.expectCca3) | ||
}) | ||
var findArrayTests = | ||
[ {field: 'borders', value: 'AFG' , findFunc: 'findByBorders', expectLength: 7} | ||
, {field: 'currency', value: 'GBP' , findFunc: 'findByCurrency', expectLength: 5} | ||
, {field: 'landlocked', value: true , findFunc: 'findByLandlocked', expectLength: 45} | ||
, {field: 'region', value: 'Africa' , findFunc: 'findByRegion', expectLength: 59} | ||
, {field: 'relevance', value: '0.5' , findFunc: 'findByRelevance', expectLength: 36} | ||
, {field: 'subregion', value: 'Western Africa' , findFunc: 'findBySubregion', expectLength: 17} | ||
] | ||
findArrayTests.forEach(function(test) { | ||
var findByXResult = CountryQuery[test.findFunc].call(CountryQuery, test.value) | ||
, findResult = CountryQuery.find(test.field, test.value) | ||
expect(findByXResult).to.deep.equal(findResult) | ||
expect(findByXResult).to.have.length(test.expectLength) | ||
}) | ||
}) | ||
}) | ||
}) |
Sorry, the diff of this file is not supported yet
23263
8
376
227