department-of-veterans-affairs/vets-website

View on GitHub
src/applications/appeals/testing/nod-new/utils/contactInfo.js

Summary

Maintainability
A
2 hrs
Test Coverage
export const getPhoneString = (phone = {}) =>
  `${phone?.areaCode || ''}${phone?.phoneNumber || ''}`;

const hashRegex = /#/g;
const phonePattern = '(###) ###-####';
export const getFormattedPhone = phone => {
  const fullString = getPhoneString(phone);
  if (fullString.length === 10) {
    let i = 0;
    // eslint-disable-next-line no-plusplus
    return phonePattern.replace(hashRegex, () => fullString[i++] || '');
  }
  return fullString;
};