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:
screendriver
2016-11-01 14:01:53 +01:00
committed by Masahiro Wakame
parent 830b43f05e
commit b398805089
3 changed files with 98 additions and 0 deletions

50
website-scraper/index.d.ts vendored Normal file
View 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;

View 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"
]
}

View 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);
});