forked from shmuelie/Humanizer.Js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
toQuantityExtensions.js
26 lines (26 loc) · 1.14 KB
/
toQuantityExtensions.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
var Humanizer;
(function (Humanizer) {
"use strict";
(function (ShowQuantityAs) {
ShowQuantityAs[ShowQuantityAs["None"] = 0] = "None";
ShowQuantityAs[ShowQuantityAs["Numeric"] = 1] = "Numeric";
ShowQuantityAs[ShowQuantityAs["Words"] = 2] = "Words";
})(Humanizer.ShowQuantityAs || (Humanizer.ShowQuantityAs = {}));
var ShowQuantityAs = Humanizer.ShowQuantityAs;
String.prototype.toQuantity = function (quantity, showQuantityAs) {
if (showQuantityAs === void 0) { showQuantityAs = ShowQuantityAs.None; }
var transformedInput = quantity === 1 ? this.singularize(false) : this.pluralize(false);
if (showQuantityAs === ShowQuantityAs.None) {
return transformedInput;
}
switch (showQuantityAs) {
case ShowQuantityAs.None:
return transformedInput;
case ShowQuantityAs.Numeric:
return quantity.toString() + transformedInput;
case ShowQuantityAs.Words:
return quantity.toWords() + transformedInput;
}
};
})(Humanizer || (Humanizer = {}));
//# sourceMappingURL=toQuantityExtensions.js.map