Skip to content

Commit

Permalink
Merge pull request DefinitelyTyped#32698 from jeffreymeng/master
Browse files Browse the repository at this point in the history
Add definition for list.js 1.5.0
  • Loading branch information
PranavSenthilnathan authored Feb 1, 2019
2 parents d673356 + 11f4d94 commit a834ed5
Show file tree
Hide file tree
Showing 4 changed files with 140 additions and 0 deletions.
63 changes: 63 additions & 0 deletions types/list.js/index.d.ts
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;
49 changes: 49 additions & 0 deletions types/list.js/list.js-tests.ts
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
25 changes: 25 additions & 0 deletions types/list.js/tsconfig.json
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"
]
}
3 changes: 3 additions & 0 deletions types/list.js/tslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "dtslint/dt.json"
}

0 comments on commit a834ed5

Please sign in to comment.