add mozilla/readability types (#23038)

This commit is contained in:
Charles Vandevoorde 2018-01-18 21:50:13 +01:00 committed by Wesley Wigham
parent 12c04f3166
commit 02be5edae6
4 changed files with 114 additions and 0 deletions

43
types/mozilla-readability/index.d.ts vendored Normal file
View File

@ -0,0 +1,43 @@
// Type definitions for mozilla-readability 0.1
// Project: https://github.com/mozilla/readability
// Definitions by: Charles Vandevoorde <https://github.com/charlesvdv>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.2
export = Readability;
declare class Readability {
constructor(uri: Readability.Uri, doc: Document, options?: Readability.Options);
parse(): Readability.ParseResult;
isProbablyReaderable(helperIsVisible?: (node: any) => boolean): boolean;
}
declare namespace Readability {
interface Uri {
spec: string;
host: string;
prePath: string;
scheme: string;
pathBase: string;
}
interface Options {
debug?: boolean;
maxElemsToParse?: number;
nbTopCandidates?: number;
wordThreshold?: number;
classesToPreserve?: string[];
}
interface ParseResult {
uri: Uri;
title: string;
byline: string;
dir: string;
content: string;
textContent: string;
length: number;
excerpt: string;
}
}

View File

@ -0,0 +1,46 @@
import * as Readability from 'mozilla-readability';
import { JSDOM } from 'jsdom';
// Compiling requires `--noImplicitUseStrict`
// because issue https://github.com/mozilla/readability/issues/346
// requires global variable `Node` when using nodejs.
const fakeUri: Readability.Uri = {
spec: "http://fakehost/test/page.html",
host: "fakehost",
prePath: "http://fakehost",
scheme: "http",
pathBase: "http://fakehost/test/"
};
function test_basic_usage() {
const dom = new JSDOM(`<p>Hello</p><p><strong>Hi!</strong>`);
// Required until https://github.com/mozilla/readability/issues/346
// is fixed.
Node = dom.window.Node;
const reader = new Readability(fakeUri, dom.window.document);
const article = reader.parse();
}
function test_readability_with_options() {
const dom = new JSDOM(`<p>Hello</p><p><strong>Hi!</strong>`);
// Required until https://github.com/mozilla/readability/issues/346
// is fixed.
Node = dom.window.Node;
const options: Readability.Options = {
debug: true,
maxElemsToParse: 100,
};
const article = new Readability(fakeUri, dom.window.document, options).parse();
}
function test_is_probably_readerable() {
const dom = new JSDOM(`<p>Hello</p><p><strong>Hi!</strong>`);
// Required until https://github.com/mozilla/readability/issues/346
// is fixed.
Node = dom.window.Node;
const isReadable = new Readability(fakeUri, dom.window.document).isProbablyReaderable();
}

View File

@ -0,0 +1,24 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6",
"dom"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": false,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"mozilla-readability-tests.ts"
]
}

View File

@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }