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

city-timezones

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

city-timezones

A light and fast method of looking up timezones given the name of a city.

  • 1.3.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
36K
increased by6.23%
Maintainers
1
Weekly downloads
 
Created
Source

city-timezones

A light and fast method of looking up timezones given the name of a city.

npm install city-timezones
var cityTimezones = require('city-timezones');

cityTimezones.lookupViaCity(city: string)

If a city is found, returns an array of possible matches with city, state, lat, lng, timezone. Returns an empty [] if nothing matches. Multiple cities can be found if they have the same name, i.e. Springfield. A U.S. based city will contain a state_ansi property which is the abbreviated form of a US State ANSI State Table

finding based on city name of Chicago (case insensitive):

const cityLookup = cityTimezones.lookupViaCity('Chicago')
console.log(cityLookup)

Will return:

[ { city: 'Chicago',
    city_ascii: 'Chicago',
    lat: 41.82999066,
    lng: -87.75005497,
    pop: 5915976,
    country: 'United States of America',
    iso2: 'US',
    iso3: 'USA',
    province: 'Illinois',
    exactCity: 'Chicago',
    exactProvince: 'IL',
    state_ansi: 'IL',
    timezone: 'America/Chicago' } ]

cityTimezones.findFromCityStateProvince(searchString: string)

This method will return any partial match for the search term based on city, province, or country, or a combination thereof. A U.S. based city will also return matches for the state_ansi property.

finding based on search term of Springfield MO

const cityLookup = cityTimezones.findFromCityStateProvince('springfield mo')
console.log(cityLookup)

Will return:

[ { city: 'Springfield',
    city_ascii: 'Springfield',
    lat: 37.18001609,
    lng: -93.31999923,
    pop: 180691,
    country: 'United States of America',
    iso2: 'US',
    iso3: 'USA',
    province: 'Missouri',
    state_ansi: 'MO',
    timezone: 'America/Chicago' } ]	

cityTimezones.findFromIsoCode(iso_code: string)

If a iso code is found, returns an array of possible matches with city, state, lat, lng, timezone. Returns an empty [] if nothing matches. Multiple cities are returned if there are more than one city for the given iso code.

finding based on iso code of Germany (case insensitive):

const findFromIsoCode = cityTimezones.findFromIsoCode('DE')
console.log(findFromIsoCode)

Will return:

[
  {
    city: "Mainz",
    city_ascii: "Mainz",
    country: "Germany",
    iso2: "DE",
    iso3: "DEU",
    lat: 49.98247246,
    lng: 8.273219156,
    pop: 184997,
    province: "Rheinland-Pfalz",
    timezone: "Europe/Berlin"
  },
  ...
]

cityTimezones.cityMapping

This array will contain the full list of all available cities.

const cityMapping = cityTimezones.cityMapping
console.log(cityMapping)

Will return:

[
  {
    "city": "Qal eh-ye Now",
    "city_ascii": "Qal eh-ye",
    "lat": 34.98300013,
    "lng": 63.13329964,
    "pop": 2997,
    "country": "Afghanistan",
    "iso2": "AF",
    "iso3": "AFG",
    "province": "Badghis",
    "timezone": "Asia/Kabul"
  },
  {
    "city": "Chaghcharan",
    "city_ascii": "Chaghcharan",
    "lat": 34.5167011,
    "lng": 65.25000063,
    "pop": 15000,
    "country": "Afghanistan",
    "iso2": "AF",
    "iso3": "AFG",
    "province": "Ghor",
    "timezone": "Asia/Kabul"
  },
  ...
]	

Keywords

FAQs

Package last updated on 25 Jul 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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