@subconverter/browser 0.0.0-stage → 0.2.1

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/README.md CHANGED
@@ -1,3 +1,55 @@
1
- # Temporary Holding Version
1
+ # @subconverter/browser
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Browser build of [subconverter-ts](https://github.com/jinganix/subconverter): convert
4
+ subscriptions entirely in the page, with no server round trip. Built on
5
+ [`@subconverter/core`](https://npmjs.com/package/@subconverter/core) and shipped as ESM
6
+ plus an IIFE global (`SubConverter`).
7
+
8
+ ```bash
9
+ npm i @subconverter/browser
10
+ ```
11
+
12
+ ## Quick start
13
+
14
+ ```ts
15
+ import { createExtraSettings, loadNodes, toClash } from "@subconverter/browser";
16
+
17
+ const nodes = await loadNodes("https://example.com/sub");
18
+ const clash = toClash(nodes, [], createExtraSettings());
19
+ ```
20
+
21
+ `loadNodes` fetches and parses in one step; `toClash` / `toSurge` are the bundled
22
+ generators. Everything else (the full `parseSubscription`, `generate`, `TargetFormat`,
23
+ and all type exports) is re-exported from `@subconverter/core`.
24
+
25
+ ## Script tag
26
+
27
+ ```html
28
+ <script src="https://unpkg.com/@subconverter/browser/dist/subconverter.global.js"></script>
29
+ <script>
30
+ const nodes = await SubConverter.loadNodes("https://example.com/sub");
31
+ </script>
32
+ ```
33
+
34
+ The IIFE bundle exposes `SubConverter` on `window`.
35
+
36
+ ## CORS
37
+
38
+ The browser build calls `fetch` directly, so the subscription host must allow cross-origin
39
+ requests. When it does not, run the [server from `@subconverter/node`](https://npmjs.com/package/@subconverter/node)
40
+ and point the browser at your own origin instead.
41
+
42
+ ## Package size
43
+
44
+ The IIFE bundle is roughly 160 kB because it contains the whole conversion engine,
45
+ including every parser and generator. Import the ESM entry point to let a bundler drop
46
+ unused targets.
47
+
48
+ ## API reference
49
+
50
+ Every public export with its signature, enum members, and interface fields:
51
+ [docs/API.md](https://github.com/jinganix/subconverter/blob/main/docs/API.md).
52
+
53
+ ## License
54
+
55
+ GPL-3.0.
@@ -0,0 +1,9 @@
1
+ import { Proxy } from '@subconverter/core';
2
+ export { ExtraSettings, Proxy, ProxyGroupConfig, RequestSettings, TargetFormat, createExtraSettings, parseSubscription, toClash, toSurge } from '@subconverter/core';
3
+
4
+ /** Fetch a remote subscription body in the browser. */
5
+ declare function fetchSubscription(url: string, init?: RequestInit): Promise<string>;
6
+ /** Fetch and parse a subscription URL into nodes. */
7
+ declare function loadNodes(url: string, init?: RequestInit): Promise<Proxy[]>;
8
+
9
+ export { fetchSubscription, loadNodes };
package/dist/index.js ADDED
@@ -0,0 +1,27 @@
1
+ // src/index.ts
2
+ import { parseSubscription } from "@subconverter/core";
3
+ import {
4
+ createExtraSettings,
5
+ parseSubscription as parseSubscription2,
6
+ toClash,
7
+ toSurge
8
+ } from "@subconverter/core";
9
+ async function fetchSubscription(url, init) {
10
+ const response = await fetch(url, init);
11
+ if (!response.ok) {
12
+ throw new Error(`Failed to fetch ${url}: ${response.status} ${response.statusText}`);
13
+ }
14
+ return response.text();
15
+ }
16
+ async function loadNodes(url, init) {
17
+ return parseSubscription(await fetchSubscription(url, init));
18
+ }
19
+ export {
20
+ createExtraSettings,
21
+ fetchSubscription,
22
+ loadNodes,
23
+ parseSubscription2 as parseSubscription,
24
+ toClash,
25
+ toSurge
26
+ };
27
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { type Proxy, parseSubscription } from \"@subconverter/core\";\n\nexport {\n type ExtraSettings,\n type Proxy,\n type ProxyGroupConfig,\n type RequestSettings,\n type TargetFormat,\n createExtraSettings,\n parseSubscription,\n toClash,\n toSurge,\n} from \"@subconverter/core\";\n\n/** Fetch a remote subscription body in the browser. */\nexport async function fetchSubscription(url: string, init?: RequestInit): Promise<string> {\n const response = await fetch(url, init);\n if (!response.ok) {\n throw new Error(`Failed to fetch ${url}: ${response.status} ${response.statusText}`);\n }\n return response.text();\n}\n\n/** Fetch and parse a subscription URL into nodes. */\nexport async function loadNodes(url: string, init?: RequestInit): Promise<Proxy[]> {\n return parseSubscription(await fetchSubscription(url, init));\n}\n"],"mappings":";AAAA,SAAqB,yBAAyB;AAE9C;AAAA,EAME;AAAA,EACA,qBAAAA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAGP,eAAsB,kBAAkB,KAAa,MAAqC;AACxF,QAAM,WAAW,MAAM,MAAM,KAAK,IAAI;AACtC,MAAI,CAAC,SAAS,IAAI;AAChB,UAAM,IAAI,MAAM,mBAAmB,GAAG,KAAK,SAAS,MAAM,IAAI,SAAS,UAAU,EAAE;AAAA,EACrF;AACA,SAAO,SAAS,KAAK;AACvB;AAGA,eAAsB,UAAU,KAAa,MAAsC;AACjF,SAAO,kBAAkB,MAAM,kBAAkB,KAAK,IAAI,CAAC;AAC7D;","names":["parseSubscription"]}