Skip to content

Instantly share code, notes, and snippets.

@gabrielsaints
Last active December 9, 2019 17:10
Show Gist options
  • Save gabrielsaints/5bcb0899b59e40299f3079d9810f4236 to your computer and use it in GitHub Desktop.
Save gabrielsaints/5bcb0899b59e40299f3079d9810f4236 to your computer and use it in GitHub Desktop.
const truncate = (label, divisor, precision = 1) => {
if(!label){
return label
}
const labelSplited = label.split(divisor);
const hiddenNames = ['DOS', 'DAS', 'DE', 'DO'];
const divisors = labelSplited.map((element, index) => {
if (!index || index + 1 === labelSplited.length) {
return element;
}
if (hiddenNames.includes(element)) {
return false;
}
return `${element.substr(0, precision)}`;
}).filter(element => element);
return divisors.join(' ');
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment