Skip to content

Commit a9ce9c1

Browse files
committed
changed naming, added description to declaration file, added test
1 parent 9599872 commit a9ce9c1

File tree

10 files changed

+251
-170
lines changed

10 files changed

+251
-170
lines changed

Diff for: .npmignore

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
tests\*
2-
dist\index.ts
2+
dist\list.ts
33
README-Developers.md
44
gulpfile.js
5-
dist\index.js
5+
dist\list.js
66
tsconfig.json
77
tslint.json

Diff for: dist/index.d.ts

-21
This file was deleted.

Diff for: dist/list.d.ts

+140
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
export declare class List<T> extends Array<T> {
2+
/**
3+
* instantiates a list either with, or with out Array or List
4+
* var fruits = new List<Fruit>(favoriteFruits);
5+
* var fruits = new List<Fruit>();
6+
* @param array can be a list, an array, or null.
7+
*/
8+
constructor(array?: List<T> | Array<T>);
9+
/**
10+
* Adds item with typeof T to current List.
11+
* @param item element to add
12+
*/
13+
Add(item: T): boolean;
14+
/**
15+
* Adds all passed elements to list, elements can be either an Array<T>, a List<T> or even multiple elements e.g.
16+
* fruits.AddRange(["apple", "banana", "lemon"]); fruits.AddRange(fruits2); fruits.AddRange("apple", "banana", "lemon");
17+
* @param args either Array<T>, List<T> or multiple elements,
18+
*/
19+
AddRange(...args: any[]): boolean;
20+
/**
21+
* Checks if list contains any elements with delegate fruits.Any(x => x.Color === Color.Yellow) // e.g. 2
22+
* @param delegate
23+
* @param args
24+
*/
25+
Any(delegate: (value: T) => boolean): boolean;
26+
/**
27+
* Checks if list contains any elements
28+
*/
29+
Any(): boolean;
30+
/**
31+
* Removes all elements from list.
32+
*/
33+
Clear(): boolean;
34+
/**
35+
* Returns true if list contains passed element.
36+
* @param item
37+
*/
38+
Contains(item: T): boolean;
39+
/**
40+
* Returns listcount by delegate. fruits.Where(x => x.Color === Color.Yellow) // e.g. 2
41+
* @param delegate boolean to compare by delegate
42+
* @param args
43+
*/
44+
Count(delegate: (value: T) => boolean): number;
45+
/**
46+
* Returns count of the List.
47+
*/
48+
Count(): number;
49+
/**
50+
* Summarizes numbers within a list by delegate, ignoring invalid values, and converts strings if possible
51+
* @param delegate must be a number
52+
* @param args
53+
*/
54+
Sum(delegate: (value: number) => number): number;
55+
/**
56+
* Summarizes numbers within a list, ignoring invalid values, and converts strings if possible
57+
*/
58+
Sum(): number;
59+
/**
60+
* Returns new list with removed duplicates and select items from delegate if set.
61+
* Works on complex objects only, if elements inside are equal.
62+
* @param delegate distinct values to return.
63+
* @param args
64+
*/
65+
Distinct(delegate: (value: T) => any): List<T>;
66+
/**
67+
* Returns new list with removed duplicates.
68+
* Works on complex objects only, if elements inside are equal.
69+
*/
70+
Distinct(): List<T>;
71+
/**
72+
* Compares two lists.
73+
*
74+
* @param list List to compare with
75+
* @param deepCompare default true. If false, equality will be checked by items, not by position ->
76+
* [ "Apple", "Banana" ].Equals([ "Banana", "Apple" ]) will then return true.
77+
*/
78+
Equals(list: List<T>, deepCompare: boolean): boolean;
79+
/**
80+
* Compares two lists
81+
* @param list List to compare with
82+
*/
83+
Equals(list: List<T>): boolean;
84+
/**
85+
* Returns first element of list.
86+
*/
87+
First(): T;
88+
/**
89+
* Returns element at index
90+
* @param index
91+
*/
92+
Get(index: number): T;
93+
/**
94+
* Returns index of passed element in list.
95+
* @param item
96+
*/
97+
IndexOf(item: T): number;
98+
/**
99+
* Returns last element of list.
100+
*/
101+
Last(): T;
102+
/**
103+
* Removes passed item from list
104+
* @param item Item to remove
105+
*/
106+
Remove(item: T): boolean;
107+
/**
108+
* Removes item at passed index.
109+
* @param index
110+
*/
111+
RemoveAt(index: number): boolean;
112+
/**
113+
* Returns new list with by delegate selected value.
114+
* @param delegate
115+
* @param args
116+
*/
117+
Select(delegate: (value: T) => any): List<T>;
118+
/**
119+
* Converts List<T> to Array. Needed for serialization e.g. with ajax calls.
120+
*/
121+
ToArray(): Array<T>;
122+
/**
123+
* Returns list by delegate fruits.Where(x => x.Color === Color.Red);
124+
* @param delegate
125+
* @param args
126+
*/
127+
Where(delegate: (value: T) => boolean): List<T>;
128+
/**
129+
* Creates list of numbers, within a specified range.
130+
* @param start where to start
131+
* @param count count of numbers to create
132+
*/
133+
static Range(start: number, count: number): List<number>;
134+
}
135+
136+
declare global {
137+
interface Array<T> extends ArrayConstructor {
138+
ToList(): List<T>;
139+
}
140+
}

Diff for: dist/index.js renamed to dist/list.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,10 @@ var List = (function (_super) {
149149
return new List();
150150
}
151151
};
152-
List.prototype.Equals = function (list, comparePosition) {
153-
if (comparePosition === void 0) { comparePosition = true; }
152+
List.prototype.Equals = function (list, deepCompare) {
153+
if (deepCompare === void 0) { deepCompare = true; }
154154
try {
155-
return this.equals(list, this._array, comparePosition);
155+
return this.equals(list, this._array, deepCompare);
156156
}
157157
catch (ex) {
158158
return false;

0 commit comments

Comments
 (0)