forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request DefinitelyTyped#32698 from jeffreymeng/master
Add definition for list.js 1.5.0
- Loading branch information
Showing
4 changed files
with
140 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// Type definitions for list.js 1.5 | ||
// Project: http://listjs.com | ||
// Definitions by: Jeffrey Meng <https://github.com/jeffreymeng> | ||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped | ||
// TypeScript Version: 2.7 | ||
|
||
interface ListOptions { | ||
valueNames?: string[]; | ||
item?: string; | ||
listClass?: string; | ||
searchClass?: string; | ||
sortClass?: string; | ||
indexAsync?: boolean; | ||
page?: number; | ||
i?: number; | ||
pagination?: boolean; | ||
} | ||
|
||
interface SortOptions { | ||
order?: string; | ||
alphabet?: string; | ||
insensitive?: boolean; | ||
sortFunction?: ((a: object, b: object) => number|undefined); | ||
} | ||
|
||
declare class List { | ||
listContainer: HTMLElement; | ||
list: HTMLElement; | ||
items: object[]; | ||
visibleItems: object[]; | ||
matchingItems: object[]; | ||
searched: boolean; | ||
filtered: boolean; | ||
|
||
constructor(element: string|HTMLElement, options?: ListOptions, values?: object[]); | ||
|
||
add(values: object[], callback?: (item: ListItem) => void): void; | ||
remove(valueName: string, value: any): number; | ||
get(valueName: string, value: any): ListItem[]; | ||
sort(valueName: string, options: SortOptions): void; | ||
search(searchString: string, columns?: string[]): void; | ||
clear(): void; | ||
filter(filterFunction: (item: ListItem) => boolean): void; | ||
size(): number; | ||
show(i: number, page: number): void; | ||
update(): void; | ||
reIndex(): void; | ||
fuzzySearch(searchString: string, columns?: string[]): void; | ||
on(event: string, callback: () => void): void; | ||
} | ||
|
||
declare class ListItem { | ||
elm: HTMLElement; | ||
|
||
values(newValues: object): void; | ||
values(): object; | ||
show(): void; | ||
hide(): void; | ||
matching(): boolean; | ||
visible(): boolean; | ||
} | ||
|
||
export = List; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import List from "list.js"; | ||
|
||
const list = new List(new HTMLElement(), { | ||
page: 3, | ||
searchClass: "class" | ||
}); | ||
|
||
list.list; // $ExpectType HTMLElement | ||
list.listContainer; // $ExpectType HTMLElement | ||
list.items; // $ExpectType object[] | ||
list.visibleItems; // $ExpectType object[] | ||
list.matchingItems; // $ExpectType object[] | ||
list.searched; // $ExpectType boolean | ||
list.filtered; // $ExpectType boolean | ||
|
||
list.add([{ // $ExpectType void | ||
name: "value", | ||
value: true | ||
}], (item) => {}); // $ExpectType (item: ListItem) => void | ||
|
||
list.remove("name", "value"); // $ExpectType number | ||
list.get("name", "value"); // $ExpectType ListItem[] | ||
list.sort("name", { // $ExpectType void | ||
order: "asec", | ||
alphabet: "ABCD1234EFGH" | ||
}); | ||
list.search("name", ["col1", "col2"]); // $ExpectType void | ||
list.clear(); // $ExpectType void | ||
list.filter((item) => { | ||
return true; | ||
}); | ||
list.size(); // $ExpectType number | ||
list.show(0, 0); // $ExpectType void | ||
list.update(); // $ExpectType void | ||
list.reIndex(); // $ExpectType void | ||
list.fuzzySearch("search", ["col1", "col2"]); // $ExpectType void | ||
list.on("event", () => { // void | ||
// Do Something | ||
}); | ||
|
||
const item = list.get("name", "value")[0]; | ||
|
||
item.elm; // $ExpectType HTMLElement | ||
item.values(["new1", "new2"]); // $ExpectType void | ||
item.values(); // $ExpectType object | ||
item.show(); // $ExpectType void | ||
item.hide(); // $ExpectType void | ||
item.matching(); // $ExpectType boolean | ||
item.visible(); // $ExpectType boolean |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"compilerOptions": { | ||
"module": "commonjs", | ||
"lib": [ | ||
"es6", | ||
"dom" | ||
], | ||
"noImplicitAny": true, | ||
"noImplicitThis": true, | ||
"strictNullChecks": true, | ||
"strictFunctionTypes": true, | ||
"esModuleInterop": true, | ||
"baseUrl": "../", | ||
"typeRoots": [ | ||
"../" | ||
], | ||
"types": [], | ||
"noEmit": true, | ||
"forceConsistentCasingInFileNames": true | ||
}, | ||
"files": [ | ||
"index.d.ts", | ||
"list.js-tests.ts" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"extends": "dtslint/dt.json" | ||
} |