Skip to content

Commit 0ee9240

Browse files
committed
v0.1.0
0 parents  commit 0ee9240

14 files changed

Lines changed: 8503 additions & 0 deletions

File tree

.babelrc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"presets": [
3+
"@babel/preset-env"
4+
],
5+
"plugins": [
6+
["@babel/plugin-proposal-class-properties"],
7+
["@babel/plugin-transform-async-to-generator"]
8+
]
9+
}

.github/workflows/unittest.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Unit test
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
unit_test:
7+
runs-on: ${{ matrix.operating-system }}
8+
strategy:
9+
matrix:
10+
operating-system: [ ubuntu-18.04, windows-2016 ]
11+
node-version: [10.x, 12.x, 14.x, 15.x]
12+
13+
env:
14+
EMAIL_VALIDATION_API_KEY: ${{ secrets.API_KEY }}
15+
16+
steps:
17+
- uses: actions/checkout@v2
18+
19+
- name: Use Node.js ${{ matrix.node-version }}
20+
uses: actions/setup-node@v1
21+
with:
22+
node-version: ${{ matrix.node-version }}
23+
24+
- name: Run test
25+
run: |
26+
npm install
27+
npm run test

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
.idea

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2021 Abstract
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
# AbstractAPI javascript-ip-geolocation library
2+
3+
Integrate the powerful [IP Geolocation API from Abstract](https://www.abstractapi.com/ip-geolocation-api) in your Javascript or NodeJS project in a few lines of code.
4+
5+
Abstract's IP Geolocation API is a fast, lightweight, modern, and RESTful JSON API allowing you to look up the location, timezone, country details, and more of an IPv4 or IPv6 address.
6+
7+
It's very simple to use: you only need to submit your API key and an IP address, and the API will respond with an assessment of its geographical location, as well as additional details like the timezone, if it's a VPN address, and more.
8+
9+
Validating and verifying IP addresses is a critical step to reducing the chances of low-quality data and fraudulent or risky users in your website or application.
10+
11+
# Documentation
12+
13+
## Installation
14+
15+
You can install **javascript-ip-geolocation** via npm, from our CDN, or download the source into your project.
16+
17+
### ES6
18+
19+
Download and install the library from npm:
20+
21+
```
22+
npm install javascript-ip-geolocation --save
23+
```
24+
25+
In your project, import it and configure your `API_KEY`:
26+
27+
```js
28+
import {AbstractIpGeolocation} from 'javascript-ip-geolocation'
29+
30+
AbstractIpGeolocation.configure('API_KEY')
31+
```
32+
33+
### Browser, from the built file
34+
35+
You can build the library yourself, or get the already built file from the `dist` directory and load it:
36+
37+
```js
38+
<script src="dist/javascript-ip-geolocation.js"></script>
39+
<script>
40+
AbstractIpGeolocation.configure('API_KEY');
41+
42+
// use the library
43+
</script>
44+
```
45+
46+
## API key
47+
48+
Get your API key for free and without hassle from the [Abstact website](https://app.abstractapi.com/users/signup?target=/api/ip-geolocation/pricing/select).
49+
50+
## Quickstart
51+
52+
AbstractAPI **javascript-ip-geolocation** library returns a [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) so you can use one of the following approaches:
53+
54+
### Async/Await
55+
56+
```js
57+
async function validateIP(ipAddress) {
58+
let response = await AbstractIpGeolocation.look_up(ipAddress);
59+
console.log(response);
60+
}
61+
```
62+
63+
### Using .then()
64+
65+
```js
66+
function validateIP(ipAddress) {
67+
AbstractIpGeolocation.look_up(ipAddress)
68+
.then(response => {
69+
console.log(response);
70+
})
71+
}
72+
```
73+
74+
## API response
75+
76+
The API response contains the following fields:
77+
78+
| PARAMETER | TYPE | DETAILS |
79+
| - | - | - |
80+
| Parameter | Type | Details |
81+
| ip_address | String | The requested IP address |
82+
| city | String | City's name. |
83+
| city_geoname_id | String | City's geoname ID. |
84+
| region | String | State or province in which the the city is located. |
85+
| region_iso_code | Char[2] | State or province's ISO 3166-2 code. |
86+
| region_geoname_id | String | State or province's geoname ID. |
87+
| postal_code | String | ZIP or postal code. |
88+
| country | String | Country's name. |
89+
| country_code | Char[2] | Country's ISO 3166-1 alpha-2 code. |
90+
| country_geoname_id | String | Country's geoname ID. |
91+
| country_is_eu | Boolean | True if the country is in the EU, false if it is not. |
92+
| continent | String | Continent's name. |
93+
| continent_code | Char[2] | 2 letter continent code: AF, AS, EU, NA, OC, SA, AN |
94+
| continent_geoname_id | String | Continent's geoname ID. |
95+
| longitude | Float | Decimal of the longitude. |
96+
| latitude | Float | Decimal of the latitude. |
97+
| security > is_vpn | Boolean | Whether the IP address is using from a VPN or using a proxy |
98+
| timezone > name | String | Timezone's name from the IANA Time Zone Database. |
99+
| timezone > abbreviation | String | Timezone's abbreviation, also from the IANA Time Zone Database. |
100+
| timezone > gmt_offset | String | Timezone's offset from Greenwich Mean Time (GMT). |
101+
| timezone > current_time | String | Current time in the local time zone. |
102+
| timezone > is_dst | Boolean | True if the location is currently in Daylight Savings Time (DST). |
103+
| flag > svg | String | Link to a hosted version of the country's flag in SVG format. |
104+
| flag > png | String | Link to a hosted version of the country's flag in PNG format. |
105+
| flag > emoji | String | Country's flag as an emoji. |
106+
| flag > unicode | String | Country's flag in unicode. |
107+
| currency > currency_name | String | The currency's name. |
108+
| currency > currency_code | String | The currency's code in ISO 4217 format. |
109+
| connection > connection_type | String | Type of network connection: Dialup, Cable/DSL, Cellular, Corporate |
110+
| connection > autonomous_system_number | Uint32 | Autonomous System number |
111+
| connection > autonomous_system_organization | String | Autonomous System Organization name. |
112+
| connection > isp_name | String | Internet Service Provider (ISP) name. |
113+
| connection > organization_name | String | Organization name. |
114+
115+
## Detailed documentation
116+
117+
You will find additional information and request examples in the [Abstract help page](https://app.abstractapi.com/api/ip-geolocation/documentation).
118+
119+
## Getting help
120+
121+
If you need help installing or using the library, please contact [Abstract's Support](https://app.abstractapi.com/api/ip-geolocation/support).
122+
123+
For bug report and feature suggestion, please use [this repository issues page](https://github.com/abstractapi/javascript-ip-geolocation/issues).
124+
125+
# Contribution
126+
127+
Contributions are always welcome, as they improve the quality of the libraries we provide to the community.
128+
129+
Please provide your changes covered by the appropriate unit tests, and post them in the [pull requests page](https://github.com/abstractapi/javascript-ip-geolocation/pulls).
130+
131+
## NPM
132+
133+
### Installation
134+
135+
Run `npm install` in the command line to install the dependencies. To update those dependencies you need to run `npm update`.
136+
137+
### Building
138+
139+
To build the library and generate the minified file in the *dist* directory, you need to run `npm run build`.
140+
141+
To build the lib, you need to run `npm run build:lib`.
142+
143+
### Test
144+
145+
To run the test suite, you need to run: `npm run test`.
146+

dist/javascript-ip-geolocation.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = require('./lib/index');

lib/index.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
"use strict";
2+
3+
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
4+
5+
Object.defineProperty(exports, "__esModule", {
6+
value: true
7+
});
8+
exports.AbstractIpGeolocation = void 0;
9+
10+
var core = _interopRequireWildcard(require("javascript-core"));
11+
12+
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }
13+
14+
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
15+
16+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
17+
18+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
19+
20+
var AbstractIpGeolocation = function AbstractIpGeolocation() {
21+
_classCallCheck(this, AbstractIpGeolocation);
22+
};
23+
24+
exports.AbstractIpGeolocation = AbstractIpGeolocation;
25+
26+
_defineProperty(AbstractIpGeolocation, "apiKey", void 0);
27+
28+
_defineProperty(AbstractIpGeolocation, "configure", function (apiKey) {
29+
AbstractIpGeolocation.apiKey = apiKey;
30+
});
31+
32+
_defineProperty(AbstractIpGeolocation, "look_up", function (ipAddress) {
33+
var ipAddressParam = '';
34+
35+
if (ipAddress) {
36+
ipAddressParam = "ip_address=".concat(ipAddress);
37+
}
38+
39+
return core.makeApiCall('ipgeolocation', AbstractIpGeolocation.apiKey, ipAddressParam);
40+
});

0 commit comments

Comments
 (0)