Skip to content

Instantly share code, notes, and snippets.

@mariano-aguero
Created January 10, 2019 17:39
Show Gist options
  • Save mariano-aguero/d32f74c7b99ce74810afb243bfe0c3e5 to your computer and use it in GitHub Desktop.
Save mariano-aguero/d32f74c7b99ce74810afb243bfe0c3e5 to your computer and use it in GitHub Desktop.
Truncate address in the middle, 3 dots
const truncateStringInTheMiddle = (
str,
strLength = 50,
strPositionStart = 24,
strPositionEnd = 25
) => {
if (typeof str === 'string' && str.length > strLength) {
return `${str.substr(0, strPositionStart)}...${str.substr(
str.length - strPositionEnd,
str.length
)}`
}
return str
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment