Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
dist/*
coverage/*
karma.conf.js
/**/*.d.ts
40 changes: 40 additions & 0 deletions dist/mercury.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
declare module '@postlight/parser' {
export type ExtractorArgs = any;

export type ParserOptions = {
html?: string;
fetchAllPages?: boolean;
fallback?: boolean;
contentType?: 'html' | 'markdown' | 'text';
headers?: Record<string, string>;
extend?: boolean;
customExtractor?: (args: ExtractorArgs) => ParserResult;
};

export type ParserResult = {
title: string;
content: string;
author: string;
date_published: string;
lead_image_url: string;
dek: string;
next_page_url: string;
url: string;
domain: string;
excerpt: string;
word_count: number;
direction: string;
total_pages: number;
rendered_pages: number;
};

export function parse(
url: string,
opts: ParserOptions
): Promise<ParserResult>;

const exported: {
parse: typeof parse;
};
export default exported;
}
6 changes: 6 additions & 0 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
/* eslint-disable import/no-extraneous-dependencies */
import fs from 'fs';
import babel from 'rollup-plugin-babel';
import commonjs from 'rollup-plugin-commonjs';

const copyDeclarations = (src, dest) => {
fs.copyFileSync(src, dest);
};

export default {
input: 'src/mercury.js',
plugins: [
Expand All @@ -10,6 +15,7 @@ export default {
externalHelpers: false,
runtimeHelpers: true,
}),
copyDeclarations('src/mercury.d.ts', 'dist/mercury.d.ts'),
],
treeshake: true,
output: {
Expand Down
40 changes: 40 additions & 0 deletions src/mercury.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
declare module '@postlight/parser' {
export type ExtractorArgs = any;

export type ParserOptions = {
html?: string;
fetchAllPages?: boolean;
fallback?: boolean;
contentType?: 'html' | 'markdown' | 'text';
headers?: Record<string, string>;
extend?: boolean;
customExtractor?: (args: ExtractorArgs) => ParserResult;
};

export type ParserResult = {
title: string;
content: string;
author: string;
date_published: string;
lead_image_url: string;
dek: string;
next_page_url: string;
url: string;
domain: string;
excerpt: string;
word_count: number;
direction: string;
total_pages: number;
rendered_pages: number;
};

export function parse(
url: string,
opts: ParserOptions
): Promise<ParserResult>;

const exported: {
parse: typeof parse;
};
export default exported;
}