IonicaBizau / scrape-it

🔮 A Node.js scraper for humans.

Home Page:http://ionicabizau.net/blog/30-how-to-write-a-web-scraper-in-node-js

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Missing the types of Cheerio, CheerioSelector and CheerioStatic

saltyshiomix opened this issue · comments

I found no declarations in the index.d.ts (v5.1.4):

(Cheerio, CheerioSelector and CheerioStatic)

declare namespace scrapeIt {
    export interface ScrapeOptions {
        [key: string]: string | ScrapeOptionList | ScrapeOptionElement;
    }

    export interface ScrapeOptionElement {
        selector?: string;
        convert?: (value: any) => any;
        how?: string | ((element: CheerioSelector) => any);
        attr?: string;
        trim?: boolean;
        closest?: string;
        eq?: number;
        texteq?: number;
    }

    export interface ScrapeOptionList {
        listItem: string;
        data?: ScrapeOptions;
        convert?: (value: any) => any;
    }

    export interface ScrapeResult<T> {
        data: T,
        $: Cheerio,
        response: any,
        body: string
    }

    export function scrapeHTML<T>(body: CheerioStatic | string, options: ScrapeOptions): T;
}

declare function scrapeIt<T>(url: string | object, opts: scrapeIt.ScrapeOptions): Promise<scrapeIt.ScrapeResult<T>>;

declare function scrapeIt<T>(url: string | object, opts: scrapeIt.ScrapeOptions, cb: (err: any, res: scrapeIt.ScrapeResult<T>) => void): void;
export = scrapeIt;

I think we should import types from cheerio.
Any other ideas?

In advance, this awesome tool I'm so glad to use :)
Thank you for your great works.

Currently I'm avoiding this issue by adding @types/cheerio in my projects' devDependencies.

I think we should add @types/cheerio in the dependencies instead of devDependencies :)

I tested both yarn install and npm install, but both of them have same errors.

Probably fixed via #137