-
Notifications
You must be signed in to change notification settings - Fork 147
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #289 from ndaidong/7.0.2
v7.0.2
- Loading branch information
Showing
10 changed files
with
248 additions
and
148 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
// Type definitions | ||
|
||
import {AxiosRequestConfig} from "axios"; | ||
import {IOptions as SanitizeOptions} from "sanitize-html"; | ||
import {defaults} from "html-crush"; | ||
import "urlpattern-polyfill"; | ||
|
||
type HtmlCrushOptions = Partial<typeof defaults> | ||
|
||
/** | ||
* @example | ||
* { | ||
* patterns: [ | ||
* '*://example.com/books/:id', { | ||
* hostname: 'example.com', | ||
* pathname: '/books/:id', | ||
* } | ||
* ], | ||
* selector: '.article-body', | ||
* unwanted: ['.removing-box'] | ||
* } | ||
*/ | ||
export interface Transformation { | ||
patterns: Array<URLPatternInit | string>, | ||
pre?: (document: Document) => Document | ||
post?: (document: Document) => Document | ||
} | ||
|
||
/** | ||
* @param input url or html | ||
*/ | ||
export function extract(input: string): Promise<ArticleData>; | ||
|
||
export function addTransformations(transformations: Array<Transformation>): Number; | ||
|
||
export function removeTransformations(options: Array<URLPatternInit>): Number; | ||
|
||
export function setParserOptions(options: ParserOptions): void; | ||
|
||
export function setRequestOptions(options: AxiosRequestConfig): void; | ||
|
||
export function setSanitizeHtmlOptions(options: SanitizeOptions): void; | ||
|
||
export function setHtmlCrushOptions(options: HtmlCrushOptions): void; | ||
|
||
export function getParserOptions(): ParserOptions; | ||
|
||
export function getRequestOptions(): AxiosRequestConfig; | ||
|
||
export function getSanitizeHtmlOptions(): SanitizeOptions; | ||
|
||
export function getHtmlCrushOptions(): HtmlCrushOptions; | ||
|
||
export interface ParserOptions { | ||
/** | ||
* For estimating "time to read". | ||
* Default: 300 | ||
*/ | ||
wordsPerMinute: number | ||
/** | ||
* To find the best url from list | ||
*/ | ||
urlsCompareAlgorithm: 'levenshtein' | 'cosine' | 'diceCoefficient' | 'jaccardIndex' | 'lcs' | 'mlcs' | ||
/** | ||
* Min num of chars required for description | ||
* Default: 40 | ||
*/ | ||
descriptionLengthThreshold: number | ||
/** | ||
* Max num of chars generated for description | ||
* Default: 156 | ||
*/ | ||
descriptionTruncateLen: number | ||
/** | ||
* Min num of chars required for content | ||
* Default: 200 | ||
*/ | ||
contentLengthThreshold: number | ||
} | ||
|
||
export interface ArticleData { | ||
url?: string; | ||
links?: string[]; | ||
title?: string; | ||
description?: string; | ||
image?: string; | ||
author?: string; | ||
content?: string; | ||
source?: string; | ||
published?: string; | ||
ttr?: number; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"name": "article-parser-cjs", | ||
"version": "7.0.1", | ||
"version": "7.0.2", | ||
"main": "./article-parser.js" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters