@ecomplus/utils
Version:
JS utility functions to E-Com Plus (not only) related apps
44 lines (43 loc) • 1.67 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
require("core-js/modules/es.symbol.js");
require("core-js/modules/es.symbol.description.js");
require("core-js/modules/es.object.to-string.js");
require("core-js/modules/es.symbol.iterator.js");
require("core-js/modules/es.array.iterator.js");
require("core-js/modules/es.string.iterator.js");
require("core-js/modules/web.dom-collections.iterator.js");
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
/**
* @method
* @memberof ecomUtils
* @name phone
* @description Returns phone string from customer body or phone object.
* @param {Object.<string, *>} customer - Customer body object or phone object with number property
* @returns {string}
*
* @example
* const customer = { 'number': '31992980000'}
* ecomUtils.phone(customer)
* // => '31992980000'
*/
var phone = function phone(customer) {
// empty string by default
var phoneString = '';
if (_typeof(customer) === 'object' && customer !== null) {
var _phone = Array.isArray(customer.phones)
// use first customer phone by default
? customer.phones[0] : customer;
if (_phone && _phone.number) {
if (_phone.country_code) {
phoneString = "+".concat(_phone.country_code, " ");
}
phoneString += _phone.number;
}
}
return phoneString;
};
var _default = exports.default = phone;