14 lines
382 B
JavaScript
14 lines
382 B
JavaScript
export function trimIfMoreThan(maybeString, maxLength = 20, sfx = "") {
|
|
if (typeof maybeString == "string" && maybeString !== "") {
|
|
let toAppSfx = sfx
|
|
let toTrimLnth = maxLength - toAppSfx.length
|
|
if (maybeString.length <= maxLength) {
|
|
toAppSfx = ""
|
|
toTrimLnth = maxLength
|
|
}
|
|
return maybeString.substring(0, toTrimLnth) + toAppSfx
|
|
}
|
|
|
|
return ""
|
|
}
|