janus-parse 2.0.3 → 2.1.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
@@ -57,6 +57,20 @@ const rawHtml = `
57
57
  const cleanText = await janusServer(rawHtml); // Output: "Hello Universe This is a highly spaced sentence."
58
58
  ```
59
59
 
60
+ The `janusServerStream` function is asynchronous. It supports streaming local or from a url.
61
+
62
+ ```typescript
63
+ import { janusServerStream } from "janus-parse/server/stream";
64
+
65
+ const cleanText = await janusServerStream({ filePath: "./sample.html" });
66
+ ```
67
+
68
+ ```typescript
69
+ import { janusServerStream } from "janus-parse/server/stream";
70
+
71
+ const cleanText = await janusServerStream({ url: "https://url.com" });
72
+ ```
73
+
60
74
  ### Client-Side Execution (Browser)
61
75
 
62
76
  The `janusClient` function is synchronous. It ignores server node environments and hooks directly into the browser's native, hardware-optimized `DOMParser` engine.
@@ -72,6 +86,14 @@ const textOnly = janusClient(webMarkup); // Output: " Dynamic Web App"
72
86
 
73
87
  ---
74
88
 
89
+ ```typescript
90
+ import { janusClientStream } from "janus-parse/client/stream";
91
+
92
+ const cleanText = await janusClientStream({ url: "https://url.com" });
93
+ ```
94
+
95
+ ---
96
+
75
97
  ## API Reference
76
98
 
77
99
  #### `Config`
