New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@zootools/email-spell-checker

Package Overview
Dependencies
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@zootools/email-spell-checker - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

lib/lib/helpers/assert.d.ts

1

lib/index.d.ts
import checkMail from './lib/check-mail';
declare const MailSpellChecker: {
run: typeof checkMail;
POPULAR_DOMAINS: string[];
};
export default MailSpellChecker;

@@ -7,5 +7,7 @@ "use strict";

const check_mail_1 = __importDefault(require("./lib/check-mail"));
const config_1 = require("./lib/config");
const MailSpellChecker = {
run: check_mail_1.default,
POPULAR_DOMAINS: config_1.POPULAR_DOMAINS,
};
exports.default = MailSpellChecker;

17

lib/lib/check-mail.js

@@ -6,15 +6,14 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
const merge_1 = __importDefault(require("merge"));
const asser_valid_user_options_1 = __importDefault(require("./helpers/asser-valid-user-options"));
const suggest_email_1 = __importDefault(require("./suggest-email"));
const config_1 = require("./config");
const get_options_1 = __importDefault(require("./helpers/get-options"));
function checkMail(userOptions) {
const options = (0, merge_1.default)({}, config_1.DEFAULT_CONFIG, userOptions || {});
(0, asser_valid_user_options_1.default)(options || {});
const email = (0, suggest_email_1.default)(options);
if (!email && options.empty) {
options.empty();
const options = get_options_1.default(userOptions);
asser_valid_user_options_1.default(options || {});
const email = suggest_email_1.default(options);
if (!email && userOptions.empty) {
userOptions.empty();
}
if (email && options.suggested) {
options.suggested(email);
if (email && userOptions.suggested) {
userOptions.suggested(email);
}

@@ -21,0 +20,0 @@ return email;

@@ -0,2 +1,11 @@

/***
* Default list of popular emails for 2022 and onwards.
* https://www.mailmunch.com/blog/best-email-service-providers
*
* If you find a domain you want to add, please submit a PR.
* Also, notice that this list is not exhaustive.
* You can always pass your own list of domains.
*/
declare const POPULAR_DOMAINS: string[];
declare const POPULAR_TLDS: string[];
declare const DEFAULT_CONFIG: {

@@ -10,5 +19,3 @@ domainThreshold: number;

distanceFunction: any;
suggested: undefined;
empty: undefined;
};
export { DEFAULT_CONFIG, POPULAR_DOMAINS };
export { DEFAULT_CONFIG, POPULAR_DOMAINS, POPULAR_TLDS };

@@ -7,7 +7,13 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.POPULAR_DOMAINS = exports.DEFAULT_CONFIG = void 0;
exports.POPULAR_TLDS = exports.POPULAR_DOMAINS = exports.DEFAULT_CONFIG = void 0;
const distance_function_1 = __importDefault(require("../helpers/distance-function"));
/***
* Default list of popular emails for 2022 and onwards.
* https://www.mailmunch.com/blog/best-email-service-providers
*
* If you find a domain you want to add, please submit a PR.
* Also, notice that this list is not exhaustive.
* You can always pass your own list of domains.
*/
const POPULAR_DOMAINS = [
// Added list of popular mails in 2022 and onwards.
// https://www.mailmunch.com/blog/best-email-service-providers
'msn.com',

@@ -42,2 +48,3 @@ 'bellsouth.net',

'me.com',
'mailw.com',
'btinternet.com',

@@ -56,2 +63,74 @@ 'charter.net',

exports.POPULAR_DOMAINS = POPULAR_DOMAINS;
const POPULAR_TLDS = [
'com',
'com.au',
'com.tw',
'co',
'ca',
'co.nz',
'co.uk',
'de',
'fr',
'it',
'ru',
'org',
'edu',
'gov',
'jp',
'nl',
'kr',
'se',
'eu',
'ie',
'co.il',
'us',
'at',
'be',
'dk',
'hk',
'es',
'gr',
'ch',
'no',
'cz',
'net',
'net.au',
'info',
'biz',
'mil',
'co.jp',
'sg',
'hu',
'uk',
// popular TLDs that startup use in 2022
// https://thewebsiteflip.com/domains/funded-startup-brands-2021/#:~:text=from%20the%20data.-,1.,TLDs%20for%20the%20foreseeable%20future.
// https://martijnoud.com/most-popular-tld-crypto/
'app',
'au',
'ai',
'biz',
'br',
'blog',
'cloud',
'club',
'cc',
'de',
'dev',
'digital',
'fi',
'finance',
'id',
'in',
'io',
'me',
'mobi',
'network',
'pw',
'so',
'xyz',
'software',
'to',
'tech',
];
exports.POPULAR_TLDS = POPULAR_TLDS;
const DEFAULT_CONFIG = {

@@ -63,49 +142,5 @@ domainThreshold: 2,

topLevelThreshold: 2,
topLevelDomains: [
'com',
'com.au',
'com.tw',
'ca',
'co.nz',
'co.uk',
'de',
'fr',
'it',
'ru',
'net',
'org',
'edu',
'gov',
'jp',
'nl',
'kr',
'se',
'eu',
'ie',
'co.il',
'us',
'at',
'be',
'dk',
'hk',
'es',
'gr',
'ch',
'no',
'cz',
'in',
'net',
'net.au',
'info',
'biz',
'mil',
'co.jp',
'sg',
'hu',
'uk',
],
topLevelDomains: POPULAR_TLDS,
distanceFunction: distance_function_1.default,
suggested: undefined,
empty: undefined,
};
exports.DEFAULT_CONFIG = DEFAULT_CONFIG;

@@ -6,10 +6,9 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
const assert_1 = __importDefault(require("assert"));
const assert_1 = __importDefault(require("./assert"));
function assertValidUserOptions(options) {
(0, assert_1.default)(options.email, 'email is required');
(0, assert_1.default)(Array.isArray(options.domains), 'domains must be an array');
(0, assert_1.default)(Array.isArray(options.topLevelDomains), 'topLevelDomains must be an array');
(0, assert_1.default)(Array.isArray(options.secondLevelDomains), 'secondLevelDomains must be an array');
(0, assert_1.default)(typeof options.distanceFunction === 'function', 'distanceFunction must be a function');
assert_1.default(Array.isArray(options.domains), 'domains must be an array');
assert_1.default(Array.isArray(options.topLevelDomains), 'topLevelDomains must be an array');
assert_1.default(Array.isArray(options.secondLevelDomains), 'secondLevelDomains must be an array');
assert_1.default(typeof options.distanceFunction === 'function', 'distanceFunction must be a function');
}
exports.default = assertValidUserOptions;

@@ -9,3 +9,3 @@ "use strict";

function parseEmail(emailStr) {
const email = (0, trim_1.default)(emailStr);
const email = trim_1.default(emailStr);
const parts = email.split('@');

@@ -12,0 +12,0 @@ if (parts.length < MINIUM_EMAIL_PARTS) {

@@ -10,4 +10,4 @@ "use strict";

function suggestEmail(opts) {
const encodedEmail = (0, encode_email_1.default)(opts.email.toLowerCase());
const email = (0, parse_email_1.default)(encodedEmail);
const encodedEmail = encode_email_1.default(opts.email.toLowerCase());
const email = parse_email_1.default(encodedEmail);
if (!email) {

@@ -25,3 +25,3 @@ return undefined;

}
let closestDomain = (0, find_closest_domain_1.default)({
let closestDomain = find_closest_domain_1.default({
domain: email.domain,

@@ -47,3 +47,3 @@ domains,

// The email address does not closely match one of the supplied domains
const closestSecondLevelDomain = (0, find_closest_domain_1.default)({
const closestSecondLevelDomain = find_closest_domain_1.default({
domain: email.secondLevelDomain,

@@ -54,3 +54,3 @@ domains: secondLevelDomains,

});
const closestTopLevelDomain = (0, find_closest_domain_1.default)({
const closestTopLevelDomain = find_closest_domain_1.default({
domain: email.topLevelDomain,

@@ -57,0 +57,0 @@ domains: topLevelDomains,

{
"private": false,
"name": "@zootools/email-spell-checker",
"version": "1.0.0",
"version": "1.0.1",
"description": "mailSpellChecker.js (mail spell checker) is a lightweight module that suggests a right domain when your users misspell it in an email address",

@@ -50,23 +50,23 @@ "main": "./lib/index.js",

"devDependencies": {
"@ryansonshine/commitizen": "^4.2.8",
"@ryansonshine/commitizen": "4.2.8",
"@ryansonshine/cz-conventional-changelog": "^3.3.4",
"@semantic-release/git": "^10.0.1",
"@types/jest": "^27.5.2",
"@types/node": "^12.20.11",
"@types/trim": "^0.1.1",
"@typescript-eslint/eslint-plugin": "^4.22.0",
"@typescript-eslint/parser": "^4.22.0",
"conventional-changelog-conventionalcommits": "^5.0.0",
"eslint": "^7.25.0",
"@types/jest": "27.5.2",
"@types/node": "12.20.11",
"@types/trim": "0.1.1",
"@typescript-eslint/eslint-plugin": "4.22.0",
"@typescript-eslint/parser": "4.22.0",
"conventional-changelog-conventionalcommits": "5.0.0",
"eslint": "7.25.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^3.4.0",
"husky": "^6.0.0",
"jest": "^27.2.0",
"lint-staged": "^10.5.4",
"prettier": "^2.2.1",
"semantic-release": "^19.0.2",
"ts-jest": "^27.0.5",
"ts-node": "^10.2.1",
"typescript": "^4.2.4"
"husky": "6.0.0",
"jest": "27.2.0",
"lint-staged": "10.5.4",
"prettier": "2.2.1",
"semantic-release": "19.0.3",
"ts-jest": "27.0.5",
"ts-node": "10.2.1",
"typescript": "4.2.4"
},

@@ -136,7 +136,4 @@ "config": {

"dependencies": {
"assert": "^2.0.0",
"js-levenshtein": "^1.1.6",
"merge": "^2.1.1",
"trim": "^1.0.1"
"js-levenshtein": "1.1.6"
}
}
<p align="center">
<a href="https://zootools.co">
<picture>
<source media="(prefers-color-scheme: dark)" srcset="assets/email-spell-checker.png">
<img src="assets/email-spell-checker.png" height="128">
<source media="(prefers-color-scheme: dark)" srcset="assets/email-spell-checker-white.png?raw=true">
<img src="assets/email-spell-checker.png?raw=true" height="128">
</picture>

@@ -37,3 +37,3 @@ <p align="center">

- 🔋 <b>Updated</b>: 38+ supported popular domains out-of-the-box and continuously updated.
- 🔋 <b>Updated</b>: 39+ popular domains, and 66+ modern TLDs out-of-the-box and continuously updated.
- 💙 <b>TypeScript</b>: Fully written in TypeScript, cause we know you love it and we too.

@@ -44,5 +44,11 @@ - ⚡️ <b>Lighting fast</b>: Highly performance email checking using `js-levenshtein`, one of the fastest string distance JS modules.

## Some good use cases
- User authentication (login, signup, email recovery).
- Backend email validation.
- Newsletter subscriptions.
## Getting started
### Install
### Installation

@@ -52,3 +58,3 @@ _Install with npm:_

```bash
npm i @zootools/email-spell-checker --save
npm i @zootools/email-spell-checker --save
```

@@ -59,3 +65,3 @@

```bash
yarn add @zootools/email-spell-checker
yarn add @zootools/email-spell-checker
```

@@ -82,8 +88,32 @@

## Some good use cases
### Usage with custom configuration (advanced)
- User authentication (login, signup, email recovery).
- Backend email validation.
- Newsletter subscriptions.
The out-of-the box configuration is the best for every mainstream project. However, we know sometimes you want to pass extra configuration.
Bare in mind that the more domains, TLDs options you add, the slower the validation will take. That's why we recommend to avoid passing your custom configuration.
You can easily extend _EmailSpellChecker_ as you need:
```js
import emailSpellChecker from '@zootools/email-spell-checker';
const suggestedEmail = emailSpellChecker.run({
email: 'jorge@gmaik.co',
domains: DOMAINS,
topLevelDomains: [
...emailSpellChecker.POPULAR_DOMAINS,
'supercooldomain.com',
],
});
if (suggestedEmail) {
// Found bad spelled email...
// ...Tell your user to fix the email
console.log('address', suggestedEmail.address); // jorge
console.log('domain', suggestedEmail.domain); // gmail.com
console.log('full', suggestedEmail.full); // jorge@gmail.com
}
```
## How does it work?

@@ -90,0 +120,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc