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 1.0.0 to 1.0.1

.watchmanconfig

1

dist/index.d.ts

@@ -10,3 +10,4 @@ import { ICountry, ICity, IState } from './src/interface';

getAllCountries: () => ICountry[];
getCountryByCode: (code: string) => ICountry;
};
export default _default;

@@ -5,18 +5,32 @@ "use strict";

};
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
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 stateList;
var cityList;
Promise.resolve().then(function () { return __importStar(require('./lib/state.json')); }).then(function (states) {
stateList = states.default;
});
Promise.resolve().then(function () { return __importStar(require('./lib/city.json')); }).then(function (cities) {
cityList = cities.default;
});
exports.default = {
getCountryById: function (id) {
return _findEntry(country_json_1.default, id);
return _findEntryById(country_json_1.default, id);
},
getStateById: function (id) {
return _findEntry(state_json_1.default, id);
console.log(stateList, 'here...');
return _findEntryById(stateList, id);
},
getCityById: function (id) {
return _findEntry(city_json_1.default, id);
return _findEntryById(cityList, id);
},
getStatesOfCountry: function (countryId) {
var states = state_json_1.default.filter(function (value, index) {
var states = stateList.filter(function (value, index) {
return value.country_id === countryId;

@@ -27,3 +41,3 @@ });

getCitiesOfState: function (stateId) {
var cities = city_json_1.default.filter(function (value, index) {
var cities = cityList.filter(function (value, index) {
return value.state_id === stateId;

@@ -35,6 +49,14 @@ });

return country_json_1.default;
},
getCountryByCode: function (code) {
return _findEntryByCode(country_json_1.default, code);
}
};
var _findEntry = function (source, id) {
var _findEntryById = function (source, id) {
if (id && source != null) {
console.log(source, 'source');
console.log(source.prototype, 'source');
console.log(source.findIndex, 'source');
console.log(typeof source, 'source');
console.log(source instanceof Array, 'source');
var idx = source.findIndex(function (c) { return c.id === id; });

@@ -46,2 +68,10 @@ return (idx !== -1) ? source[idx] : "";

};
var _findEntryByCode = function (source, code) {
if (code && source != null) {
var codex = source.findIndex(function (c) { return c.sortname === code; });
return (codex !== -1) ? source[codex] : "";
}
else
return "";
};
function compare(a, b) {

@@ -48,0 +78,0 @@ if (a.name < b.name)

8

package.json
{
"name": "country-state-city",
"version": "1.0.0",
"version": "1.0.1",
"description": "Library for fetching Country, its States and Cities",

@@ -8,3 +8,3 @@ "main": "dist/index.js",

"scripts": {
"test": "jest",
"test": "npm run build && jest",
"build": "tsc -p tsconfig.json"

@@ -46,3 +46,5 @@ },

},
"dependencies": {}
"dependencies": {
"@types/node": "^12.7.5"
}
}

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

## Latest Release : `v1.0.0` (First Major Version Release - Not backword compatible)
## Latest Release : `v1.0.0` (First Major Version Release - Not backward compatible)
- ES6 Module usage
`import csc from 'country-state-city'`
```js
import csc from 'country-state-city'
// Import Interfaces`
import { ICountry, IState, ICity } from 'country-state-city'
```
- AMD Module usage
`let csc = require('country-state-city').default`
```js
let csc = require('country-state-city').default
```

@@ -29,11 +35,30 @@

`import csc from 'country-state-city'`
```js
import csc from 'country-state-city'
```
- AMD Module usage
`let csc = require('country-state-city')`
```js
let csc = require('country-state-city')
```
# Docs
getCountryByCode(code)
---------------
It accepts a valid `CountryCode` eg: `'AS'` and returns *Country Details*
type: **json | ICountry**
```js
{
"id": "4",
"sortname": "AS",
"name": "American Samoa",
"phonecode": "1684"
}
```
getCountryById(id)

@@ -40,0 +65,0 @@ ---------------

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