The removeHierarchyFromName function effectively simplifies strings by eliminating hierarchical prefixes. It takes a string input, splits it at the colon, and returns the last segment, making it ideal for cleaning up names or titles. The function is wrapped in a try-catch block to handle potential errors gracefully, logging any issues for debugging.
This is particularly useful for formatting names or titles that include unnecessary hierarchy.
/**
* @description Remove hierarchy from the given string
* @param {string} parameter string from where change hierarchy
* @returns {string} formatted string
*/
function removeHierarchyFromName(parameter) {
try {
return parameter.toString().split(": ")[parameter.toString().split(": ").length - 1];
} catch (er) {
log.debug("er", er.message);
}
}