46 lines
1.4 KiB
JavaScript
46 lines
1.4 KiB
JavaScript
/**
|
|
* @function stripRteStyle
|
|
* @summary
|
|
* Returns string with inline style tag stripped out
|
|
* @param {string} stringWithStyleTag
|
|
* @returns {string}
|
|
*/
|
|
export function stripRteStyle(stringWithStyleTag) {
|
|
const regexExp = /[\s*]style="(.*?)"/g;
|
|
return stringWithStyleTag.replace(regexExp, '');
|
|
}
|
|
|
|
/**
|
|
* @function toTitleCase
|
|
* @summary Returns title cased string version of 'text'
|
|
* @param {string} text
|
|
* @returns {string}
|
|
*/
|
|
export function toTitleCase(text) {
|
|
const temp = text?.toLowerCase()?.split(' ') ?? [];
|
|
for (let i = 0; i < temp.length; i++) {
|
|
temp[i] = temp[i].charAt(0).toUpperCase() + temp[i].slice(1);
|
|
}
|
|
return temp.join(' ');
|
|
}
|
|
|
|
/**
|
|
* @function toDisplayPhoneNumber
|
|
* @summary If 10 or 11 digits are in phoneNumber, then the expected number including dashes will be returned
|
|
* in either d-ddd-ddd-dddd or ddd-ddd-dddd format. Otherwise, an empty string will be returned.
|
|
* @param {string} phoneNumber
|
|
* @returns {string}
|
|
*/
|
|
export function toDisplayPhoneNumber(phoneNumber) {
|
|
let result = '';
|
|
if (!phoneNumber) { return result; }
|
|
let remainingDigits = phoneNumber.match(/\d+/g).join('');
|
|
if (remainingDigits.length === 11) {
|
|
result += `${remainingDigits[0]}-`;
|
|
remainingDigits = remainingDigits.substring(1);
|
|
}
|
|
if (remainingDigits.length === 10) {
|
|
result += remainingDigits.replace(/^(\d{3})(\d{3})(\d{4})/, '$1-$2-$3');
|
|
}
|
|
return result;
|
|
}
|