Skip to content

Commit 51c98b0

Browse files
committed
v0.1.0
0 parents  commit 51c98b0

File tree

14 files changed

+8532
-0
lines changed

14 files changed

+8532
-0
lines changed

.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: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
# AbstractAPI javascript-email-validation library
2+
3+
Integrate the powerful [email validation API from Abstract](https://www.abstractapi.com/email-verification-validation-api) in your Javascript or NodeJS project in a few lines of code.
4+
5+
Abstract's Email Validation and Verification API is a fast, lightweight, modern, and RESTful JSON API for determining the validity and other details of email addresses.
6+
7+
It's very simple to use: you only need to submit your API key and an email address, and the API will respond an assessment of its validity, as well as additional details like quality score if it's a disposable email, a catchall address, and more.
8+
9+
Validating and verifying email 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-email-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-email-validation --save
23+
```
24+
25+
In your project, import it and configure your `API_KEY`:
26+
27+
```js
28+
import {AbstractEmailValidation} from 'javascript-email-validation'
29+
30+
AbstractEmailValidation.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-email-validation.js"></script>
39+
<script>
40+
AbstractEmailValidation.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/email-validation/pricing/select).
49+
50+
## Quickstart
51+
52+
AbstractAPI **javascript-email-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 validateEmail(email) {
58+
let response = await AbstractEmailValidation.verify(email);
59+
console.log(response);
60+
}
61+
```
62+
63+
### Using .then()
64+
65+
```js
66+
function validateEmail(email) {
67+
AbstractEmailValidation.verify(email)
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+
| email | String | The value for "email" that was entered into the request. |
81+
| auto_correct | String | If a typo has been detected then this parameter returns a suggestion of the correct email (e.g., johnsmith@gmial.com => johnsmith@gmail.com). If no typo is detected then this is empty. |
82+
| deliverability | String | Abstract's evaluation of the deliverability of the email. Possible values are: DELIVERABLE, UNDELIVERABLE, RISKY, and UNKNOWN |
83+
| quality_score | Number | An internal decimal score between 0.01 and 0.99 reflecting Abstract's confidence in the quality and deliverability of the submitted email. |
84+
| is_valid_format | Boolean | Is true if the email follows the format of "address @ domain . TLD". If any of those elements are missing or if they contain extra or incorrect special characters, then it returns false. |
85+
| is_free_email | Boolean | Is true if the email's domain is found among Abstract's list of free email providers (e.g., Gmail, Yahoo, etc). |
86+
| is_disposable_email | Boolean | Is true if the email's domain is found among Abstract's list of disposable email providers (e.g., Mailinator, Yopmail, etc). |
87+
| is_role_email | Boolean | Is true if the email's local part (e.g., the "to" part) appears to be for a role rather than individual. Examples of this include "team@", "sales@", info@", etc. |
88+
| is_catchall_email | Boolean | Is true if the domain is configured to catch all email. |
89+
| is_mx_found | Boolean | Is true if MX Records for the domain can be found. Only available on paid plans. Will return null and UNKNOWN on free plans. |
90+
| is_smtp_valid | Boolean | Is true is the SMTP check of the domain was successful. Only available on paid plans. Will return null and UNKNOWN on free plans. |
91+
92+
## Detailed documentation
93+
94+
You will find additional information and request examples in the [Abstract help page](https://app.abstractapi.com/api/email-validation/documentation).
95+
96+
## Getting help
97+
98+
If you need help installing or using the library, please contact [Abstract's Support](https://app.abstractapi.com/api/email-validation/support).
99+
100+
For bug report and feature suggestion, please use [this repository issues page](https://github.com/abstractapi/javascript-email-validation/issues).
101+
102+
# Contribution
103+
104+
Contributions are always welcome, as they improve the quality of the libraries we provide to the community.
105+
106+
Please provide your changes covered by the appropriate unit tests, and post them in the [pull requests page](https://github.com/abstractapi/javascript-email-validation/pulls).
107+
108+
## NPM
109+
110+
### Installation
111+
112+
Run `npm install` in the command line to install the dependencies. To update those dependencies you need to run `npm update`.
113+
114+
### Building
115+
116+
To build the library and generate the minified file in the *dist* directory, you need to run `npm run build`.
117+
118+
To build the lib, you need to run `npm run build:lib`.
119+
120+
### Test
121+
122+
To run the test suite, you need to run: `npm run test`.
123+

dist/javascript-email-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: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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.AbstractEmailValidation = 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 AbstractEmailValidation = function AbstractEmailValidation() {
21+
_classCallCheck(this, AbstractEmailValidation);
22+
};
23+
24+
exports.AbstractEmailValidation = AbstractEmailValidation;
25+
26+
_defineProperty(AbstractEmailValidation, "apiKey", void 0);
27+
28+
_defineProperty(AbstractEmailValidation, "configure", function (apiKey) {
29+
AbstractEmailValidation.apiKey = apiKey;
30+
});
31+
32+
_defineProperty(AbstractEmailValidation, "verify", function (email) {
33+
if (!email) {
34+
throw new Error('Email is not provided.');
35+
}
36+
37+
var self = AbstractEmailValidation;
38+
return core.makeApiCall('emailvalidation', self.apiKey, "email=".concat(email)).then(function (response) {
39+
// modify response so it returns Boolean instead of object
40+
var modifiedResponse = response;
41+
modifiedResponse['is_catchall_email'] = response.is_catchall_email.value;
42+
modifiedResponse['is_disposable_email'] = response.is_disposable_email.value;
43+
modifiedResponse['is_free_email'] = response.is_free_email.value;
44+
modifiedResponse['is_mx_found'] = response.is_mx_found.value;
45+
modifiedResponse['is_role_email'] = response.is_role_email.value;
46+
modifiedResponse['is_smtp_valid'] = response.is_smtp_valid.value;
47+
modifiedResponse['is_valid_format'] = response.is_valid_format.value;
48+
return modifiedResponse;
49+
})["catch"](function (error) {
50+
return error;
51+
});
52+
});

0 commit comments

Comments
 (0)