country-timezone
Advanced tools
Comparing version 1.0.4 to 1.0.5
{ | ||
"name": "country-timezone", | ||
"version": "1.0.4", | ||
"version": "1.0.5", | ||
"description": "Find timezone based on country code or country name.", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
# country-timezone | ||
Find timezone based on country IOS code or country name | ||
Find timezone with country code and country name | ||
#### Install | ||
``` | ||
npm install country-timezone --save | ||
``` | ||
OR install with yarn | ||
``` | ||
yarn add country-timezone | ||
``` | ||
#### Get time with country name and country code | ||
``` | ||
import countryTimezone from 'country-timezone'; | ||
const timezonesWithName = countryTimezone.getTimezonesWithCountryName('India'); | ||
const timezonesWithCode = countryTimezone.getTimezonesWithCountryCode('IN'); | ||
console.log(timezonesWithName, timezonesWithCode); | ||
// [ 'Asia/Kolkata' ] [ 'Asia/Kolkata' ] | ||
``` |
@@ -10,4 +10,11 @@ var rawData = require('./data.json'); | ||
const matchedCountry = countries.find(function(country) { | ||
const removedSpaceName = name.replace(/^\s+|\s+$/g, ''); | ||
return country.name.toLowerCase() === removedSpaceName.toLowerCase() | ||
const lowerCountryName = country.name.toLowerCase().trim() | ||
const userEnteredCountryName = removedSpaceName.toLowerCase() | ||
// If user has entered both country name and city name together | ||
const nameSplit = name.toLowerCase().split(' ') | ||
return lowerCountryName === userEnteredCountryName || nameSplit.includes(lowerCountryName) | ||
}) | ||
@@ -14,0 +21,0 @@ |
34078
6
1937
23