From e8197e3172c46fb299f178cd4b5b9d050b732a06 Mon Sep 17 00:00:00 2001 From: Bret Little Date: Thu, 24 Jan 2013 15:48:28 -0700 Subject: [PATCH] Add cheerio typescript definition --- cheerio/cheerio-test.ts | 65 +++++++++++++++++++++++++++++++++++ cheerio/cheerio.d.ts | 75 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 140 insertions(+) create mode 100644 cheerio/cheerio-test.ts create mode 100644 cheerio/cheerio.d.ts diff --git a/cheerio/cheerio-test.ts b/cheerio/cheerio-test.ts new file mode 100644 index 0000000000..b2a5d84f3b --- /dev/null +++ b/cheerio/cheerio-test.ts @@ -0,0 +1,65 @@ +/// + +import cheerio = module("cheerio"); + +var $ = cheerio.load(""); +var $el = $('selector'); +var $multiEl = $('seletor', 'selector', 'selector'); + +$el.addClass("class").addClass("test"); +$el.hasClass("test"); +$el.removeClass("class").removeClass("test"); + +$el.attr('class'); +$el.attr('class', 'test'); +$el.removeAttr("class").removeAttr("test"); + +$el.find("ul").find("> li"); + +$el.parent().parent(); +$el.next().next(); +$el.prev().prev(); +$el.siblings().siblings(); + +$el.children().children(); +$el.children("li").children("a"); + +$el.children().each((index, element) => { + $(element).find('t'); +}); + +$el.children().map((index, element) => { + return $(element).find('t'); +}); + +$el.children().filter((index) => { + return $el.children().eq(index).find('t'); +}); + +$el.filter('span').filter('li'); + +$el.first().last().find('t'); + +$('div').eq(0).find('b'); + +$('#id').append("test html", "other html").find('a'); +$('#id').prepend("test html", "other html").find('a'); +$('#id').after("test html", "other html").find('a'); +$('#id').before("test html", "other html").find('a'); + +$el.remove('div').remove('a'); + +$('#id').replaceWith('some html').parent(); +$('#id').empty().parent(); + +$el.html(); +$el.html("").find('div'); + +$el.text(); +$el.text('some text'); + +$el.toArray(); +$el.clone().find('a').parent(); +$el.root().find('a'); + +$el.dom(); diff --git a/cheerio/cheerio.d.ts b/cheerio/cheerio.d.ts new file mode 100644 index 0000000000..d3416a74f8 --- /dev/null +++ b/cheerio/cheerio.d.ts @@ -0,0 +1,75 @@ +declare interface Cheerio { + + addClass(classNames: string): Cheerio; + hasClass(className: string): bool; + 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): bool; + isArray(obj: any): bool; + inArray(value: any, array: any[], fromIndex?: number): number; + merge(first: any[], second: any[]): any[]; + + +} + +declare interface CheerioOptionsInterface { + ignoreWhitespace?: bool; + xmlMode?: bool; + lowerCaseTags?: bool; +} + +declare interface CheerioStatic { + (...selectors: any[]): Cheerio; + (): Cheerio; +} + +declare module "cheerio" { + export function load (html : string, options?: CheerioOptionsInterface) : CheerioStatic; +}