From: xangelo Date: Wed, 6 Apr 2022 16:47:56 +0000 (-0400) Subject: extract the parser api to a base class X-Git-Url: https://git.xangelo.ca/?p=rss-reader.git;a=commitdiff_plain;h=ec6bf9840b03bdab70c4ca028b6e0acc7c4af897 extract the parser api to a base class --- diff --git a/src/parsers/base.ts b/src/parsers/base.ts index 64aaa8b..acf9a25 100644 --- a/src/parsers/base.ts +++ b/src/parsers/base.ts @@ -11,3 +11,7 @@ export type Feed = { link: string; items: FeedItem[]; }; + +export abstract class BaseParser { + abstract parse(url: string): Promise; +} diff --git a/src/parsers/rss.ts b/src/parsers/rss.ts index d23dcc2..e2db58d 100644 --- a/src/parsers/rss.ts +++ b/src/parsers/rss.ts @@ -1,5 +1,5 @@ import Parser from 'rss-parser'; -import {Feed} from './base'; +import {Feed, BaseParser} from './base'; function timestamp(str: string): number { const date = +(new Date(str)); @@ -13,9 +13,10 @@ function reasonable(dateStr: string): string { return `${date.getFullYear()}-${month}-${day}`; } -export class RSSParser { +export class RSSParser extends BaseParser { parser: Parser; constructor() { + super(); this.parser = new Parser; }