From 507a26a9ed6000d3cfed072332495895538229ed Mon Sep 17 00:00:00 2001 From: VILIC VANE Date: Sun, 15 Jun 2014 16:27:36 +0800 Subject: [PATCH] cheerio v0.17.0 definitions --- cheerio/cheerio-old.d.ts | 81 +++++++++++ cheerio/cheerio-tests.ts | 6 +- cheerio/cheerio-tests.ts.tscparams | 1 - cheerio/cheerio.d.ts | 207 +++++++++++++++++++++++------ cheerio/cheerio.d.ts.tscparams | 1 - 5 files changed, 252 insertions(+), 44 deletions(-) create mode 100644 cheerio/cheerio-old.d.ts delete mode 100644 cheerio/cheerio-tests.ts.tscparams delete mode 100644 cheerio/cheerio.d.ts.tscparams diff --git a/cheerio/cheerio-old.d.ts b/cheerio/cheerio-old.d.ts new file mode 100644 index 000000000..b0e09b778 --- /dev/null +++ b/cheerio/cheerio-old.d.ts @@ -0,0 +1,81 @@ +// Type definitions for Cheerio +// Project: https://github.com/MatthewMueller/cheerio +// Definitions by: Bret Little +// Definitions: https://github.com/borisyankov/DefinitelyTyped + + +interface Cheerio { + + addClass(classNames: string): Cheerio; + hasClass(className: string): boolean; + removeClass(className?: any): Cheerio; + + attr(attributeName: string, value: any): Cheerio; + attr(attributeName: string): string; + removeAttr(attributeName: any): Cheerio; + + find(selector: string): Cheerio; + + parent(): Cheerio; + + next(): Cheerio; + prev(): Cheerio; + + siblings(): Cheerio; + + children(selector?: any): Cheerio; + + each(func: (index: any, elem: any) => Cheerio); + + map(callback: (index: any, domElement: Element) =>any): Cheerio; + + filter(selector: string): Cheerio; + filter(func: (index: any) =>any): Cheerio; + + first(): Cheerio; + last(): Cheerio; + + eq(index: number): Cheerio; + + append(...content: any[]): Cheerio; + prepend(...content: any[]): Cheerio; + after(...content: any[]): Cheerio; + before(...content: any[]): Cheerio; + remove(selector: string): Cheerio; + replaceWith(content: string): Cheerio; + empty(): Cheerio; + + html(htmlString: string): Cheerio; + html(): string; + + text(textString: string): Cheerio; + text(): string; + + toArray(): any[]; + + clone() : Cheerio; + root() : Cheerio; + dom(): any; + + contains(container: Element, contained: Element): boolean; + isArray(obj: any): boolean; + inArray(value: any, array: any[], fromIndex?: number): number; + merge(first: any[], second: any[]): any[]; + + +} + +interface CheerioOptionsInterface { + ignoreWhitespace?: boolean; + xmlMode?: boolean; + lowerCaseTags?: boolean; +} + +interface CheerioStatic { + (...selectors: any[]): Cheerio; + (): Cheerio; +} + +declare module "cheerio" { + export function load (html : string, options?: CheerioOptionsInterface) : CheerioStatic; +} diff --git a/cheerio/cheerio-tests.ts b/cheerio/cheerio-tests.ts index 71d54c557..af671cd00 100644 --- a/cheerio/cheerio-tests.ts +++ b/cheerio/cheerio-tests.ts @@ -33,7 +33,7 @@ $el.children().map((index, element) => { }); $el.children().filter((index) => { - return $el.children().eq(index).find('t'); + return $el.children().eq(index).find('t').length >= 0; }); $el.filter('span').filter('li'); @@ -60,6 +60,6 @@ $el.text('some text'); $el.toArray(); $el.clone().find('a').parent(); -$el.root().find('a'); +$.root().find('a'); -$el.dom(); +$el.data(); diff --git a/cheerio/cheerio-tests.ts.tscparams b/cheerio/cheerio-tests.ts.tscparams deleted file mode 100644 index e16c76dff..000000000 --- a/cheerio/cheerio-tests.ts.tscparams +++ /dev/null @@ -1 +0,0 @@ -"" diff --git a/cheerio/cheerio.d.ts b/cheerio/cheerio.d.ts index b0e09b778..92334de45 100644 --- a/cheerio/cheerio.d.ts +++ b/cheerio/cheerio.d.ts @@ -1,81 +1,210 @@ -// Type definitions for Cheerio -// Project: https://github.com/MatthewMueller/cheerio -// Definitions by: Bret Little +// Type definitions for Cheerio v0.17.0 +// Project: https://github.com/cheeriojs/cheerio +// Definitions by: VILIC VANE // Definitions: https://github.com/borisyankov/DefinitelyTyped - interface Cheerio { - - addClass(classNames: string): Cheerio; - hasClass(className: string): boolean; - removeClass(className?: any): Cheerio; + // Document References + // Cheerio https://github.com/cheeriojs/cheerio + // JQuery http://api.jquery.com - attr(attributeName: string, value: any): Cheerio; - attr(attributeName: string): string; - removeAttr(attributeName: any): Cheerio; + [index: number]: CheerioElement; + length: number; + + // Attributes + + attr(name: string): string; + attr(name: string, value: any): Cheerio; + + data(): Object; + + val(): string; + val(value: string): Cheerio; + + removeAttr(name: string): Cheerio; + + hasClass(className: string): boolean; + addClass(classNames: string): Cheerio; + + removeClass(): Cheerio; + removeClass(className: string): Cheerio; + removeClass(func: (index: number, className: string) => string): Cheerio; + + toggleClass(className: string): Cheerio; + toggleClass(className: string, toggleSwitch: boolean): Cheerio; + toggleClass(toggleSwitch?: boolean): Cheerio; + toggleClass(func: (index: number, className: string, toggleSwitch: boolean) => string, toggleSwitch?: boolean): Cheerio; + + is(selector: string): boolean; + is(element: CheerioElement): boolean; + is(element: CheerioElement[]): boolean; + is(selection: Cheerio): boolean; + is(func: (index: number, element: CheerioElement) => boolean): boolean; + + // Traversing find(selector: string): Cheerio; - parent(): Cheerio; + parent(selector?: string): Cheerio; + parents(selector?: string): Cheerio; + parentsUntil(selector?: string, filter?: string): Cheerio; + parentsUntil(element: CheerioElement, filter?: string): Cheerio; + parentsUntil(element: Cheerio, filter?: string): Cheerio; - next(): Cheerio; - prev(): Cheerio; + closest(selector: string): Cheerio; - siblings(): Cheerio; + next(selector?: string): Cheerio; + nextAll(): Cheerio; - children(selector?: any): Cheerio; + nextUntil(selector?: string, filter?: string): Cheerio; + nextUntil(element: CheerioElement, filter?: string): Cheerio; + nextUntil(element: Cheerio, filter?: string): Cheerio; - each(func: (index: any, elem: any) => Cheerio); + prev(selector?: string): Cheerio; + prevAll(): Cheerio; - map(callback: (index: any, domElement: Element) =>any): Cheerio; + prevUntil(selector?: string, filter?: string): Cheerio; + prevUntil(element: CheerioElement, filter?: string): Cheerio; + prevUntil(element: Cheerio, filter?: string): Cheerio; + + slice(start: number, end?: number): Cheerio; + + siblings(selector?: string): Cheerio; + + children(selector?: string): Cheerio; + + each(func: (index: number, element: CheerioElement) => any): Cheerio; + map(func: (index: number, element: CheerioElement) => any): Cheerio; filter(selector: string): Cheerio; - filter(func: (index: any) =>any): Cheerio; + filter(selection: Cheerio): Cheerio; + filter(element: CheerioElement): Cheerio; + filter(elements: CheerioElement[]): Cheerio; + filter(func: (index: number) => boolean): Cheerio; first(): Cheerio; last(): Cheerio; eq(index: number): Cheerio; - append(...content: any[]): Cheerio; - prepend(...content: any[]): Cheerio; - after(...content: any[]): Cheerio; - before(...content: any[]): Cheerio; - remove(selector: string): Cheerio; + get(): Document[]; + get(index: number): Document; + + end(): Cheerio; + + add(selectorOrHtml: string): Cheerio; + add(selector: string, context: Document): Cheerio; + add(element: CheerioElement): Cheerio; + add(elements: CheerioElement[]): Cheerio; + add(selection: Cheerio): Cheerio; + + // Manipulation + + append(content: string, ...contents: any[]): Cheerio; + append(content: Document, ...contents: any[]): Cheerio; + append(content: Document[], ...contents: any[]): Cheerio; + append(content: Cheerio, ...contents: any[]): Cheerio; + + prepend(content: string, ...contents: any[]): Cheerio; + prepend(content: Document, ...contents: any[]): Cheerio; + prepend(content: Document[], ...contents: any[]): Cheerio; + prepend(content: Cheerio, ...contents: any[]): Cheerio; + + after(content: string, ...contents: any[]): Cheerio; + after(content: Document, ...contents: any[]): Cheerio; + after(content: Document[], ...contents: any[]): Cheerio; + after(content: Cheerio, ...contents: any[]): Cheerio; + + before(content: string, ...contents: any[]): Cheerio; + before(content: Document, ...contents: any[]): Cheerio; + before(content: Document[], ...contents: any[]): Cheerio; + before(content: Cheerio, ...contents: any[]): Cheerio; + + remove(selector?: string): Cheerio; + replaceWith(content: string): Cheerio; + replaceWith(content: CheerioElement): Cheerio; + replaceWith(content: CheerioElement[]): Cheerio; + replaceWith(content: Cheerio): Cheerio; + empty(): Cheerio; - html(htmlString: string): Cheerio; html(): string; + html(html: string): Cheerio; - text(textString: string): Cheerio; text(): string; + text(text: string): Cheerio; - toArray(): any[]; + css(propertyName: string): string; + css(propertyNames: string[]): string[]; + css(propertyName: string, value: string): Cheerio; + css(propertyName: string, value: number): Cheerio; + css(propertyName: string, func: (index: number, value: string) => string): Cheerio; + css(propertyName: string, func: (index: number, value: string) => number): Cheerio; + css(properties: Object): Cheerio; - clone() : Cheerio; - root() : Cheerio; - dom(): any; + // Rendering - contains(container: Element, contained: Element): boolean; - isArray(obj: any): boolean; - inArray(value: any, array: any[], fromIndex?: number): number; - merge(first: any[], second: any[]): any[]; + // Miscellaneous + clone(): Cheerio; + // Not Documented + + toArray(): CheerioElement[]; } interface CheerioOptionsInterface { - ignoreWhitespace?: boolean; + // Document References + // Cheerio https://github.com/cheeriojs/cheerio + // HTMLParser2 https://github.com/fb55/htmlparser2/wiki/Parser-options + // DomHandler https://github.com/fb55/DomHandler + xmlMode?: boolean; + decodeEntities?: boolean; lowerCaseTags?: boolean; + lowerCaseAttributeNames?: boolean; + recognizeCDATA?: boolean; + recognizeSelfClosing?: boolean; + normalizeWhitespace?: boolean; } interface CheerioStatic { - (...selectors: any[]): Cheerio; - (): Cheerio; + // Document References + // Cheerio https://github.com/cheeriojs/cheerio + // JQuery http://api.jquery.com + + (selector: string): Cheerio; + (selector: string, context: string): Cheerio; + (selector: string, context: CheerioElement): Cheerio; + (selector: string, context: CheerioElement[]): Cheerio; + (selector: string, context: Cheerio): Cheerio; + (selector: string, context: string, root: string): Cheerio; + (selector: string, context: CheerioElement, root: string): Cheerio; + (selector: string, context: CheerioElement[], root: string): Cheerio; + (selector: string, context: Cheerio, root: string): Cheerio; + (selector: any): Cheerio; + + xml(): string; + root(): Cheerio; + contains(container: CheerioElement, contained: CheerioElement): boolean; + parseHTML(data: string, context?: Document, keepScripts?: boolean): Document[]; +} + +interface CheerioElement { + // Document References + // Node Console + + type: string; + name: string; + attribs: Object; + children: CheerioElement[]; + next: CheerioElement; + prev: CheerioElement; + parent: CheerioElement; + root: CheerioElement; } declare module "cheerio" { - export function load (html : string, options?: CheerioOptionsInterface) : CheerioStatic; -} + export function load(html: string, options?: CheerioOptionsInterface): CheerioStatic; +} \ No newline at end of file diff --git a/cheerio/cheerio.d.ts.tscparams b/cheerio/cheerio.d.ts.tscparams deleted file mode 100644 index e16c76dff..000000000 --- a/cheerio/cheerio.d.ts.tscparams +++ /dev/null @@ -1 +0,0 @@ -""