JSFiddle - React, Tailwind, and code Playground
by Steven Senkus
JavaScript
function removeBusinessDesignatorFromBusinessName(businessName) {
if (!businessName) {
return null;
}
// Prepare business name by removing all leading/trailing spaces
businessName = businessName.trim();
const businessDesignators = [
'LLC',
'LLC.',
'LL.C.',
'LL.C.',
'L.LC',
'L.LC.',
'L.L.C',
'L.L.C.',
'Limited Liability Company'
]
for (let businessDesignator of businessDesignators) {
const lowerCaseBusinessDesignator = businessDesignator.toLowerCase();
const caseInsensitiveBusinessDesignator = new RegExp(`${businessDesignator}$`, 'i');
if (caseInsensitiveBusinessDesignator.test(businessName)) {
businessName = businessName.replace(caseInsensitiveBusinessDesignator, '');
break;
}
}
return businessName.trim();
}
[
'Test Company LlC.',
'test company limited Liability CompanY'
].forEach((name) => {
console.log(name.toString(), removeBusinessDesignatorFromBusinessName(name));
})