@ntegral/country-state-city
Advanced tools
Comparing version 1.0.1 to 1.0.2
import { ICountry, IState } from "./interfaces/csc.interface"; | ||
export { ICountry, IState } from "./interfaces/csc.interface"; | ||
declare let csc: { | ||
getAllCountries(): ICountry[]; | ||
getCountryById(id: number): ICountry; | ||
getCountryByCode(code: string): ICountry; | ||
getStatesByCountry(countryId: number): IState[]; | ||
}; | ||
export default csc; | ||
export { ICountry, IState }; |
@@ -5,9 +5,9 @@ "use strict"; | ||
const states = require("./data/states.json"); | ||
let csc = { | ||
class csc { | ||
getAllCountries() { | ||
return countries; | ||
}, | ||
} | ||
getCountryById(id) { | ||
return countries.find(c => c.id === id); | ||
}, | ||
} | ||
getCountryByCode(code) { | ||
@@ -20,17 +20,16 @@ if (code.length === 3) { | ||
} | ||
}, | ||
} | ||
getStatesByCountry(countryId) { | ||
let result = states.filter(s => s.country_id === countryId); | ||
return result.sort(compare); | ||
return result.sort(this.compare); | ||
} | ||
}; | ||
exports.default = csc; | ||
function compare(a, b) { | ||
if (a.name < b.name) { | ||
return -1; | ||
compare(a, b) { | ||
if (a.name < b.name) { | ||
return -1; | ||
} | ||
if (a.name > b.name) { | ||
return 1; | ||
} | ||
return 0; | ||
} | ||
if (a.name > b.name) { | ||
return 1; | ||
} | ||
return 0; | ||
} |
import countries = require("./data/countries.json"); | ||
import states = require("./data/states.json"); | ||
import { ICountry, IState } from "./interfaces/csc.interface"; | ||
export { ICountry, IState } from "./interfaces/csc.interface"; | ||
export { ICountry, IState }; | ||
let csc = { | ||
class csc { | ||
getAllCountries(): ICountry[] { | ||
return countries as ICountry[]; | ||
} | ||
getCountryById(id: number): ICountry { | ||
return countries.find(c => c.id === id) as ICountry; | ||
} | ||
getCountryByCode(code: string): ICountry { | ||
if (code.length === 3) { | ||
return countries.find(c => c.iso3 === code) as ICountry; | ||
} else { | ||
return countries.find(c => c.iso2 === code) as ICountry; | ||
} | ||
} | ||
getStatesByCountry(countryId:number): IState[] { | ||
let result = states.filter(s => s.country_id === countryId) as IState[]; | ||
return result.sort(this.compare); | ||
} | ||
private compare(a:any,b:any) { | ||
if(a.name < b.name) { | ||
return -1; | ||
} | ||
if(a.name > b.name) { | ||
return 1; | ||
} | ||
return 0; | ||
} | ||
} | ||
/* let csc = return { | ||
getAllCountries(): ICountry[] { | ||
return countries as ICountry[]; | ||
}, | ||
@@ -26,12 +60,2 @@ getCountryById(id: number): ICountry { | ||
} | ||
export default csc; | ||
function compare(a:any,b:any) { | ||
if(a.name < b.name) { | ||
return -1; | ||
} | ||
if(a.name > b.name) { | ||
return 1; | ||
} | ||
return 0; | ||
} | ||
export default csc; */ |
@@ -10,3 +10,3 @@ { | ||
"name": "@ntegral/country-state-city", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "Full database of city, state and countries", | ||
@@ -13,0 +13,0 @@ "main": "./dist/index.js", |
36534245
73531