UNPKG

@ecomplus/utils

Version:

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

36 lines (33 loc) 1.14 kB
import formatDate from './format-date.mjs' /** * @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" */ const birthDate = customer => { if (typeof customer === 'object' && customer !== null) { let birth = customer.birth_date || customer if (birth) { let { day, month, year } = birth if (day && month && year) { // has complete customer birth date // mount Date object and return formatted date string return formatDate(new Date(year, month - 1, day)) } } } // returns empty string by default return '' } export default birthDate