Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

country-state-city

Package Overview
Dependencies
Maintainers
1
Versions
41
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

country-state-city - npm Package Compare versions

Comparing version 2.2.0 to 3.0.0

assets/city.json

20

dist/index.d.ts

@@ -1,14 +0,6 @@

import { ICountry, ICity, IState } from './src/interface';
export { ICountry, ICity, IState } from './src/interface';
declare const _default: {
getStatesOfCountry(countryCode: string): IState[];
getCitiesOfState(countryCode: string, stateCode: string): ICity[];
getCitiesOfCountry(countryCode: string): ICity[];
getAllCountries(): ICountry[];
getAllStates(): IState[];
getAllCities(): ICity[];
getCountryByCode(isoCode: string): ICountry;
getStateByCode(isoCode: string): IState;
getStateByCodeAndCountry(isoCode: string, countryCode: string): IState;
};
export default _default;
import Country from './lib/country';
import State from './lib/state';
import City from './lib/city';
export { Country };
export { State };
export { City };

@@ -6,70 +6,8 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
var country_json_1 = __importDefault(require("./lib/country.json"));
var state_json_1 = __importDefault(require("./lib/state.json"));
var city_json_1 = __importDefault(require("./lib/city.json"));
var _findEntryByCode = function (source, code) {
if (code && source != null) {
var codex = source.findIndex(function (c) {
return c.isoCode === code;
});
return codex !== -1 ? source[codex] : '';
}
return '';
};
var _findStateByCodeAndCountryCode = function (source, code, countryCode) {
if (code && countryCode && source != null) {
var codex = source.findIndex(function (c) {
return c.isoCode === code && c.countryCode === countryCode;
});
return codex !== -1 ? source[codex] : '';
}
return '';
};
var compare = function (a, b) {
if (a.name < b.name)
return -1;
if (a.name > b.name)
return 1;
return 0;
};
exports.default = {
getStatesOfCountry: function (countryCode) {
var states = state_json_1.default.filter(function (value) {
return value.countryCode === countryCode;
});
return states.sort(compare);
},
getCitiesOfState: function (countryCode, stateCode) {
var cities = city_json_1.default.filter(function (value) {
return value.countryCode === countryCode && value.stateCode === stateCode;
});
return cities.sort(compare);
},
getCitiesOfCountry: function (countryCode) {
var cities = city_json_1.default.filter(function (value) {
return value.countryCode === countryCode;
});
return cities.sort(compare);
},
getAllCountries: function () {
return country_json_1.default;
},
getAllStates: function () {
return state_json_1.default;
},
getAllCities: function () {
return city_json_1.default;
},
getCountryByCode: function (isoCode) {
return _findEntryByCode(country_json_1.default, isoCode);
},
// to be deprecate
getStateByCode: function (isoCode) {
// eslint-disable-next-line no-console
console.warn("WARNING! 'getStateByCode' has been deprecated, please use the new 'getStateByCodeAndCountry' function instead!");
return _findEntryByCode(state_json_1.default, isoCode);
},
getStateByCodeAndCountry: function (isoCode, countryCode) {
return _findStateByCodeAndCountryCode(state_json_1.default, isoCode, countryCode);
},
};
exports.City = exports.State = exports.Country = void 0;
var country_1 = __importDefault(require("./lib/country"));
exports.Country = country_1.default;
var state_1 = __importDefault(require("./lib/state"));
exports.State = state_1.default;
var city_1 = __importDefault(require("./lib/city"));
exports.City = city_1.default;
{
"name": "country-state-city",
"version": "2.2.0",
"version": "3.0.0",
"description": "Library for fetching Country, its States and Cities",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"sideEffects": false,
"scripts": {
"test": "jest",
"build": "tsc -p tsconfig.json",
"build-ts": "tsc -p tsconfig.json",
"build": "npm run build-ts",
"lint": "eslint index.ts __test__ --fix"

@@ -52,7 +54,13 @@ },

"jest": "^26.6.3",
"json-minimizer-webpack-plugin": "^3.0.0",
"prettier": "^2.2.1",
"ts-jest": "^26.4.4",
"typescript": "^4.1.3"
"ts-loader": "^9.2.3",
"typescript": "^4.3.2",
"webpack": "^5.38.1",
"webpack-cli": "^4.7.2"
},
"dependencies": {}
"dependencies": {
"copy-webpack-plugin": "^9.0.0"
}
}

@@ -14,10 +14,14 @@ country-state-city

## Release : `v2.0.0` (Major Version Release - Not backward compatible)
## Release : `v3.0.0` (Major Version Release - Not backward compatible)
- ES6 Module usage
```js
import csc from 'country-state-city'
// Latest version - v3.0.0 with Tree Shaking to reduce bundle size
import { Country, State, City } from 'country-state-city';
console.log(Country.getAllCountries())
console.log(State.getAllStates())
// Import Interfaces`
import { ICountry, IState, ICity } from 'country-state-city'
import { ICountry, IState, ICity } from 'country-state-city'
```

@@ -27,7 +31,13 @@ - AMD Module usage

```js
let csc = require('country-state-city').default
// 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())
```
## For versions `v0.1.8 and below`
## For versions `below v2.2.0 and above v0.1.8`

@@ -37,3 +47,3 @@ - ES6 Module usage

```js
import csc from 'country-state-city'
import csc from 'country-state-city';
```

@@ -44,3 +54,3 @@

```js
let csc = require('country-state-city')
let csc = require('country-state-city').default;
```

@@ -227,38 +237,2 @@

Change Logs
---------------
**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
[taylorthurlow](https://github.com/taylorthurlow) - For pointing into right direction - Module Tree Shaking

@@ -17,2 +17,2 @@ {

]
}
}
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