Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"dependencies": {
"axios": "^1.4.0",
"currency-codes": "^1.5.1",
"email-validator": "^2.0.4",
"iso-3166-1": "^2.1.1",
"js-sha256": "^0.9.0",
"mixwith": "~0.1.1"
Expand Down
8 changes: 3 additions & 5 deletions src/objects/serverside/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import DeliveryCategory from './delivery-category.js';
const sha256 = require('js-sha256');
const currency_codes = require('currency-codes');
const country_codes = require('iso-3166-1');
const validator = require('email-validator');

const PHONE_NUMBER_IGNORE_CHAR_SET = /[\-@#<>'",; ]|\(|\)|\+|[a-z]/g;
const PHONE_NUMBER_DROP_PREFIX_ZEROS = /^\+?0{0,2}/;
Expand Down Expand Up @@ -153,15 +154,12 @@ export default class ServerSideUtils {
}

/**
* Normalizes the given email to RFC 822 standard and returns acceptable email value
* @param {String} [email] email value to be normalized.
* @return {String} Normalized email value.
*/
static normalizeEmail (email: string) {
// RFC 2822 REGEX approximation
const EMAIL_RE = /^[\w!#\$%&'\*\+\/\=\?\^`\{\|\}~\-]+(:?\.[\w!#\$%&'\*\+\/\=\?\^`\{\|\}~\-]+)*@(?:[a-z0-9](?:[a-z0-9\-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9\-]*[a-z0-9])?$/i;

if (!EMAIL_RE.test(email)) {
// Use email-validator to validate the email format
if (!validator.validate(email)) {
throw new Error("Invalid email format for the passed email:'" + email + "'.Please check the passed email format.");
}

Expand Down
Loading