email-utils

@email-utils/classifier/classify

The API of the classify entry point.

Interfaces

Classification

What the classifier knows about an address.

Properties

disposable
disposable: boolean;

From isDisposable.

provider
provider: ProviderInfo | undefined;

The mailbox provider, from getProvider.

role
role: boolean;

From isRoleAccount.

suggestion
suggestion: string | undefined;

A likely intended address when the domain looks like a typo, from suggestCorrection.


Classifier

classify and each check it makes, with options bound.

Methods

classify()
classify(email): Classification;
Parameters
ParameterType
emailstring | ParsedAddress
Returns

Classification

getProvider()
getProvider(email): ProviderInfo | undefined;
Parameters
ParameterType
emailstring | ParsedAddress
Returns

ProviderInfo | undefined

isDisposable()
isDisposable(email): boolean;
Parameters
ParameterType
emailstring | ParsedAddress
Returns

boolean

isRoleAccount()
isRoleAccount(email): boolean;
Parameters
ParameterType
emailstring | ParsedAddress
Returns

boolean

suggestCorrection()
suggestCorrection(email): string | undefined;
Parameters
ParameterType
emailstring | ParsedAddress
Returns

string | undefined


ClassifyOptions

How suggestCorrection matches a domain against the ones it knows.

Properties

domains?
optional domains?: readonly string[];

Domains that suggestCorrection corrects toward, ahead of the common mailbox domains, and never away from, such as your own company's. Compared without case.

ignore?
optional ignore?: readonly string[];

Domains that are never corrected and never corrected toward, compared without case. Replaces defaultIgnore, the real domains one edit from a common one; spread it in to keep them. Registry domains are never corrected either way.

Default Value

defaultIgnore

keyboard?
optional keyboard?: Keyboard;

The layout that key distance is measured on.

Default Value

'qwerty'

maxEdits?
optional maxEdits?: 0 | 1 | 2;

The most edits a domain may be from a known one and still be taken for it: 0 turns name corrections off, leaving only TLD fixes. 2 catches double slips like hotmal.co, and also turns some distinct domains, like yopmail.com, into common ones.

Default Value

1

maxKeyDistance?
optional maxKeyDistance?: number;

How many keys apart a typed letter may be from the intended one and still count as one edit: 1 for neighboring keys only. A letter farther away counts as two, a deletion and an insertion. Infinity counts any substitution as one edit.

Default Value

1

Type Aliases

Keyboard

type Keyboard = "qwerty" | "qwertz" | "azerty";

A keyboard layout that typo suggestions measure key distance on.

Variables

defaultIgnore

const defaultIgnore: readonly string[];

Widely used domains outside the registry that sit one edit from a common one and would otherwise be "corrected" to it. The ignore option replaces them, so spread them in to add your own.

Example

import {
  createClassifier,
  defaultIgnore,
} from '@email-utils/classifier/classify';

defaultIgnore.includes('mail.com'); // => true
createClassifier({ ignore: [...defaultIgnore, 'gmial.com'] })
  .suggestCorrection('ada@gmial.com'); // => undefined

Functions

classify()

function classify(email, options?): Classification;

The address's provider, whether it's disposable or a role account, and a suggested correction if its domain looks like a typo. A string is parsed once for all four.

Parameters

ParameterType
emailstring | ParsedAddress
options?ClassifyOptions

Returns

Classification

Example

import { classify } from '@email-utils/classifier/classify';

classify('ceo@mailinator.com');
// => { provider: undefined, disposable: true, role: true, suggestion: undefined }
classify('ada@gmial.com').suggestion; // => 'ada@gmail.com'
classify('ada@gmail.com', { maxKeyDistance: 0 }); // => throws TypeError

Throws

TypeError when email is neither a string nor a parsed address, or options are malformed.


createClassifier()

function createClassifier(options?): Classifier;

Binds options once, checking them up front, and returns classify and the checks it makes with them applied.

Parameters

ParameterType
options?ClassifyOptions

Returns

Classifier

Example

import { createClassifier } from '@email-utils/classifier/classify';

const classifier = createClassifier({ domains: ['example-corp.com'] });
classifier.suggestCorrection('ada@example-crop.com');
// => 'ada@example-corp.com'
classifier.classify('ada@example-corp.com');
// => { provider: undefined, suggestion: undefined }

Throws

TypeError when options are malformed.

On this page