janus-parse 1.2.2 → 2.0.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/README.md CHANGED
@@ -39,7 +39,7 @@ yarn install janus-parse
39
39
  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.
40
40
 
41
41
  ```typescript
42
- import { janusServer } from "janus-parse";
42
+ import { janusServer } from "janus-parse/server";
43
43
 
44
44
  const rawHtml = `
45
45
  <main>
@@ -57,7 +57,7 @@ const cleanText = await janusServer(rawHtml); // Output: "Hello Universe This is
57
57
  The `janusClient` function is synchronous. It ignores server node environments and hooks directly into the browser's native, hardware-optimized `DOMParser` engine.
58
58
 
59
59
  ```typescript
60
- import { janusClient } from "janus-parse";
60
+ import { janusClient } from "janus-parse/client";
61
61
 
62
62
  const webMarkup =
63
63
  "<div> Dynamic Web App <style>body { display: none; }</style></div>";
@@ -0,0 +1,3 @@
1
+ import type { Config } from "./utils";
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.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAOtC,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,GAAE,MAAsB,UASvE"}
package/dist/client.js ADDED
@@ -0,0 +1,12 @@
1
+ import { validateText, getTags, normalizeWhitespace, serialize } from "./utils";
2
+ const defaultConfig = {
3
+ tagsToRemove: [],
4
+ tagsToPreserve: [],
5
+ };
6
+ export function janusClient(text, config = defaultConfig) {
7
+ validateText(text);
8
+ const parser = new DOMParser();
9
+ const { removedTags, preservedTags } = getTags(config);
10
+ const root = parser.parseFromString(text, "text/html").body;
11
+ return normalizeWhitespace(serialize({ node: root, removedTags, preservedTags }));
12
+ }
@@ -1,4 +1,3 @@
1
1
  import type { Config } from "./utils";
2
2
  export declare function janusServer(text: string, config?: Config): Promise<string>;
3
- export declare function janusClient(text: string, config?: Config): string;
4
- //# sourceMappingURL=janus-parse.d.ts.map
3
+ //# sourceMappingURL=server.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../lib/server.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAOtC,wBAAsB,WAAW,CAC/B,IAAI,EAAE,MAAM,EACZ,MAAM,GAAE,MAAsB,mBAS/B"}
package/dist/server.js ADDED
@@ -0,0 +1,12 @@
1
+ import { parse } from "node-html-parser";
2
+ import { validateText, getTags, normalizeWhitespace, serialize } from "./utils";
3
+ const defaultConfig = {
4
+ tagsToRemove: [],
5
+ tagsToPreserve: [],
6
+ };
7
+ export async function janusServer(text, config = defaultConfig) {
8
+ validateText(text);
9
+ const root = parse(text);
10
+ const { removedTags, preservedTags } = getTags(config);
11
+ return normalizeWhitespace(serialize({ node: root, removedTags, preservedTags }));
12
+ }
package/package.json CHANGED
@@ -1,26 +1,30 @@
1
1
  {
2
2
  "name": "janus-parse",
3
3
  "license": "MIT",
4
- "version": "1.2.2",
5
- "main": "./dist/index.js",
6
- "types": "./dist/index.d.ts",
4
+ "version": "2.0.0",
7
5
  "packageManager": "pnpm@11.15.1",
8
6
  "keywords": [
9
7
  "html-parser",
10
8
  "text-extractor",
11
9
  "html-to-text",
12
10
  "html-sanitizer",
13
- "isomorphic",
14
- "typescript",
15
- "dom-parser",
16
11
  "clean-text",
17
- "strip-tags",
18
- "node-html-parser"
12
+ "strip-tags"
19
13
  ],
20
14
  "files": [
21
15
  "dist",
22
16
  "THIRD-PARTY-NOTICES.md"
23
17
  ],
18
+ "exports": {
19
+ "./server": {
20
+ "types": "./dist/server.d.ts",
21
+ "default": "./dist/server.js"
22
+ },
23
+ "./client": {
24
+ "types": "./dist/client.d.ts",
25
+ "default": "./dist/client.js"
26
+ }
27
+ },
24
28
  "release": {
25
29
  "branches": [
26
30
  "main"
@@ -46,7 +50,7 @@
46
50
  "type": "module",
47
51
  "prepack": "pnpm build",
48
52
  "scripts": {
49
- "janus": "tsx ./lib",
53
+ "janus": "tsx ./lib/server.ts",
50
54
  "test": "vitest",
51
55
  "code:lint": "pnpm eslint --flag unstable_native_nodejs_ts_config --cache .",
52
56
  "fmt": "prettier --write .",
package/dist/index.d.ts DELETED
@@ -1,2 +0,0 @@
1
- export * from "./janus-parse";
2
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC"}
package/dist/index.js DELETED
@@ -1 +0,0 @@
1
- export * from "./janus-parse";
@@ -1 +0,0 @@
1
- {"version":3,"file":"janus-parse.d.ts","sourceRoot":"","sources":["../lib/janus-parse.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAOtC,wBAAsB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,GAAE,MAAoB,mBAS3E;AAED,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,GAAE,MAAoB,UASrE"}
@@ -1,19 +0,0 @@
1
- import { validateText, getTags, normalizeWhitespace, serialize } from "./utils";
2
- const janusConfig = {
3
- tagsToRemove: [],
4
- tagsToPreserve: [],
5
- };
6
- export async function janusServer(text, config = janusConfig) {
7
- validateText(text);
8
- const parser = await import("node-html-parser");
9
- const root = parser.parse(text);
10
- const { removedTags, preservedTags } = getTags(config);
11
- return normalizeWhitespace(serialize({ node: root, removedTags, preservedTags }));
12
- }
13
- export function janusClient(text, config = janusConfig) {
14
- validateText(text);
15
- const parser = new DOMParser();
16
- const { removedTags, preservedTags } = getTags(config);
17
- const root = parser.parseFromString(text, "text/html").body;
18
- return normalizeWhitespace(serialize({ node: root, removedTags, preservedTags }));
19
- }