npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

dialectica_geography

v1.1.29

Published

Geography tools get list of countries, get country continent, dial etc..

Downloads

93

Readme

Installation

  npm i dialectica_geography

Usage example

In Node

var mavenGeo = require('dialectica_geography');

In Html

mavenGeography.js is in dist folder minified version

 <script src="./your path/mavenGeography.js"></script>

In ES6

 import mavenGeo from "dialectica_geography";

List of Tools for countries and Continents

Find tools:

Get list of countries names (Afghanistan, Albania, etc...)

 mavenGeo.getListOfNamesCountries();

Get list of Continents (Europe, North, America, etc...)

 mavenGeo.getListOfContinents();

Get short Name of Country (AF, BH, etc..)

 mavenGeo.getNameShort("name of country");

Get Capital Name of Country

 mavenGeo.getCapital("name of country");

Get Continent of Country

 mavenGeo.getContinent("name of country");

Get Dial code of Country

 mavenGeo.getDial("name of country");

Get Currency code of Country

 mavenGeo.getCurrencyCode("name of country");

Get Currency name of Country

 mavenGeo.getCurrencyName("name of country");

Get Total area of Country

 mavenGeo.getTotalArea("name of country");

Get Geoname ID of Country

 mavenGeo.getGeonameID("name of country");

Get country name from Country short name

For example Greece is the country name for short name 'GR'.

 mavenGeo.getCountryFromShortName("short name of country");

Show country flag

Works only on browser environment not in node.js.

 mavenGeo.showCountryFlag('element to show', 'short name of country');
Example:
  //Suppose in html we have the element
  <img id='imgId'/>

  let element = document.getElementById('imgId');
  //or jquery
  let element = $('#imgId');
  //Country to show flag Greece. Short name of Greece is 'gr'
  mavenGeo.showCountryFlag(element, 'gr');

Get geolocation from ip

 mavenGeo.getGeolocationJsonFromIp("globalObject", ip);

globalObject values are: "window", "node", "local".

When testing from localHost and library is loaded as a script for example

 <script src="./dist/mavenGeography.js"></script>

or from browser address bar like this

file://path..../index.html => (script is inside index.html)

we choose globalObject local to avoid Cors errors => response header Origin: null

Above function returns a promise.

Example:
  let data = await mavenGeo.getGeolocationJsonFromIp("local", "10.0.0.0");
  //We can use also .then(function(res) {})
  //Then we use the function fetchGeolocationFromJson(data) to get location
  let test = mavenGeo.fetchGeolocationFromJson(data);
  console.log(test);
  //The result is for example "52.37559917665907 4.888916015625"
Example node:
  //First we require https node js library and then passing to function
  const https = require('https');
  let data = await mavenGeo.getGeolocationJsonFromIp("node", "10.0.0.0", https);
  //We can use also .then(function(res) {})
  //Then we use the function fetchGeolocationFromJson(data) to get location
  let test = mavenGeo.fetchGeolocationFromJson(data);
  console.log(test);
  //The result is for example "52.37559917665907 4.888916015625"

Get country short name from ip

 mavenGeo.getCountryJsonFromIp("globalObject", ip);

globalObject values are: "window", "node", "local".

When testing from localHost and library is loaded as a script for example

 <script src="./dist/mavenGeography.js"></script>

or from browser address bar like this

file://..../index.html => (script is inside index.html)

we choose globalObject local to avoid Cors errors => response header Origin: null

Above function returns a promise.

Example:
  let data = await mavenGeo.getCountryJsonFromIp("local", "10.0.0.0");
  //We can use also .then(function(res) {})
  //Then we use the function fetchCountryFromJson(data) to get location
  let test = mavenGeo.fetchCountryFromJson(data);
  console.log(test);
  //The result is for example "GR".
Example node:
  //First we require https node js library and then passing to function
  const https = require('https');
  let data = await mavenGeo.getCountryJsonFromIp("node", "10.0.0.0", https);
  //We can use also .then(function(res) {})
  //Then we use the function fetchCountryFromJson(data) to get location
  let test = mavenGeo.fetchCountryFromJson(data);
  console.log(test);
  ////The result is for example "GR".

Check tools:

Check if country belongs to Continent

 mavenGeo.isContinent("name of country", "continent name");

Check if country belongs to APAC

 mavenGeo.isApac("name of country");

Check if country belongs to Nordigs

 mavenGeo.isNordigs("name of country");

Check if country belongs to DACH

 mavenGeo.isDach("name of country");

Check if country belongs to Benelux

 mavenGeo.isBenelux("name of country");