-
Notifications
You must be signed in to change notification settings - Fork 181
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #65 from harpreetkhalsagtbit/release-v3.0.0
Release v3.0.0 Refactoring of complete package to make this package - Tree shakable
- Loading branch information
Showing
19 changed files
with
1,153 additions
and
274 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
Change Logs | ||
--------------- | ||
**v3.0.0** :: | ||
1. Refactoring of complete package to make this package - Tree shakable [Fix:60](https://github.com/harpreetkhalsagtbit/country-state-city/issues/60). | ||
2. Change in usage: | ||
|
||
- ES6 Module usage | ||
|
||
```js | ||
// Latest version - v3.0.0 | ||
import { Country, State, City } from 'country-state-city'; | ||
``` | ||
|
||
- AMD Module usage | ||
|
||
```js | ||
// Latest version - v3.0.0 | ||
let Country = require('country-state-city').Country; | ||
let State = require('country-state-city').State; | ||
console.log(Country.getAllCountries()) | ||
console.log(State.getAllStates()) | ||
``` | ||
|
||
**v2.2.0** :: | ||
|
||
1. State, City Database update by [(dr5hn)](https://github.com/dr5hn/countries-states-cities-database) | ||
|
||
**v2.1.0** :: | ||
|
||
1. Fix [#53](https://github.com/harpreetkhalsagtbit/country-state-city/issues/53): returns wrong state as state codes can ne duplicate for different countries. | ||
2. **Deprecate warning**: `getStateByCode` | ||
3. New function - `getStateByCodeAndCountry` | ||
|
||
**v2.0.0 (Backward Incompatible)** :: [Data Source (dr5hn)](https://github.com/dr5hn/countries-states-cities-database) | ||
|
||
1. Not backward compatible with previous versions. | ||
2. New and updated API functions. | ||
3. Removed proprietor Indexed Id's for uniquely identifying Country, State, City. Instead now using standard isoCodes. | ||
4. Data taken from more robust and accurate database. | ||
5. Countries with their respective flags, isoCode, currencies, latitude, longitude & timezones. | ||
6. States & cities with their latitude & longitude. | ||
|
||
**v1.0.0** :: [Data Source (hiiamrohit)](https://github.com/hiiamrohit/Countries-States-Cities-database) | ||
1. `export = {}` changed to `export default` in index.ts. | ||
2. `Interface` type `re-exported` from `index.ts`. | ||
3. `Compatible` with `ES6` module syntax. | ||
4. `Compatible` with `AMD` module - using `require('../index').default`. | ||
5. Add tests for Interface Re-Exports. | ||
6. Test cases for both AMD modules and ES6 modules usage. | ||
7. Common Test Cases are being shared between AMD and ES6 modules test files. | ||
**v0.1.8** :: [Data Source (hiiamrohit)](https://github.com/hiiamrohit/Countries-States-Cities-database) | ||
1. Development code - Javascript to Typescript conversion: [#12](https://github.com/harpreetkhalsagtbit/country-state-city/pull/12) | ||
**v0.1.0** | ||
1. Fix: [#2](https://github.com/harpreetkhalsagtbit/country-state-city/issues/2) | ||
2. Fix: [#3](https://github.com/harpreetkhalsagtbit/country-state-city/issues/3) | ||
3. Added some missing states and cities for Canada and US |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import executeAllTests from './index.test'; | ||
|
||
const { Country, State, City } = require('../index'); | ||
|
||
executeAllTests(Country, State, City); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,69 +1,97 @@ | ||
// importing interfaces from main index.ts file | ||
import { ICountry, ICity, IState } from '../index'; | ||
import { ICountry } from '../lib/interface'; | ||
|
||
// writing tests for Interfaces | ||
// https://stackoverflow.com/questions/14425568/interface-type-check-with-typescript | ||
|
||
function isValidCountryObjectStructure(object: any): object is ICountry { | ||
return 'name' in object && 'phonecode' in object && 'isoCode' in object && 'flag' in object; | ||
return 'name' in object && 'phonecode' in object && 'isoCode' in object && 'flag' in object; | ||
} | ||
|
||
test('Check for Interface export when Type Structure is Same', () => { | ||
const country: ICountry = { | ||
name: 'India', | ||
phonecode: '+91', | ||
isoCode: 'IN', | ||
flag: '🇮🇳', | ||
currency: 'INR', | ||
latitude: '20.00000000', | ||
longitude: '77.00000000', | ||
timezones: [{"zoneName":"Asia\/Kolkata","gmtOffset":19800,"gmtOffsetName":"UTC+05:30","abbreviation":"IST","tzName":"Indian Standard Time"}] | ||
}; | ||
let isCountry = isValidCountryObjectStructure(country) | ||
expect(isCountry).toEqual(true); | ||
const country = { | ||
name: 'India', | ||
phonecode: '+91', | ||
isoCode: 'IN', | ||
flag: '🇮🇳', | ||
currency: 'INR', | ||
latitude: '20.00000000', | ||
longitude: '77.00000000', | ||
timezones: [ | ||
{ | ||
zoneName: 'Asia/Kolkata', | ||
gmtOffset: 19800, | ||
gmtOffsetName: 'UTC+05:30', | ||
abbreviation: 'IST', | ||
tzName: 'Indian Standard Time', | ||
}, | ||
] | ||
}; | ||
const isCountry = isValidCountryObjectStructure(country); | ||
expect(isCountry).toEqual(true); | ||
}); | ||
|
||
test('Check for Interface export when Type Structure is Not Same', () => { | ||
const country = { | ||
phonecode: '+91', // missing name field | ||
isoCode: 'IN', | ||
flag: '🇮🇳' | ||
}; | ||
let isCountry = isValidCountryObjectStructure(country) | ||
expect(isCountry).toEqual(false); | ||
const country = { | ||
phonecode: '+91', // missing name field | ||
isoCode: 'IN', | ||
flag: '🇮🇳', | ||
}; | ||
const isCountry = isValidCountryObjectStructure(country); | ||
expect(isCountry).toEqual(false); | ||
}); | ||
|
||
function isValidCountryObjectAndValueType(object: any): object is ICountry { | ||
return typeof typeof object.name == "string" && typeof object.phonecode == "string" && typeof object.isoCode == "string" && typeof object.flag == "string"; | ||
return ( | ||
typeof typeof object.name === 'string' && | ||
typeof object.phonecode === 'string' && | ||
typeof object.isoCode === 'string' && | ||
typeof object.flag === 'string' | ||
); | ||
} | ||
|
||
test('Check for Interface export when Type Structure is Same and Value is of same type as well', () => { | ||
const country: ICountry = { | ||
name: 'India', | ||
phonecode: '+91', | ||
isoCode: 'IN', | ||
flag: '🇮🇳', | ||
currency: 'INR', | ||
latitude: '20.00000000', | ||
longitude: '77.00000000', | ||
timezones: [{"zoneName":"Asia\/Kolkata","gmtOffset":19800,"gmtOffsetName":"UTC+05:30","abbreviation":"IST","tzName":"Indian Standard Time"}] | ||
}; | ||
let isCountry = isValidCountryObjectAndValueType(country) | ||
expect(isCountry).toEqual(true); | ||
const country: ICountry = { | ||
name: 'India', | ||
phonecode: '+91', | ||
isoCode: 'IN', | ||
flag: '🇮🇳', | ||
currency: 'INR', | ||
latitude: '20.00000000', | ||
longitude: '77.00000000', | ||
timezones: [ | ||
{ | ||
zoneName: 'Asia/Kolkata', | ||
gmtOffset: 19800, | ||
gmtOffsetName: 'UTC+05:30', | ||
abbreviation: 'IST', | ||
tzName: 'Indian Standard Time', | ||
}, | ||
], | ||
}; | ||
const isCountry = isValidCountryObjectAndValueType(country); | ||
expect(isCountry).toEqual(true); | ||
}); | ||
|
||
test('Check for Interface export when Type Structure is Same and Value is of same type as well', () => { | ||
const country = { | ||
name: 'India', | ||
phonecode: 91, // wrong type | ||
isoCode: 'IN', | ||
flag: '🇮🇳', | ||
currency: 'INR', | ||
latitude: '20.00000000', | ||
longitude: '77.00000000', | ||
timezones: [{"zoneName":"Asia\/Kolkata","gmtOffset":19800,"gmtOffsetName":"UTC+05:30","abbreviation":"IST","tzName":"Indian Standard Time"}] | ||
}; | ||
let isCountry = isValidCountryObjectAndValueType(country) | ||
expect(isCountry).toEqual(false); | ||
const country = { | ||
name: 'India', | ||
phonecode: 91, // wrong type | ||
isoCode: 'IN', | ||
flag: '🇮🇳', | ||
currency: 'INR', | ||
latitude: '20.00000000', | ||
longitude: '77.00000000', | ||
timezones: [ | ||
{ | ||
zoneName: 'Asia/Kolkata', | ||
gmtOffset: 19800, | ||
gmtOffsetName: 'UTC+05:30', | ||
abbreviation: 'IST', | ||
tzName: 'Indian Standard Time', | ||
}, | ||
], | ||
}; | ||
const isCountry = isValidCountryObjectAndValueType(country); | ||
expect(isCountry).toEqual(false); | ||
}); | ||
|
File renamed without changes.
File renamed without changes.
File renamed without changes.
Oops, something went wrong.