JSFiddle - React, Tailwind, and code Playground

by Barry Peterson

HTML

<p class="super-short-title">This is the worlds most longest title in the world that should really be shorter.</p>

Babel + JSX

function truncator (string, length, delimeter = '...') {
	const strLength = length - delimeter.length;
	const beginningString = string.substr(0, strLength);
  const endString = string.substr(string.length - strLength);
	return `${beginningString}${delimeter}${endString}`
}

$('.super-short-title').each((indx, elem) {
	$(elem).text(truncator($(elem).text(), 8));
})