Skip to content
This repository has been archived by the owner on Sep 6, 2021. It is now read-only.

Fix outdated comments in StringUtils truncate() #8707

Merged
merged 2 commits into from
Aug 11, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/utils/StringUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,18 +199,18 @@ define(function (require, exports, module) {
}

/**
* Truncate strings to specified length.
* Truncate text to specified length.
* @param {string} str Text to be truncated.
* @param {number} len Length to which text should be limited.
* @return {string} Returns truncated text only if it was changed.
* @param {number} len Length to which text should be truncated
* @return {?string} Returns truncated text only if it was changed
*/
function truncate(str, len) {
// Truncate the description if it is too long
// Truncate text to specified length
if (str.length > len) {
str = str.substr(0, len);

// To prevent awkward addition of ellipsis, try to truncate
// at the end of the last whole word
// To prevent awkwardly truncating in the middle of a word,
// attempt to truncate at the end of the last whole word
var lastSpaceChar = str.lastIndexOf(" ");
if (lastSpaceChar < len && lastSpaceChar > -1) {
str = str.substr(0, lastSpaceChar);
Expand Down