forked from shmuelie/Humanizer.Js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
truncateExtensions.js
43 lines (43 loc) · 1.42 KB
/
truncateExtensions.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
var Humanizer;
(function (Humanizer) {
"use strict";
/**
* Truncation location for humanizer
* @enum
* @readonly
*/
(function (TruncateFrom) {
/** Truncate letters from the left (start) of the string */
TruncateFrom[TruncateFrom["Left"] = 0] = "Left";
/** Truncate letters from the right (end) of the string */
TruncateFrom[TruncateFrom["Right"] = 1] = "Right";
})(Humanizer.TruncateFrom || (Humanizer.TruncateFrom = {}));
var TruncateFrom = Humanizer.TruncateFrom;
String.prototype.truncate = function () {
var length = arguments[0];
var truncationString = "…";
var from = TruncateFrom.Right;
var truncator = Humanizer.Truncator.FixedLength;
if (arguments.length > 1) {
if (typeof arguments[1] === "string") {
truncationString = arguments[1];
}
else {
truncator = arguments[1];
}
}
if (arguments.length > 2) {
if (typeof arguments[2] === "number") {
from = arguments[2];
}
else {
truncator = arguments[2];
}
}
if (arguments.length > 3) {
from = arguments[3];
}
return truncator.truncate(this, length, truncationString, from);
};
})(Humanizer || (Humanizer = {}));
//# sourceMappingURL=truncateExtensions.js.map