source: node_modules/autolinker/dist/commonjs/truncate/truncate-middle.js

main
Last change on this file was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago

Initial commit

  • Property mode set to 100644
File size: 1.4 KB
RevLine 
[d24f17c]1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.truncateMiddle = void 0;
4/**
5 * Date: 2015-10-05
6 * Author: Kasper Søfren <soefritz@gmail.com> (https://github.com/kafoso)
7 *
8 * A truncation feature, where the ellipsis will be placed in the dead-center of the URL.
9 *
10 * @param {String} url A URL.
11 * @param {Number} truncateLen The maximum length of the truncated output URL string.
12 * @param {String} ellipsisChars The characters to place within the url, e.g. "..".
13 * @return {String} The truncated URL.
14 */
15function truncateMiddle(url, truncateLen, ellipsisChars) {
16 if (url.length <= truncateLen) {
17 return url;
18 }
19 var ellipsisLengthBeforeParsing;
20 var ellipsisLength;
21 if (ellipsisChars == null) {
22 ellipsisChars = '&hellip;';
23 ellipsisLengthBeforeParsing = 8;
24 ellipsisLength = 3;
25 }
26 else {
27 ellipsisLengthBeforeParsing = ellipsisChars.length;
28 ellipsisLength = ellipsisChars.length;
29 }
30 var availableLength = truncateLen - ellipsisLength;
31 var end = '';
32 if (availableLength > 0) {
33 end = url.substr(-1 * Math.floor(availableLength / 2));
34 }
35 return (url.substr(0, Math.ceil(availableLength / 2)) + ellipsisChars + end).substr(0, availableLength + ellipsisLengthBeforeParsing);
36}
37exports.truncateMiddle = truncateMiddle;
38//# sourceMappingURL=truncate-middle.js.map
Note: See TracBrowser for help on using the repository browser.