1.1.29 • Published 5 years ago

dialectica_geography v1.1.29

Weekly downloads
4
License
ISC
Repository
-
Last release
5 years ago

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");
1.1.29

5 years ago

1.1.28

5 years ago

1.1.27

5 years ago

1.1.26

5 years ago

1.1.25

5 years ago

1.1.24

5 years ago

1.1.23

5 years ago

1.1.22

5 years ago

1.1.21

5 years ago

1.1.20

5 years ago

1.1.19

5 years ago

1.1.18

5 years ago

1.1.17

5 years ago

1.1.16

5 years ago

1.1.15

5 years ago

1.1.14

5 years ago

1.1.13

5 years ago

1.1.12

5 years ago

1.1.11

5 years ago

1.1.10

5 years ago

1.1.9

5 years ago

1.1.8

5 years ago

1.1.7

5 years ago

1.1.6

5 years ago

1.1.5

5 years ago

1.1.4

5 years ago

1.1.3

5 years ago

1.1.2

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.9

5 years ago

1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago