mirror of
https://github.com/FlipsideCrypto/DefinitelyTyped.git
synced 2026-02-06 19:07:08 +00:00
add mozilla/readability types (#23038)
This commit is contained in:
parent
12c04f3166
commit
02be5edae6
43
types/mozilla-readability/index.d.ts
vendored
Normal file
43
types/mozilla-readability/index.d.ts
vendored
Normal 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;
|
||||
}
|
||||
}
|
||||
46
types/mozilla-readability/mozilla-readability-tests.ts
Normal file
46
types/mozilla-readability/mozilla-readability-tests.ts
Normal 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();
|
||||
}
|
||||
24
types/mozilla-readability/tsconfig.json
Normal file
24
types/mozilla-readability/tsconfig.json
Normal 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"
|
||||
]
|
||||
}
|
||||
1
types/mozilla-readability/tslint.json
Normal file
1
types/mozilla-readability/tslint.json
Normal file
@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Loading…
Reference in New Issue
Block a user