UNPKG

@ecomplus/utils

Version:

JS utility functions to E-Com Plus (not only) related apps

50 lines (49 loc) 2.13 kB
"use strict"; 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"); var _formatDate = _interopRequireDefault(require("./format-date")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } 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 birthDate * @description Returns birth date formatted string from customer body object. * @param {Object.<string, *>} customer - Customer body object or birth date object with day, month and year * @returns {string} * * @example * // costumer will be the parameter of this function and as result will return his birth date * // const customer = object (body customer) * // customer can be like: * const costumer = { main_email: 'joejonh@me.com', birth_date: { year: 1990, month: 10, day: 1 } } * ecomUtils.birthDate(costumer) * // => "10/1/1990" */ var birthDate = function birthDate(customer) { if (_typeof(customer) === 'object' && customer !== null) { var birth = customer.birth_date || customer; if (birth) { var day = birth.day, month = birth.month, year = birth.year; if (day && month && year) { // has complete customer birth date // mount Date object and return formatted date string return (0, _formatDate.default)(new Date(year, month - 1, day)); } } } // returns empty string by default return ''; }; var _default = exports.default = birthDate;