forked from shmuelie/Humanizer.Js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
collectionHumanizeExtensions.ts
47 lines (45 loc) · 1.69 KB
/
collectionHumanizeExtensions.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
37
38
39
40
41
42
43
44
45
46
47
interface Array<T>
{
/**
* Formats the collection for display, calling ToString() on each object and using the default separator for the current culture.
*/
humanize(): string;
/**
* Formats the collection for display, calling `objectFormatter` on each object and using the default separator for the current culture.
*/
humanize(displayFormatter: (item: T) => string): string;
/**
* Formats the collection for display, calling ToString() on each object and using the provided separator.
*/
humanize(separator: string): string;
/**
* Formats the collection for display, calling `objectFormatter` on each object and using the provided separator.
*/
humanize(displayFormatter: (item: T) => string, separator: string): string;
}
module Humanizer
{
"use strict";
Array.prototype.humanize = function (): string
{
switch (arguments.length)
{
case 0:
return Configuration.Configurator.getCollectionFormatters().humanize(this);
case 1:
if (typeof arguments[0] === "string")
{
return Configuration.Configurator.getCollectionFormatters().humanize(this, <string>arguments[0]);
}
else
{
var df: (item: any) => string = arguments[0];
return Configuration.Configurator.getCollectionFormatters().humanize(this, df);
}
case 2:
return Configuration.Configurator.getCollectionFormatters().humanize(this, arguments[0], arguments[1]);
default:
throw new Error("Unknown call");
}
};
}