Skip to content

Instantly share code, notes, and snippets.

View JefCurtis's full-sized avatar
🎄
I may be slow to respond.

Jef Curtis JefCurtis

🎄
I may be slow to respond.
View GitHub Profile
@pbojinov
pbojinov / trim.string.js
Last active December 5, 2018 16:09
Shorten string to specified max length and and append ... at the end. It will not cut in the middle of a word but at the minimum amount of words under the limit.
function trim(message, maxLength) {
var m = message;
var maxLen = maxLength;
//string is too long, lets trim it and append ...
if (m.length > maxLen) {
var lastSpace = m.lastIndexOf(' ');
//there is no space in the word
if (lastSpace === -1) {
m = m.slice(0, maxLen-3);