@@ -82,7 +104,22 @@ Optionanl second function parameter to fine-tune tag removal behaviors.
82
104
  type Config {
83
105
  tagsToRemove?: string[];
84
106
  tagsToPreserve?: string[];
85
- }
107
+ };
108
+
109
+ type JanusClientStreamConfig = {
110
+ url: string;
111
+ config?: Config;
112
+ encoding?: BufferEncoding;
113
+ fetchOptions?: RequestInit;
114
+ };
115
+
116
+ type JanusServerStreamConfig = {
117
+ url?: string;
118
+ config?: Config;
119
+ encoding?: BufferEncoding;
120
+ fetchOptions?: RequestInit;
121
+ filePath?: string;
122
+ };
86
123
  ```
87
124
 
88
125
  ---
@@ -91,3 +128,14 @@ type Config {
91
128
  - `config`: Optional rule blocks to override standard cleaning lists.
92
129
  - `janusServer(rawHtml, config)`: Returns a promise that resolves to a stripped, whitespace-normalized single-line string
93
130
  - `janusClient(rawHtml, config)`: Returns a stripped, whitespace-normalized single-line string
131
+
132
+ ## 📦 Bundle Size
133
+
134
+ This package is split into targeted modules. Modern bundlers will only bundle the exact module you import, keeping your builds incredibly lightweight.
135
+
136
+ | Import Path | Target Environment | Size (Gzipped) |
137
+ | :-------------------------- | :----------------- | :------------- |
138
+ | `janus-parse/server` | Node.js | **~47.6 KB** |
139
+ | `janus-parse/server:stream` | Node.js | **~49 KB** |
140
+ | `janus-parse/client` | Browser | **~700 B** |
141
+ | `janus-parse/client:stream` | Browser | **~1 KB** |
@@ -0,0 +1,3 @@
1
+ import type { Config } from "../utils/index";
2
+ export declare function janusClient(text: string, config?: Config): string;
3
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../lib/client/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAa7C,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,GAAE,MAAsB,UASvE"}
@@ -1,4 +1,4 @@
1
- import { validateText, getTags, normalizeWhitespace, serialize, } from "./utils/index.js";
1
+ import { validateText, getTags, normalizeWhitespace, serialize, } from "../utils/index.js";
2
2
  const defaultConfig = {
3
3
  tagsToRemove: [],
4
4
  tagsToPreserve: [],
@@ -0,0 +1,10 @@
1
+ import type { Config } from "../utils/index.js";
2
+ type JanusClientStreamConfig = {
3
+ url: string;
4
+ config?: Config;
5
+ encoding?: BufferEncoding;
6
+ fetchOptions?: RequestInit;
7
+ };
8
+ export declare function janusClientStream({ url, config, encoding, fetchOptions, }: JanusClientStreamConfig): Promise<string>;
9
+ export {};
10
+ //# sourceMappingURL=stream.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../../lib/client/stream.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAEhD,KAAK,uBAAuB,GAAG;IAC7B,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,cAAc,CAAC;IAC1B,YAAY,CAAC,EAAE,WAAW,CAAC;CAC5B,CAAC;AAEF,wBAAsB,iBAAiB,CAAC,EACtC,GAAG,EACH,MAAM,EACN,QAAQ,EACR,YAAY,GACb,EAAE,uBAAuB,GAAG,OAAO,CAAC,MAAM,CAAC,CAS3C"}
@@ -0,0 +1,26 @@
1
+ import { janusClient } from "./client.js";
2
+ export async function janusClientStream({ url, config, encoding, fetchOptions, }) {
3
+ const response = await fetch(url, fetchOptions);
4
+ if (!response.ok || !response.body) {
5
+ throw new Error(`Failed downloading stream.\n====\nURL: ${url}\n====\n
6
+ Status:${response.status}`);
7
+ }
8
+ return await _janusClient(response.body, config, encoding);
9
+ }
10
+ async function _janusClient(inputStream, config, encoding = "utf8") {
11
+ const decodedStream = inputStream.pipeThrough(new TextDecoderStream(encoding));
12
+ const reader = decodedStream.getReader();
13
+ let text = "";
14
+ try {
15
+ while (true) {
16
+ const { done, value } = await reader.read();
17
+ if (done)
18
+ break;
19
+ text += value;
20
+ }
21
+ }
22
+ finally {
23
+ reader.releaseLock();
24
+ }
25
+ return janusClient(text, config);
26
+ }
@@ -1,3 +1,3 @@
1
- import type { Config } from "./utils/index";
1
+ import type { Config } from "../utils/index";
2
2
  export declare function janusServer(text: string, config?: Config): Promise<string>;
3
3
  //# sourceMappingURL=server.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../lib/server/server.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAa7C,wBAAsB,WAAW,CAC/B,IAAI,EAAE,MAAM,EACZ,MAAM,GAAE,MAAsB,mBAS/B"}
@@ -1,5 +1,5 @@
1
1
  import { parse } from "node-html-parser";
2
- import { validateText, getTags, normalizeWhitespace, serialize, } from "./utils/index.js";
2
+ import { validateText, getTags, normalizeWhitespace, serialize, } from "../utils/index.js";
3
3
  const defaultConfig = {
4
4
  tagsToRemove: [],
5
5
  tagsToPreserve: [],
@@ -0,0 +1,16 @@
1
+ import type { Config } from "../utils/index.js";
2
+ type ConfigOptions = {
3
+ encoding?: BufferEncoding;
4
+ fetchOptions?: RequestInit;
5
+ config?: Config;
6
+ };
7
+ type JanusFileConfig = Omit<ConfigOptions, "fetchOptions"> & {
8
+ filePath: string;
9
+ };
10
+ type JanusServerStreamConfig = ConfigOptions & {
11
+ url: string;
12
+ };
13
+ export declare function janusServerStream({ config, filePath, encoding, }: JanusFileConfig): Promise<string>;
14
+ export declare function janusServerStream({ url, encoding, fetchOptions, config, }: JanusServerStreamConfig): Promise<string>;
15
+ export {};
16
+ //# sourceMappingURL=stream.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../../lib/server/stream.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAEhD,KAAK,aAAa,GAAG;IACnB,QAAQ,CAAC,EAAE,cAAc,CAAC;IAC1B,YAAY,CAAC,EAAE,WAAW,CAAC;IAC3B,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AAMF,KAAK,eAAe,GAAG,IAAI,CAAC,aAAa,EAAE,cAAc,CAAC,GAAG;IAC3D,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AACF,KAAK,uBAAuB,GAAG,aAAa,GAAG;IAAE,GAAG,EAAE,MAAM,CAAA;CAAE,CAAC;AAE/D,wBAAsB,iBAAiB,CAAC,EACtC,MAAM,EACN,QAAQ,EACR,QAAQ,GACT,EAAE,eAAe,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;AACrC,wBAAsB,iBAAiB,CAAC,EACtC,GAAG,EACH,QAAQ,EACR,YAAY,EACZ,MAAM,GACP,EAAE,uBAAuB,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC"}
@@ -0,0 +1,32 @@
1
+ import { open } from "node:fs/promises";
2
+ import { Readable } from "node:stream";
3
+ import { buffer } from "node:stream/consumers";
4
+ export async function janusServerStream({ encoding = "utf8", filePath = "", fetchOptions = {}, config = {}, url = "", }) {
5
+ if (url.trim().length > 0) {
6
+ const response = await fetch(url, fetchOptions);
7
+ if (!response.ok || !response.body) {
8
+ throw new Error(`Failed downloading stream.\n====\nURL: ${url}\n====\n
9
+ Status:${response.status}`);
10
+ }
11
+ const webStream = Readable.from(response.body);
12
+ return await _janusServer(webStream, config, encoding);
13
+ }
14
+ let handle;
15
+ try {
16
+ handle = await open(filePath, "r"); // Read mode.
17
+ const file = handle.createReadStream();
18
+ return await _janusServer(file, config, encoding);
19
+ }
20
+ finally {
21
+ if (handle) {
22
+ await handle.close();
23
+ }
24
+ }
25
+ }
26
+ async function _janusServer(inputStream, config, encoding = "utf8") {
27
+ const bytesBuffer = await buffer(inputStream);
28
+ const decoder = new TextDecoder(encoding);
29
+ const text = decoder.decode(bytesBuffer);
30
+ const { janusServer } = await import("./server.js");
31
+ return await janusServer(text, config);
32
+ }
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "janus-parse",
3
3
  "license": "MIT",
4
- "version": "2.0.3",
5
- "packageManager": "pnpm@11.17.0",
4
+ "version": "2.1.1",
5
+ "packageManager": "pnpm@11.20.0",
6
6
  "keywords": [
7
7
  "html-parser",
8
8
  "text-extractor",
@@ -16,13 +16,25 @@
16
16
  "THIRD-PARTY-NOTICES.md"
17
17
  ],
18
18
  "exports": {
19
+ ".": {
20
+ "types": "./dist/client/client.d.js",
21
+ "import": "./dist/client/client.js"
22
+ },
23
+ "./server/stream": {
24
+ "types": "./dist/server/stream.d.ts",
25
+ "import": "./dist/server/stream.js"
26
+ },
27
+ "./client/stream": {
28
+ "types": "./dist/client/stream.d.ts",
29
+ "import": "./dist/client/stream.js"
30
+ },
19
31
  "./server": {
20
- "types": "./dist/server.d.ts",
21
- "import": "./dist/server.js"
32
+ "types": "./dist/server/server.d.ts",
33
+ "import": "./dist/server/server.js"
22
34
  },
23
35
  "./client": {
24
- "types": "./dist/client.d.ts",
25
- "import": "./dist/client.js"
36
+ "types": "./dist/client/client.d.ts",
37
+ "import": "./dist/client/client.js"
26
38
  }
27
39
  },
28
40
  "release": {
@@ -55,11 +67,13 @@
55
67
  "code:lint": "pnpm eslint --flag unstable_native_nodejs_ts_config --cache .",
56
68
  "fmt": "prettier --write .",
57
69
  "type:check": "tsc --noEmit",
58
- "build": "tsc",
59
- "prepublishOnly": "pnpm build"
70
+ "build": "rm -rf ./dist && tsc --project tsconfig.lib.json",
71
+ "build:lib": "tsc --project tsconfig.lib.json",
72
+ "prepublishOnly": "pnpm build",
73
+ "bundle:size": "tsx scripts/bundle-size.ts"
60
74
  },
61
75
  "dependencies": {
62
- "node-html-parser": "9.0.0"
76
+ "node-html-parser": "9.0.1"
63
77
  },
64
78
  "devDependencies": {
65
79
  "@eslint/js": "^10.0.1",
@@ -68,6 +82,7 @@
68
82
  "@semantic-release/npm": "^13.1.5",
69
83
  "@semantic-release/release-notes-generator": "^14.1.1",
70
84
  "@types/node": "^26.1.1",
85
+ "esbuild": "^0.28.1",
71
86
  "eslint": "^10.7.0",
72
87
  "eslint-import-resolver-typescript": "^4.4.5",
73
88
  "eslint-plugin-import-x": "^4.17.1",
package/dist/client.d.ts DELETED
@@ -1,3 +0,0 @@
1
- import type { Config } from "./utils/index";
2
- export declare function janusClient(text: string, config?: Config): string;
3
- //# sourceMappingURL=client.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../lib/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAa5C,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,GAAE,MAAsB,UASvE"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../lib/server.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAa5C,wBAAsB,WAAW,CAC/B,IAAI,EAAE,MAAM,EACZ,MAAM,GAAE,MAAsB,mBAS/B"}