extract the parser api to a base class
authorxangelo <git@xangelo.ca>
Wed, 6 Apr 2022 16:47:56 +0000 (12:47 -0400)
committerxangelo <git@xangelo.ca>
Wed, 6 Apr 2022 16:47:56 +0000 (12:47 -0400)
src/parsers/base.ts
src/parsers/rss.ts

index 64aaa8b60ff894cace3f5afc1b11a79fedbb503c..acf9a250037364fec06eff3cc8976a9f687113f2 100644 (file)
@@ -11,3 +11,7 @@ export type Feed = {
   link: string;
   items: FeedItem[];
 };
+
+export abstract class BaseParser {
+  abstract parse(url: string): Promise<Feed>;
+}
index d23dcc2327b0c348dd0c605d2c58dd55e04a4754..e2db58d7ef130576cd42efd7073fb2f937c9db9a 100644 (file)
@@ -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;
   }