New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

wikigeocode

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

wikigeocode

Simple utility to geocode an administrative location using the wikimedia APIs.

  • 1.5.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

wikigeocode

This tiny module performs the geocode of an administrative location (town, city, county, state, country, etc) using the wikimedia APIs, returning the wikipedia page title and the lat, lon coordinates if available, caching the results for an hour. For example:

> const {fetchSearchGeo} = require('wikigeocode')
> fetchSearchGeo('bogota').then(x => console.log(x))
> { pageid: 211271,
  ns: 0,
  title: 'Bogotá',
  coordinates:
   [ { lat: 4.71111111,
       lon: -74.07222222,
       primary: '',
       globe: 'earth' } ] }

The module only has an external node-fetch dependency to query the wikimedia APIs and Jest as dev dependency to run the tests.

Install

You can install with [npm]:

$ npm install --save wikigeocode

Usage

The module provides two main functions: fetchGeo to get the coordinates property from a wikipedia geographical entry and fetchExtract to get the summary (extract) of that particular page:

> const {fetchGeo, fetchExtra} = require('wikigeocode')
> fetchGeo('dublin').then(x => console.log(x))
> { pageid: 8504,
  ns: 0,
  title: 'Dublin',
  coordinates: [ { lat: 53.35, lon: -6.26666667, primary: '', globe: 'earth' } ] }

> fetchExtract('dublin').then(x => console.log(x))
>{ pageid: 8504,
  ns: 0,
  title: 'Dublin',
  extract: 'Dublin (; Irish: Baile Átha Cliath [ˈbˠalʲə aːhə ˈclʲiə; ˌbʲlʲaː ˈclʲiə]) is the capital of, and largest city in, Ireland ... '}

The previous two functions require the exact wikipedia page title. If you don't know the exact entry, you can use fetchSearchGeo and fetchSearchExtract to get the closest match to your query:

> const {fetchSearchGeo, fetchSearchExtra} = require('wikigeocode')
> fetchSearchGeo('londonderry').then(x => console.log(x))
> { pageid: 9055,
  ns: 0,
  title: 'Derry',
  coordinates: [ { lat: 54.9958, lon: -7.3074, primary: '', globe: 'earth' } ] }

> fetchSearchExtract('londonderry').then(x => console.log(x))
>{ pageid: 9055,
  ns: 0,
  title: 'Derry',
  extract: 'Derry, officially Londonderry (), is the second-largest city in Northern Ireland and the fourth-largest city on the island of Ireland. ...'}

License

Copyright © 2019, Juan Convers. Released under the MIT License.

Keywords

FAQs

Package last updated on 05 Dec 2022

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