Skip to content

Commit cb4f7e2

Browse files
committed
v0.1.0
0 parents  commit cb4f7e2

14 files changed

Lines changed: 8463 additions & 0 deletions

.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: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
# AbstractAPI javascript-phone-validation library
2+
3+
Integrate the powerful [Phone Validation API from Abstract](https://www.abstractapi.com/phone-validation-api) in your Javascript or NodeJS project in a few lines of code.
4+
5+
Abstract's Phone Number Validation and Verification API is a fast, lightweight, modern, and RESTful JSON API for determining the validity and other details of phone numbers from over 190 countries.
6+
7+
It's very simple to use: you only need to submit your API key and a phone number, and the API will respond as assessment of its validity, as well as additional details like the carrier details, line type, region and city details, and more.
8+
9+
Validating and verifying phone numbers 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-phone-validation** 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-phone-validation --save
23+
```
24+
25+
In your project, import it and configure your `API_KEY`:
26+
27+
```js
28+
import {AbstractPhoneValidation} from 'javascript-phone-validation'
29+
30+
AbstractPhoneValidation.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-phone-validation.js"></script>
39+
<script>
40+
AbstractPhoneValidation.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/phone-validation/pricing/select).
49+
50+
## Quickstart
51+
52+
AbstractAPI **javascript-phone-validation** 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 validatePhone(number) {
58+
let response = await AbstractPhoneValidation.verify(number);
59+
console.log(response);
60+
}
61+
```
62+
63+
### Using .then()
64+
65+
```js
66+
function validatePhone(number) {
67+
AbstractPhoneValidation.verify(number)
68+
.then(response => {
69+
console.log(response);
70+
})
71+
}
72+
```
73+
74+
## API response
75+
76+
The API response is returned in a `IpGeolocationData` object.
77+
78+
| PARAMETER | TYPE | DETAILS |
79+
| - | - | - |
80+
| number | String | The phone number submitted for validation and verification. |
81+
| valid | Boolean | Is true if the phone number submitted is valid. |
82+
| local_format | String | The local or national format of the submitted phone number. For example, it removes any international formatting, such as "+1" in the case of the US. |
83+
| international_format | String | The international format of the submitted phone number. This means appending the phone number's country code and a "+" at the beginning. |
84+
| country_name | String | The name of the country in which the phone number is registered. |
85+
| country_code | String | The country's two letter ISO 3166-1 alpha-2 code. |
86+
| country_prefix | The country's calling code prefix. |
87+
| registered_location | String | As much location details as are available from our data. This can include the region, state / province, and in some cases down to the city. |
88+
| carrier | String | The carrier that the number is registered with. |
89+
| line_type | String | The type of phone number. The possible values are: Landline, Mobile, Satellite, Premium, Paging, Special, Toll_Free, and Unknown. |
90+
91+
## Detailed documentation
92+
93+
You will find additional information and request examples in the [Abstract help page](https://app.abstractapi.com/api/phone-validation/documentation).
94+
95+
## Getting help
96+
97+
If you need help installing or using the library, please contact [Abstract's Support](https://app.abstractapi.com/api/phone-validation/support).
98+
99+
For bug report and feature suggestion, please use [this repository issues page](https://github.com/abstractapi/javascript-phone-validation/issues).
100+
101+
# Contribution
102+
103+
Contributions are always welcome, as they improve the quality of the libraries we provide to the community.
104+
105+
Please provide your changes covered by the appropriate unit tests, and post them in the [pull requests page](https://github.com/abstractapi/javascript-phone-validation/pulls).
106+
107+
## NPM
108+
109+
### Installation
110+
111+
Run `npm install` in the command line to install the dependencies. To update those dependencies you need to run `npm update`.
112+
113+
### Building
114+
115+
To build the library and generate the minified file in the *dist* directory, you need to run `npm run build`.
116+
117+
To build the lib, you need to run `npm run build:lib`.
118+
119+
### Test
120+
121+
To run the test suite, you need to run: `npm run test`.

dist/javascript-phone-validation.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: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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.AbstractPhoneValidation = 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 AbstractPhoneValidation = function AbstractPhoneValidation() {
21+
_classCallCheck(this, AbstractPhoneValidation);
22+
};
23+
24+
exports.AbstractPhoneValidation = AbstractPhoneValidation;
25+
26+
_defineProperty(AbstractPhoneValidation, "apiKey", void 0);
27+
28+
_defineProperty(AbstractPhoneValidation, "configure", function (apiKey) {
29+
AbstractPhoneValidation.apiKey = apiKey;
30+
});
31+
32+
_defineProperty(AbstractPhoneValidation, "verify", function (phone) {
33+
if (!phone) {
34+
throw new Error('Phone is not provided.');
35+
}
36+
37+
return core.makeApiCall('phonevalidation', AbstractPhoneValidation.apiKey, "phone=".concat(phone));
38+
});

0 commit comments

Comments
 (0)