10 lines
251 B
TypeScript
10 lines
251 B
TypeScript
|
export const shorten = (str: string, offset = 9) => {
|
||
|
// return original string if it is not long enough
|
||
|
if (str.length < offset * 2 + 4) return str
|
||
|
|
||
|
return `${str.slice(0, offset)}...${str.slice(
|
||
|
str.length - offset,
|
||
|
str.length
|
||
|
)}`
|
||
|
}
|