mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-03-29 00:18:20 +08:00
Added type definitions for website-scraper v1.2.x (#12125)
* Added type definitions for website-scraper v1.2.x * Renamed test file * Fixed "files" in tsconfig.json * Renamed test file * Replaced module with namespace
This commit is contained in:
committed by
Masahiro Wakame
parent
830b43f05e
commit
b398805089
50
website-scraper/index.d.ts
vendored
Normal file
50
website-scraper/index.d.ts
vendored
Normal file
@@ -0,0 +1,50 @@
|
||||
// Type definitions for website-scraper v1.2.x
|
||||
// Project: https://github.com/s0ph1e/node-website-scraper
|
||||
// Definitions by: Christian Rackerseder <https://www.echooff.de>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
import * as request from 'request';
|
||||
|
||||
declare namespace websiteScraper {
|
||||
interface Url {
|
||||
url: string;
|
||||
filename: string;
|
||||
}
|
||||
interface SubDirectory {
|
||||
directory: string;
|
||||
extensions: string[];
|
||||
}
|
||||
interface Source {
|
||||
selector: string;
|
||||
attr: string;
|
||||
}
|
||||
interface RequestOptions {
|
||||
headers: request.Headers
|
||||
}
|
||||
interface Options {
|
||||
urls: Array<string | Url>;
|
||||
directory: string;
|
||||
urlFilter?: (url: string) => boolean;
|
||||
filenameGenerator?: string;
|
||||
defaultFilename?: string;
|
||||
prettifyUrls?: boolean;
|
||||
sources?: Source[];
|
||||
subdirectories?: SubDirectory[] | null;
|
||||
request?: RequestOptions;
|
||||
recursive?: boolean;
|
||||
maxDepth?: number;
|
||||
ignoreErrors?: boolean;
|
||||
}
|
||||
interface Resource {
|
||||
url: string;
|
||||
filename: string;
|
||||
assets: Resource[];
|
||||
}
|
||||
interface Callback {
|
||||
(error: any | null, result: Resource[] | null): void;
|
||||
}
|
||||
function scrape(options: Options, callback: Callback): void;
|
||||
function scrape(options: Options): Promise<Resource[]>;
|
||||
}
|
||||
|
||||
export = websiteScraper;
|
||||
19
website-scraper/tsconfig.json
Normal file
19
website-scraper/tsconfig.json
Normal file
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"target": "es6",
|
||||
"noImplicitAny": true,
|
||||
"strictNullChecks": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"website-scraper-tests.ts"
|
||||
]
|
||||
}
|
||||
29
website-scraper/website-scraper-tests.ts
Normal file
29
website-scraper/website-scraper-tests.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import * as scraper from 'website-scraper';
|
||||
|
||||
scraper.scrape({
|
||||
urls: [
|
||||
'http://nodejs.org/',
|
||||
{url: 'http://nodejs.org/about', filename: 'about.html'},
|
||||
{url: 'http://blog.nodejs.org/', filename: 'blog.html'}
|
||||
],
|
||||
directory: '/path/to/save',
|
||||
subdirectories: [
|
||||
{directory: 'img', extensions: ['.jpg', '.png', '.svg']},
|
||||
{directory: 'js', extensions: ['.js']},
|
||||
{directory: 'css', extensions: ['.css']}
|
||||
],
|
||||
sources: [
|
||||
{selector: 'img', attr: 'src'},
|
||||
{selector: 'link[rel="stylesheet"]', attr: 'href'},
|
||||
{selector: 'script', attr: 'src'}
|
||||
],
|
||||
request: {
|
||||
headers: {
|
||||
'User-Agent': 'Mozilla/5.0 (Linux; Android 4.2.1; en-us; Nexus 4 Build/JOP40D) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Mobile Safari/535.19'
|
||||
}
|
||||
}
|
||||
}).then(function (result) {
|
||||
console.log(result);
|
||||
}).catch(function(err){
|
||||
console.log(err);
|
||||
});
|
||||
Reference in New Issue
Block a user