Skip to content

Commit

Permalink
refactor: use toE164 in common
Browse files Browse the repository at this point in the history
  • Loading branch information
lykmapipo committed Jun 16, 2019
1 parent 984a0d3 commit 08cfb4f
Showing 1 changed file with 2 additions and 16 deletions.
18 changes: 2 additions & 16 deletions lib/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
const { sortedUniq } = require('@lykmapipo/common');
const { getStrings } = require('@lykmapipo/env');
const { createSubSchema } = require('@lykmapipo/mongoose-common');
const { parsePhoneNumber } = require('@lykmapipo/phone');
const { toE164 } = require('@lykmapipo/phone');

/**
* @name toE164
Expand All @@ -18,21 +18,7 @@ const { parsePhoneNumber } = require('@lykmapipo/phone');
* @version 0.1.0
* @public
*/
exports.toE164 = (phoneNumber, countryCode) => {
// try convert give phone number to e.164
try {
const parsedNumber = parsePhoneNumber(phoneNumber, countryCode);
if (parsedNumber && parsedNumber.e164NoPlus) {
return parsedNumber.e164NoPlus;
}
return phoneNumber;
}

// fail to convert, return original format
catch (error) {
return phoneNumber;
}
};
exports.toE164 = toE164;

/**
* @description contact sub schema
Expand Down

0 comments on commit 08cfb4f

Please sign in to comment.