@windingtree/wt-write-api
Version:
API to write data to the Winding Tree platform
45 lines (39 loc) • 1.24 kB
JavaScript
function normalizeEmail (email) {
return email && email.trim().toLowerCase();
}
function normalizePhone (phone) {
if (!phone) {
return;
}
const normalizedPhone = phone.trim().replace(/ |-|\(|\)/gi, '');
if (normalizedPhone.substring(0, 2) === '00') {
return '+' + normalizedPhone.substring(2);
}
return normalizedPhone;
}
function normalizeNestedContacts (description) {
if (description.contacts && description.contacts.general) {
if (description.contacts.general.email) {
description.contacts.general.email = normalizeEmail(description.contacts.general.email);
}
if (description.contacts.general.phone) {
description.contacts.general.phone = normalizePhone(description.contacts.general.phone);
}
}
return description;
}
function normalizeHotelRequest (hotelData) {
if (hotelData && hotelData.legalEntity) {
hotelData.legalEntity = normalizeNestedContacts(hotelData.legalEntity);
}
if (hotelData && hotelData.hotel && hotelData.hotel.description) {
hotelData.hotel.description = normalizeNestedContacts(hotelData.hotel.description);
}
return hotelData;
}
module.exports = {
normalizeEmail,
normalizePhone,
normalizeNestedContacts,
normalizeHotelRequest,
};