Skip to content

Instantly share code, notes, and snippets.

@semperos
Created December 28, 2012 14:21
Show Gist options
  • Select an option

  • Save semperos/4398258 to your computer and use it in GitHub Desktop.

Select an option

Save semperos/4398258 to your computer and use it in GitHub Desktop.
TypeScript with "--module amd"
define(["require", "exports"], function(require, exports) {
var StringUtil = (function () {
function StringUtil() { }
StringUtil.truncate = function truncate(str, limit) {
if(str.length > limit) {
var r;
var ret;
r = new RegExp("^.{0," + limit + "}\\b");
ret = r.exec(str)[0];
if(ret.charAt(ret.length - 1) === " ") {
ret = ret.slice(0, -1);
}
ret += '...';
return ret;
} else {
return str;
}
}
return StringUtil;
})();
exports.StringUtil = StringUtil;
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment