Socket
Socket
Sign inDemoInstall

location-database

Package Overview
Dependencies
0
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    location-database

This package contains a list of countries, cities, states and time-zones and derives information from three different repositories


Version published
Weekly downloads
3
increased by200%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

Location Database

Curated database in JSON format of countries, states, cities and timezones This data has been curated from three different souces with priority to the first one

Install via npm

npm install location-database

Methods

const ld = require('location-database')

getAll()

Returns the entire database

getCountryByCode(code)

Pass the iso2 country code (e.g. US) to get entire information on that country. Returns an empty array for no data found.

country object looks like

{ 
      id: 233,
      name: 'United States',
      iso3: 'USA',
      iso2: 'US',
      phone_code: '1',
      capital: 'Washington D.C.',
      currency: 'USD',
      native: 'United States',
      continent: 'NA',
      languages: [ 'en' ],
      emoji: '🇺🇸',
      emojiU: 'U+1F1FA U+1F1F8',
      states: [...],
      timezones: [...]
}

getStatesByCode(code)

Pass the iso2 country code (e.g. US) to get an array of states for that country. Returns an empty array for no data found.

state object looks like

{ 
      id: 1456,
      name: 'Alabama',
      country_id: 233,
      country_code: 'US',
      state_code: 'AL',
      cities: [...] 
}

getTimezonesByCode(code)

Pass the iso2 country code (e.g. US) to get an array of timezones for that country. Returns an empty array for no data found.

timezone object looks like

{ 
      name: 'America/Adak',
      country: 'US',
      utcOffset: -600,
      utcOffsetStr: '-10:00',
      dstOffset: -540,
      dstOffsetStr: '-09:00',
      aliasOf: null,
      country_code: 'US',
      country_id: 233
}

getCities(code, stateCode)

Pass the iso2 country code (e.g. US) and the state code to get an array of cities for that country and state combination. Returns an empty array for no data found.

city object looks like

{ 
      id: '114994',
      name: 'Dallas County',
      state_id: 1456,
      state_code: 'AL',
      country_id: 233,
      country_code: 'US',
      latitude: '32.32597000',
      longitude: '-87.10648000' 
}

Scripts

  • npm run lint to lint code, eslint standard being used
  • npm run lint:fix to auto fix linting where possible
  • npm run build to compile the database, it overwrites db.json in src
  • npm run test to run tests

FAQs

Last updated on 18 Dec 2019

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc