Created
July 22, 2015 18:20
-
-
Save ihorkatkov/bed0356af4c697eeb3eb to your computer and use it in GitHub Desktop.
[JS] Функция усечения строки. Проверяет длину строки str, и если она превосходит maxlength — заменяет конец str на "...", так что ее длина становится равна maxlength. Результатом функции будет усечённая строка.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function truncate(str, maxlength) { | |
if (str.length > maxlength) { | |
return str.slice(0, maxlength - 3) + '...'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment