diff --git a/.eslintignore b/.eslintignore index 78502e5ab..94aecd834 100644 --- a/.eslintignore +++ b/.eslintignore @@ -2,3 +2,4 @@ dist/* coverage/* karma.conf.js +/**/*.d.ts \ No newline at end of file diff --git a/dist/mercury.d.ts b/dist/mercury.d.ts new file mode 100644 index 000000000..026f1f387 --- /dev/null +++ b/dist/mercury.d.ts @@ -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; + 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; + + const exported: { + parse: typeof parse; + }; + export default exported; +} diff --git a/rollup.config.js b/rollup.config.js index b0eac06ca..3e37984e0 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -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: [ @@ -10,6 +15,7 @@ export default { externalHelpers: false, runtimeHelpers: true, }), + copyDeclarations('src/mercury.d.ts', 'dist/mercury.d.ts'), ], treeshake: true, output: { diff --git a/src/mercury.d.ts b/src/mercury.d.ts new file mode 100644 index 000000000..026f1f387 --- /dev/null +++ b/src/mercury.d.ts @@ -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; + 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; + + const exported: { + parse: typeof parse; + }; + export default exported; +}