Skip to content

Commit 29daf6e

Browse files
danmactoughclaude
andcommitted
Add automated typecheck for type definitions
Adds test/types.ts exercising the full public API surface, a typecheck script running tsc --strict, and wires it into pretest alongside lint. Also adds .eslintignore to skip .ts files and typescript as a devDep. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent d7ec424 commit 29daf6e

File tree

4 files changed

+98
-3
lines changed

4 files changed

+98
-3
lines changed

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
**/*.ts

package-lock.json

Lines changed: 16 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,13 @@
5252
"eslint": "^6.8.0",
5353
"iconv-lite": "^0.5.1",
5454
"mocha": "^7.1.2",
55-
"node-fetch": "^2.6.0"
55+
"node-fetch": "^2.6.0",
56+
"typescript": "^5.9.3"
5657
},
5758
"scripts": {
5859
"lint": "eslint .",
59-
"pretest": "npm run lint",
60+
"typecheck": "tsc --noEmit --strict test/types.ts --lib es6 --module commonjs",
61+
"pretest": "npm run lint && npm run typecheck",
6062
"test": "mocha",
6163
"version": "git changelog ; git add History.md"
6264
},

test/types.ts

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
import FeedParser = require('../index');
2+
3+
// Constructor with no options
4+
const fp1 = new FeedParser();
5+
6+
// Constructor with all options
7+
const fp2 = new FeedParser({
8+
strict: false,
9+
normalize: true,
10+
addmeta: true,
11+
feedurl: 'https://example.com/feed',
12+
resume_saxerror: true,
13+
MAX_BUFFER_LENGTH: 1024 * 1024,
14+
});
15+
16+
// meta event
17+
fp2.on('meta', (meta: FeedParser.Meta) => {
18+
const title: string = meta.title;
19+
const description: string = meta.description;
20+
const type: FeedParser.Type = meta['#type'];
21+
const version: string = meta['#version'];
22+
const ns: Array<{ [key: string]: string }> = meta['#ns'];
23+
const attrs: { [key: string]: any } = meta['@'];
24+
const date: Date | null = meta.date;
25+
const pubdate: Date | null = meta.pubdate;
26+
const link: string = meta.link;
27+
const xmlurl: string = meta.xmlurl;
28+
const author: string = meta.author;
29+
const language: string = meta.language;
30+
const image: FeedParser.Image = meta.image;
31+
const imageUrl: string = image.url;
32+
const favicon: string = meta.favicon;
33+
const copyright: string = meta.copyright;
34+
const generator: string = meta.generator;
35+
const categories: string[] = meta.categories;
36+
// namespace-prefixed properties via index signature
37+
const itunesAuthor = meta['itunes:author'];
38+
});
39+
40+
// error event
41+
fp2.on('error', (err: Error) => {
42+
err.message;
43+
});
44+
45+
// readable event + read()
46+
fp2.on('readable', () => {
47+
let item: FeedParser.Item | null;
48+
while ((item = fp2.read()) !== null) {
49+
const title: string = item.title;
50+
const description: string = item.description;
51+
const summary: string = item.summary;
52+
const date: Date | null = item.date;
53+
const pubdate: Date | null = item.pubdate;
54+
const link: string = item.link;
55+
const origlink: string = item.origlink;
56+
const author: string = item.author;
57+
const guid: string = item.guid;
58+
const comments: string = item.comments;
59+
const image: { url: string } = item.image;
60+
const categories: string[] = item.categories;
61+
const source: FeedParser.Source = item.source;
62+
const sourceTitle: string = source.title;
63+
const sourceUrl: string = source.url;
64+
const enclosures: FeedParser.Enclosure[] = item.enclosures;
65+
const enc: FeedParser.Enclosure = enclosures[0];
66+
const encUrl: string = enc.url;
67+
const meta: FeedParser.Meta = item.meta;
68+
// namespace-prefixed properties via index signature
69+
const mediaContent = item['media:content'];
70+
}
71+
});
72+
73+
// once and addListener overloads
74+
fp2.once('meta', (_meta: FeedParser.Meta) => {});
75+
fp2.addListener('error', (_err: Error) => {});
76+
77+
fp2.resumeSaxError();

0 commit comments

Comments
 (0)