janus-parse 1.0.0 → 1.0.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.
Files changed (2) hide show
  1. package/README.md +149 -0
  2. package/package.json +1 -1
package/README.md ADDED
@@ -0,0 +1,149 @@
1
+ # janus-parse
2
+
3
+ [![npm version](https://shields.io)](https://npmjs.com)
4
+ [![License: MIT](https://shields.io)](https://opensource.org)
5
+
6
+ A lightweight, high-performance, isomorphic HTML text extractor and sanitizer built entirely in TypeScript. It safely strips out targeted layout elements or malicious scripts and returns clean, whitespace-normalized text.
7
+
8
+ `janus-parse` provides dedicated entry points optimized for both Node.js environments and client-side browsers, ensuring minimal browser bundle overhead.
9
+
10
+ ---
11
+
12
+ ## Features
13
+
14
+ - **Isomorphic Architecture:** Native support for both Node.js servers and Web Browsers.
15
+ - **Smart Tree Shaking:** Heavy server-side dependencies are dynamically imported, keeping your browser footprint tiny.
16
+ - **Strict Validation:** Automatically ensures inputs are safe and structurally sound before parsing.
17
+ - **Built-in TypeScript Types:** Ship code confidently with full type safety and explicit configuration interfaces.
18
+
19
+ ---
20
+
21
+ ## Installation
22
+
23
+ Install the package via your favorite package manager:
24
+
25
+ ```bash
26
+ # Using pnpm
27
+ pnpm install janus-parse
28
+
29
+ # Using npm
30
+ npm install janus-parse
31
+
32
+ # Using yarn
33
+ yarn install janus-parse
34
+ ```
35
+
36
+ ---
37
+
38
+ ## Usage
39
+
40
+ ### 1. Server-Side Execution (Node.js)
41
+
42
+ The `janusServer` function is asynchronous. It dynamically imports [node-html-parser](https://www.npmjs.com/package/node-html-parser) to handle complex document object trees smoothly on the backend.
43
+
44
+ ```typescript
45
+ import { janusServer } from "janus-parse";
46
+
47
+ const rawHtml = `
48
+ <main>
49
+ <h1>Hello Universe</h1>
50
+ <script type="text/javascript">alert('unwanted execution')</script>
51
+ <p>This is a highly spaced sentence.</p>
52
+ </main>
53
+ `;
54
+
55
+ const cleanText = await janusServer(rawHtml);
56
+ console.log(cleanText);
57
+ // Output: "Hello Universe This is a highly spaced sentence."
58
+ ```
59
+
60
+ ### 2. Client-Side Execution (Browser)
61
+
62
+ The `janusClient` function is synchronous. It ignores server node environments and hooks directly into the browser's native, hardware-optimized `DOMParser` engine.
63
+
64
+ ```typescript
65
+ import { janusClient } from "janus-parse";
66
+
67
+ const webMarkup =
68
+ "<div> Dynamic Web App <style>body { display: none; }</style></div>";
69
+
70
+ const textOnly = janusClient(webMarkup);
71
+ console.log(textOnly);
72
+ // Output: " Dynamic Web App"
73
+ ```
74
+
75
+ ### 3. Custom Configurations
76
+
77
+ You can modify which HTML tags are targeted for destruction by passing an optional configuration object.
78
+
79
+ ```typescript
80
+ const structuralConfig = {
81
+ addBlacklistTags: ["span", "section"], // Purge extra elements
82
+ removeBlacklistTags: ["script"], // Keep scripts if you are building an isolated sandbox
83
+ };
84
+ ```
85
+
86
+ ```typescript
87
+ import { janusServer } from "janus-parse";
88
+
89
+ const processedTextServer = await janusServer(htmlSource, structuralConfig);
90
+ ```
91
+
92
+ ```typescript
93
+ import { janusClient } from 'janus-parse';
94
+
95
+ const processedTextClient = janusClienthtmlSource, structuralConfig);
96
+ ```
97
+
98
+ ---
99
+
100
+ ## API Reference
101
+
102
+ ### `Config`
103
+
104
+ TypeScript interface passed to fine-tune tag removal behaviors.
105
+
106
+ ```typescript
107
+ interface Config {
108
+ addBlacklistTags?: string[];
109
+ removeBlacklistTags?: string[];
110
+ }
111
+ ```
112
+
113
+ ### `janusServer(text: string, config?: Config): Promise<string>`
114
+
115
+ - **`text`**: The input raw HTML string.
116
+ - **`config`**: Optional rule blocks to override standard cleaning lists.
117
+ - **Returns**: A promise that resolves to a stripped, whitespace-normalized single-line string.
118
+
119
+ ### `janusClient(text: string, config?: Config): string`
120
+
121
+ - **`text`**: The input raw HTML string.
122
+ - **`config`**: Optional rule blocks to override standard cleaning lists.
123
+ - **Returns**: A clean string containing target inner-text nodes parsed from the browser context.
124
+
125
+ ---
126
+
127
+ ## Development & Testing
128
+
129
+ If you want to contribute or modify this package, pull down the code and use the built-in development workflows:
130
+
131
+ ```bash
132
+ # Install dependencies
133
+ pnpm install
134
+
135
+ # Run the test suite via Vitest
136
+ pnpm test
137
+
138
+ # Check or fix formatting rules
139
+ pnpm fmt
140
+
141
+ # Compile the TypeScript project into the 'dist/' folder
142
+ pnpm build
143
+ ```
144
+
145
+ ---
146
+
147
+ ## License
148
+
149
+ Distributed under the MIT License. See [LICENSE](LICENSE) for more information.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "janus-parse",
3
3
  "license": "MIT",
4
- "version": "1.0.0",
4
+ "version": "1.0.1",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
7
7
  "files": [