diginext-utils
Version:
README.md
39 lines • 2.08 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());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.emailValidator = void 0;
const deep_email_validator_1 = __importDefault(require("deep-email-validator"));
const toString_1 = __importDefault(require("lodash/toString"));
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.
const emailValidator = (email, opts) => __awaiter(void 0, void 0, void 0, function* () {
email = `${(0, toString_1.default)(email)}`;
const res = yield (0, deep_email_validator_1.default)(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 };
});
exports.emailValidator = emailValidator;
//# sourceMappingURL=index.js.map