From ec6bf9840b03bdab70c4ca028b6e0acc7c4af897 Mon Sep 17 00:00:00 2001 From: xangelo Date: Wed, 6 Apr 2022 12:47:56 -0400 Subject: [PATCH] extract the parser api to a base class --- src/parsers/base.ts | 4 ++++ src/parsers/rss.ts | 5 +++-- 2 files changed, 7 insertions(+), 2 deletions(-) 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; } -- 2.25.1