forked from shmuelie/Humanizer.Js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
toQuantityExtensions.ts
36 lines (31 loc) · 928 Bytes
/
toQuantityExtensions.ts
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
interface String
{
toQuantity(quantity: number, showQuantityAs?: Humanizer.ShowQuantityAs): string;
}
module Humanizer
{
"use strict";
export enum ShowQuantityAs
{
None,
Numeric,
Words
}
String.prototype.toQuantity = function (quantity: number, showQuantityAs: ShowQuantityAs = ShowQuantityAs.None): string
{
var transformedInput: string = 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;
}
};
}