diginext-utils
Version:
README.md
32 lines • 1.7 kB
JavaScript
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
import validate from "deep-email-validator";
import toString from "lodash/toString.js";
function extractReasons(emailValidatorOutput) {
const reasons = [];
// Loop through each validator
for (const key in emailValidatorOutput.validators) {
const validator = emailValidatorOutput.validators[key];
if (validator && validator.reason) {
reasons.push(validator.reason);
}
}
return reasons;
}
// SMTP Error: The mail address that you specified was not syntactically correct.
export const emailValidator = (email, opts) => __awaiter(void 0, void 0, void 0, function* () {
email = `${toString(email)}`;
const res = yield validate(Object.assign({ email: email, sender: email, validateRegex: true, validateMx: true, validateTypo: false, validateDisposable: true, validateSMTP: false }, opts));
if (res.valid)
return { status: true };
const reason = extractReasons(res);
return { status: false, reason };
});
//# sourceMappingURL=index.js.map