feedscout 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Maciej Lamberski
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,113 @@
1
+ # Feedscout
2
+
3
+ [![codecov](https://codecov.io/gh/macieklamberski/feedscout/branch/main/graph/badge.svg)](https://codecov.io/gh/macieklamberski/feedscout)
4
+ [![npm version](https://img.shields.io/npm/v/feedscout.svg)](https://www.npmjs.com/package/feedscout)
5
+ [![license](https://img.shields.io/npm/l/feedscout.svg)](https://github.com/macieklamberski/feedscout/blob/main/LICENSE)
6
+
7
+ Lightweight feed autodiscovery for TypeScript. Extract RSS, Atom, and JSON feed URIs from HTML with configurable options.
8
+
9
+ > **Work in Progress:** This library is under active development. The API may change before reaching v1.0.
10
+
11
+ ## Overview
12
+
13
+ Feedscout makes it easy to gather all feed URIs from a webpage. It implements multiple discovery strategies:
14
+
15
+ - **Standard autodiscovery** — `<link rel="alternate">` with feed MIME types
16
+ - **HTML5 feeds** — `<link rel="feed">` elements
17
+ - **Anchor patterns** — Links matching `/feed`, `/rss.xml`, etc.
18
+ - **Anchor text** — Links containing "RSS", "Subscribe", etc.
19
+
20
+ The library uses [htmlparser2](https://github.com/fb55/htmlparser2) for efficient HTML parsing with low memory footprint (streaming support on the roadmap).
21
+
22
+ Implementation follows [RSS Board](https://www.rssboard.org/rss-autodiscovery), [WHATWG](https://blog.whatwg.org/feed-autodiscovery), and [historical best practices](https://web.archive.org/web/20100620085023/http://diveintomark.org/archives/2002/08/15/ultraliberal_rss_locator) for feed autodiscovery.
23
+
24
+ ## Installation
25
+
26
+ ```bash
27
+ npm install feedscout
28
+ ```
29
+
30
+ ## Usage
31
+
32
+ ```typescript
33
+ import { discoverFeedUris } from 'feedscout'
34
+
35
+ const html = `
36
+ <html>
37
+ <head>
38
+ <link rel="alternate" type="application/rss+xml" href="/feed.xml" />
39
+ </head>
40
+ <body>
41
+ <a href="/rss">RSS Feed</a>
42
+ </body>
43
+ </html>
44
+ `
45
+
46
+ const uris = discoverFeedUris(html, {
47
+ linkMimeTypes: ['application/rss+xml', 'application/atom+xml'],
48
+ anchorUris: ['/feed', '/rss', '/rss.xml'],
49
+ anchorIgnoredUris: ['wp-json/', 'comments'],
50
+ anchorLabels: ['rss', 'feed', 'subscribe'],
51
+ })
52
+
53
+ console.log(uris) // ['/feed.xml', '/rss']
54
+ ```
55
+
56
+ Returned URIs may be relative. Resolve to absolute URLs using new URL(uri, baseUrl).
57
+
58
+ Identical URIs are deduplicated, but variations like http:// vs https:// are preserved.
59
+
60
+ ## API Reference
61
+
62
+ ### `discoverFeedUris(html, options)`
63
+
64
+ Discovers feed URIs from HTML content.
65
+
66
+ | Parameter | Type | Required | Description |
67
+ |-----------|------|----------|-------------|
68
+ | `html` | `string` | Yes | HTML content to parse |
69
+ | `options` | `DiscoverFeedUrisOptions` | Yes | Discovery configuration |
70
+
71
+ **Returns:** `string[]` — Array of discovered feed URIs (may be relative)
72
+
73
+ ### `DiscoverFeedUrisOptions`
74
+
75
+ All options are **required**. Configure each discovery strategy explicitly.
76
+
77
+ | Property | Type | Description |
78
+ |----------|------|-------------|
79
+ | `linkMimeTypes` | `string[]` | MIME types to match in `<link type="...">` attributes |
80
+ | `anchorUris` | `string[]` | URI patterns to match in anchor `href` attributes |
81
+ | `anchorIgnoredUris` | `string[]` | URI patterns to exclude from anchor matching |
82
+ | `anchorLabels` | `string[]` | Text patterns to match in anchor content (case-insensitive) |
83
+
84
+ **Example configuration:**
85
+
86
+ ```typescript
87
+ const options: DiscoverFeedUrisOptions = {
88
+ linkMimeTypes: [
89
+ 'application/rss+xml',
90
+ 'application/atom+xml',
91
+ 'application/json',
92
+ 'application/feed+json',
93
+ ],
94
+ anchorUris: [
95
+ '/feed',
96
+ '/rss',
97
+ '/rss.xml',
98
+ '/atom.xml',
99
+ '?feed=rss',
100
+ ],
101
+ anchorIgnoredUris: [
102
+ 'wp-json/',
103
+ 'comments',
104
+ 'twitter.com',
105
+ ],
106
+ anchorLabels: [
107
+ 'rss',
108
+ 'feed',
109
+ 'atom',
110
+ 'subscribe',
111
+ ],
112
+ }
113
+ ```
File without changes
@@ -0,0 +1,2 @@
1
+ import { n as ParserContext, t as DiscoverFeedUrisOptions } from "../types-BZOn_2Ua.cjs";
2
+ export { DiscoverFeedUrisOptions, ParserContext };
@@ -0,0 +1,2 @@
1
+ import { n as ParserContext, t as DiscoverFeedUrisOptions } from "../types-B0jVPx9s.js";
2
+ export { DiscoverFeedUrisOptions, ParserContext };
@@ -0,0 +1 @@
1
+ export { };
@@ -0,0 +1,7 @@
1
+ const require_utils = require('../utils-DsxN2_bI.cjs');
2
+
3
+ exports.createHandlers = require_utils.createHandlers;
4
+ exports.handleCloseTag = require_utils.handleCloseTag;
5
+ exports.handleOpenTag = require_utils.handleOpenTag;
6
+ exports.handleText = require_utils.handleText;
7
+ exports.includesAny = require_utils.includesAny;
@@ -0,0 +1,13 @@
1
+ import { n as ParserContext } from "../types-BZOn_2Ua.cjs";
2
+ import { Handler } from "htmlparser2";
3
+
4
+ //#region src/common/utils.d.ts
5
+ declare const includesAny: (value: string, patterns: Array<string>) => boolean;
6
+ declare const handleOpenTag: (context: ParserContext, name: string, attribs: {
7
+ [key: string]: string;
8
+ }, _isImplied: boolean) => void;
9
+ declare const handleText: (context: ParserContext, text: string) => void;
10
+ declare const handleCloseTag: (context: ParserContext, name: string, _isImplied: boolean) => void;
11
+ declare const createHandlers: (context: ParserContext) => Partial<Handler>;
12
+ //#endregion
13
+ export { createHandlers, handleCloseTag, handleOpenTag, handleText, includesAny };
@@ -0,0 +1,13 @@
1
+ import { n as ParserContext } from "../types-B0jVPx9s.js";
2
+ import { Handler } from "htmlparser2";
3
+
4
+ //#region src/common/utils.d.ts
5
+ declare const includesAny: (value: string, patterns: Array<string>) => boolean;
6
+ declare const handleOpenTag: (context: ParserContext, name: string, attribs: {
7
+ [key: string]: string;
8
+ }, _isImplied: boolean) => void;
9
+ declare const handleText: (context: ParserContext, text: string) => void;
10
+ declare const handleCloseTag: (context: ParserContext, name: string, _isImplied: boolean) => void;
11
+ declare const createHandlers: (context: ParserContext) => Partial<Handler>;
12
+ //#endregion
13
+ export { createHandlers, handleCloseTag, handleOpenTag, handleText, includesAny };
@@ -0,0 +1,3 @@
1
+ import { a as includesAny, i as handleText, n as handleCloseTag, r as handleOpenTag, t as createHandlers } from "../utils-BVlxsJfJ.js";
2
+
3
+ export { createHandlers, handleCloseTag, handleOpenTag, handleText, includesAny };
package/dist/index.cjs ADDED
@@ -0,0 +1,45 @@
1
+ //#region rolldown:runtime
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
10
+ key = keys[i];
11
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
12
+ get: ((k) => from[k]).bind(null, key),
13
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
14
+ });
15
+ }
16
+ return to;
17
+ };
18
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
19
+ value: mod,
20
+ enumerable: true
21
+ }) : target, mod));
22
+
23
+ //#endregion
24
+ const require_utils = require('./utils-DsxN2_bI.cjs');
25
+ let htmlparser2 = require("htmlparser2");
26
+ htmlparser2 = __toESM(htmlparser2);
27
+
28
+ //#region src/discover/index.ts
29
+ const discoverFeedUris = (html, options) => {
30
+ const context = {
31
+ discoveredUris: /* @__PURE__ */ new Set(),
32
+ currentAnchor: {
33
+ href: "",
34
+ text: ""
35
+ },
36
+ options
37
+ };
38
+ const parser = new htmlparser2.Parser(require_utils.createHandlers(context), { decodeEntities: true });
39
+ parser.write(html);
40
+ parser.end();
41
+ return Array.from(context.discoveredUris);
42
+ };
43
+
44
+ //#endregion
45
+ exports.discoverFeedUris = discoverFeedUris;
@@ -0,0 +1,6 @@
1
+ import { t as DiscoverFeedUrisOptions } from "./types-BZOn_2Ua.cjs";
2
+
3
+ //#region src/discover/index.d.ts
4
+ declare const discoverFeedUris: (html: string, options: DiscoverFeedUrisOptions) => Array<string>;
5
+ //#endregion
6
+ export { type DiscoverFeedUrisOptions, discoverFeedUris };
@@ -0,0 +1,6 @@
1
+ import { t as DiscoverFeedUrisOptions } from "./types-B0jVPx9s.js";
2
+
3
+ //#region src/discover/index.d.ts
4
+ declare const discoverFeedUris: (html: string, options: DiscoverFeedUrisOptions) => Array<string>;
5
+ //#endregion
6
+ export { type DiscoverFeedUrisOptions, discoverFeedUris };
package/dist/index.js ADDED
@@ -0,0 +1,21 @@
1
+ import { t as createHandlers } from "./utils-BVlxsJfJ.js";
2
+ import { Parser } from "htmlparser2";
3
+
4
+ //#region src/discover/index.ts
5
+ const discoverFeedUris = (html, options) => {
6
+ const context = {
7
+ discoveredUris: /* @__PURE__ */ new Set(),
8
+ currentAnchor: {
9
+ href: "",
10
+ text: ""
11
+ },
12
+ options
13
+ };
14
+ const parser = new Parser(createHandlers(context), { decodeEntities: true });
15
+ parser.write(html);
16
+ parser.end();
17
+ return Array.from(context.discoveredUris);
18
+ };
19
+
20
+ //#endregion
21
+ export { discoverFeedUris };
@@ -0,0 +1,17 @@
1
+ //#region src/common/types.d.ts
2
+ type DiscoverFeedUrisOptions = {
3
+ linkMimeTypes: Array<string>;
4
+ anchorUris: Array<string>;
5
+ anchorIgnoredUris: Array<string>;
6
+ anchorLabels: Array<string>;
7
+ };
8
+ type ParserContext = {
9
+ discoveredUris: Set<string>;
10
+ currentAnchor: {
11
+ href: string;
12
+ text: string;
13
+ };
14
+ options: DiscoverFeedUrisOptions;
15
+ };
16
+ //#endregion
17
+ export { ParserContext as n, DiscoverFeedUrisOptions as t };
@@ -0,0 +1,17 @@
1
+ //#region src/common/types.d.ts
2
+ type DiscoverFeedUrisOptions = {
3
+ linkMimeTypes: Array<string>;
4
+ anchorUris: Array<string>;
5
+ anchorIgnoredUris: Array<string>;
6
+ anchorLabels: Array<string>;
7
+ };
8
+ type ParserContext = {
9
+ discoveredUris: Set<string>;
10
+ currentAnchor: {
11
+ href: string;
12
+ text: string;
13
+ };
14
+ options: DiscoverFeedUrisOptions;
15
+ };
16
+ //#endregion
17
+ export { ParserContext as n, DiscoverFeedUrisOptions as t };
@@ -0,0 +1,49 @@
1
+ //#region src/common/utils.ts
2
+ const includesAny = (value, patterns) => {
3
+ const lowerValue = value?.toLowerCase();
4
+ return patterns.some((pattern) => lowerValue?.includes(pattern.toLowerCase()));
5
+ };
6
+ const handleOpenTag = (context, name, attribs, _isImplied) => {
7
+ if (name === "link" && attribs.href) {
8
+ const rel = attribs.rel?.toLowerCase();
9
+ if (rel === "alternate" && includesAny(attribs.type, context.options.linkMimeTypes)) context.discoveredUris.add(attribs.href);
10
+ if (rel?.includes("feed") && !rel.includes("stylesheet")) context.discoveredUris.add(attribs.href);
11
+ }
12
+ if (name === "a" && attribs.href) {
13
+ const lowerHref = attribs.href.toLowerCase();
14
+ if (includesAny(lowerHref, context.options.anchorIgnoredUris)) {
15
+ context.currentAnchor.href = "";
16
+ context.currentAnchor.text = "";
17
+ return;
18
+ }
19
+ context.currentAnchor.href = attribs.href;
20
+ context.currentAnchor.text = "";
21
+ if (context.options.anchorUris.some((uri) => lowerHref.endsWith(uri.toLowerCase()))) context.discoveredUris.add(attribs.href);
22
+ }
23
+ };
24
+ const handleText = (context, text) => {
25
+ if (context.currentAnchor.href) context.currentAnchor.text += text;
26
+ };
27
+ const handleCloseTag = (context, name, _isImplied) => {
28
+ if (name === "a" && context.currentAnchor.href && context.currentAnchor.text) {
29
+ if (includesAny(context.currentAnchor.text.toLowerCase().trim(), context.options.anchorLabels)) context.discoveredUris.add(context.currentAnchor.href);
30
+ context.currentAnchor.href = "";
31
+ context.currentAnchor.text = "";
32
+ }
33
+ };
34
+ const createHandlers = (context) => {
35
+ return {
36
+ onopentag: (name, attribs, isImplied) => {
37
+ return handleOpenTag(context, name, attribs, isImplied);
38
+ },
39
+ ontext: (text) => {
40
+ return handleText(context, text);
41
+ },
42
+ onclosetag: (name, isImplied) => {
43
+ return handleCloseTag(context, name, isImplied);
44
+ }
45
+ };
46
+ };
47
+
48
+ //#endregion
49
+ export { includesAny as a, handleText as i, handleCloseTag as n, handleOpenTag as r, createHandlers as t };
@@ -0,0 +1,79 @@
1
+
2
+ //#region src/common/utils.ts
3
+ const includesAny = (value, patterns) => {
4
+ const lowerValue = value?.toLowerCase();
5
+ return patterns.some((pattern) => lowerValue?.includes(pattern.toLowerCase()));
6
+ };
7
+ const handleOpenTag = (context, name, attribs, _isImplied) => {
8
+ if (name === "link" && attribs.href) {
9
+ const rel = attribs.rel?.toLowerCase();
10
+ if (rel === "alternate" && includesAny(attribs.type, context.options.linkMimeTypes)) context.discoveredUris.add(attribs.href);
11
+ if (rel?.includes("feed") && !rel.includes("stylesheet")) context.discoveredUris.add(attribs.href);
12
+ }
13
+ if (name === "a" && attribs.href) {
14
+ const lowerHref = attribs.href.toLowerCase();
15
+ if (includesAny(lowerHref, context.options.anchorIgnoredUris)) {
16
+ context.currentAnchor.href = "";
17
+ context.currentAnchor.text = "";
18
+ return;
19
+ }
20
+ context.currentAnchor.href = attribs.href;
21
+ context.currentAnchor.text = "";
22
+ if (context.options.anchorUris.some((uri) => lowerHref.endsWith(uri.toLowerCase()))) context.discoveredUris.add(attribs.href);
23
+ }
24
+ };
25
+ const handleText = (context, text) => {
26
+ if (context.currentAnchor.href) context.currentAnchor.text += text;
27
+ };
28
+ const handleCloseTag = (context, name, _isImplied) => {
29
+ if (name === "a" && context.currentAnchor.href && context.currentAnchor.text) {
30
+ if (includesAny(context.currentAnchor.text.toLowerCase().trim(), context.options.anchorLabels)) context.discoveredUris.add(context.currentAnchor.href);
31
+ context.currentAnchor.href = "";
32
+ context.currentAnchor.text = "";
33
+ }
34
+ };
35
+ const createHandlers = (context) => {
36
+ return {
37
+ onopentag: (name, attribs, isImplied) => {
38
+ return handleOpenTag(context, name, attribs, isImplied);
39
+ },
40
+ ontext: (text) => {
41
+ return handleText(context, text);
42
+ },
43
+ onclosetag: (name, isImplied) => {
44
+ return handleCloseTag(context, name, isImplied);
45
+ }
46
+ };
47
+ };
48
+
49
+ //#endregion
50
+ Object.defineProperty(exports, 'createHandlers', {
51
+ enumerable: true,
52
+ get: function () {
53
+ return createHandlers;
54
+ }
55
+ });
56
+ Object.defineProperty(exports, 'handleCloseTag', {
57
+ enumerable: true,
58
+ get: function () {
59
+ return handleCloseTag;
60
+ }
61
+ });
62
+ Object.defineProperty(exports, 'handleOpenTag', {
63
+ enumerable: true,
64
+ get: function () {
65
+ return handleOpenTag;
66
+ }
67
+ });
68
+ Object.defineProperty(exports, 'handleText', {
69
+ enumerable: true,
70
+ get: function () {
71
+ return handleText;
72
+ }
73
+ });
74
+ Object.defineProperty(exports, 'includesAny', {
75
+ enumerable: true,
76
+ get: function () {
77
+ return includesAny;
78
+ }
79
+ });
package/package.json ADDED
@@ -0,0 +1,75 @@
1
+ {
2
+ "name": "feedscout",
3
+ "description": "Lightweight feed autodiscovery for TypeScript. Extract RSS, Atom, and JSON feed URIs from HTML with configurable options.",
4
+ "keywords": [
5
+ "rss",
6
+ "rss-autodiscovery",
7
+ "autodiscovery",
8
+ "auto-discovery",
9
+ "feed-finder",
10
+ "rss-finder",
11
+ "feed-discovery",
12
+ "rss-discovery",
13
+ "feed-locator"
14
+ ],
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "https://github.com/macieklamberski/feedscout.git"
18
+ },
19
+ "homepage": "https://github.com/macieklamberski/feedscout",
20
+ "bugs": {
21
+ "url": "https://github.com/macieklamberski/feedscout/issues"
22
+ },
23
+ "author": "Maciej Lamberski",
24
+ "license": "MIT",
25
+ "type": "module",
26
+ "files": [
27
+ "dist"
28
+ ],
29
+ "exports": {
30
+ ".": {
31
+ "import": {
32
+ "types": "./dist/index.d.ts",
33
+ "default": "./dist/index.js"
34
+ },
35
+ "require": {
36
+ "types": "./dist/index.d.cts",
37
+ "default": "./dist/index.cjs"
38
+ }
39
+ },
40
+ "./utils": {
41
+ "import": {
42
+ "types": "./dist/common/utils.d.ts",
43
+ "default": "./dist/common/utils.js"
44
+ },
45
+ "require": {
46
+ "types": "./dist/common/utils.d.cts",
47
+ "default": "./dist/common/utils.cjs"
48
+ }
49
+ },
50
+ "./types": {
51
+ "import": {
52
+ "types": "./dist/common/types.d.ts",
53
+ "default": "./dist/common/types.js"
54
+ },
55
+ "require": {
56
+ "types": "./dist/common/types.d.cts",
57
+ "default": "./dist/common/types.cjs"
58
+ }
59
+ },
60
+ "./package.json": "./package.json"
61
+ },
62
+ "scripts": {
63
+ "prepare": "lefthook install",
64
+ "build": "tsdown src/index.ts src/common/utils.ts src/common/types.ts --format cjs,esm --dts --clean"
65
+ },
66
+ "dependencies": {
67
+ "htmlparser2": "^10.0.0"
68
+ },
69
+ "devDependencies": {
70
+ "@types/bun": "^1.3.2",
71
+ "kvalita": "^1.3.1",
72
+ "tsdown": "^0.15.12"
73
+ },
74
+ "version": "0.9.0"
75
+ }