Truncate: To reduce length of text

PHOTO EMBED

Fri Feb 05 2021 14:38:15 GMT+0000 (UTC)

Saved by @Dante Frank #javascript

truncate: (str, len) => {
        if (str.length > len && str.length>0) {
            let new_str = str + ' '
            new_str = str.substr(0, len)
            new_str = str.substr(0, new_str.lastIndexOf(' '))
            new_str = new_str.length > 0 ? new_str : str.substr(0, len)
            return new_str + '...'
        }
        return str
    }
content_copyCOPY