1-liners
Version:
Useful oneliners and shorthand functions
24 lines (21 loc) • 551 B
JavaScript
/**
* @module 1-liners/truncate
*
* @description
*
* Truncate string when longer than maxLength and add the Unicode Character horizontal ellipsis keeping the total within maxLength.
*
* @example
*
* const truncate = require('1-liners/truncate');
*
* truncate('super', 5) // => super
* truncate('super', 4) // => sup…
*
*/
;
exports.__esModule = true;
exports["default"] = function (str, maxLength) {
return str.length > maxLength ? str.substr(0, maxLength - 1) + "…" : str;
};
module.exports = exports["default"];