janus-parse 1.0.3 → 1.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
@@ -1,4 +1,4 @@
1
- # janus-parse
1
+ # janus-parse [![npm version](https://img.shields.io/npm/v/janus-parse?style=flat-round)](https://www.npmjs.com/package/janus-parse) ![language](https://img.shields.io/badge/Language-Typescript-blue?style=flat-round) [![release](https://github.com/Casneil/janus-parse/actions/workflows/publish.yml/badge.svg)](https://github.com/Casneil/janus-parse/actions/workflows/publish.yml) [![build](https://github.com/Casneil/janus-parse/actions/workflows/build.yml/badge.svg)](https://github.com/Casneil/janus-parse/actions/workflows/build.yml)
2
2
 
3
3
  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.
4
4
 
package/dist/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export * from "./janus-parse.js";
1
+ export * from "./janus-parse";
2
2
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC"}
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- export * from "./janus-parse.js";
1
+ export * from "./janus-parse";
@@ -1,4 +1,4 @@
1
- import { Config } from "./utils/index.js";
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 | null;
3
+ export declare function janusClient(text: string, config?: Config): string;
4
4
  //# sourceMappingURL=janus-parse.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"janus-parse.d.ts","sourceRoot":"","sources":["../lib/janus-parse.ts"],"names":[],"mappings":"AAAA,OAAO,EAA6B,MAAM,EAAW,MAAM,kBAAkB,CAAC;AAO9E,wBAAsB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,GAAE,MAAoB,mBAU3E;AAED,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,GAAE,MAAoB,iBAYrE"}
1
+ {"version":3,"file":"janus-parse.d.ts","sourceRoot":"","sources":["../lib/janus-parse.ts"],"names":[],"mappings":"AAMA,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,UAUrE"}
@@ -1,4 +1,4 @@
1
- import { validateText, removeNodes, getTags } from "./utils/index.js";
1
+ import { validateText, removeNodes, getTags, normalizeWhitespace, } from "./utils";
2
2
  const janusConfig = {
3
3
  addBlacklistTags: [],
4
4
  removeBlacklistTags: [],
@@ -9,17 +9,15 @@ export async function janusServer(text, config = janusConfig) {
9
9
  const parser = await import("node-html-parser");
10
10
  const root = parser.parse(text);
11
11
  const nodesToRemove = root.querySelectorAll(tags);
12
- // @ts-expect-error
13
12
  removeNodes(nodesToRemove);
14
- return root.textContent.replace(new RegExp("\\s+", "g"), " ").trim();
13
+ return normalizeWhitespace(root.textContent);
15
14
  }
16
15
  export function janusClient(text, config = janusConfig) {
17
16
  validateText(text);
18
17
  const tags = getTags(config);
19
18
  const parser = new DOMParser();
20
- const virtualDoc = parser.parseFromString(text, "text/html");
21
- const nodesToRemove = virtualDoc.querySelectorAll(tags);
19
+ const virtualDocument = parser.parseFromString(text, "text/html");
20
+ const nodesToRemove = virtualDocument.querySelectorAll(tags);
22
21
  removeNodes(nodesToRemove);
23
- const cleanText = virtualDoc.body.textContent;
24
- return cleanText;
22
+ return normalizeWhitespace(virtualDocument.body.textContent);
25
23
  }
@@ -1,8 +1,10 @@
1
+ import type { HTMLElement as NodeHTMLElement } from "node-html-parser";
1
2
  export type Config = {
2
3
  addBlacklistTags?: string[];
3
4
  removeBlacklistTags?: string[];
4
5
  };
5
6
  export declare function validateText(text: string): void;
7
+ export declare function normalizeWhitespace(text?: string): string;
6
8
  export declare function getTags(config: Config): string;
7
- export declare function removeNodes(nodesToRemove: HTMLElement[] | NodeListOf<Element>): NodeListOf<Element> | HTMLElement[];
9
+ export declare function removeNodes(nodesToRemove: NodeHTMLElement[] | NodeListOf<Element>): NodeListOf<Element> | NodeHTMLElement[];
8
10
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../lib/utils/index.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,MAAM,GAAG;IACnB,gBAAgB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC5B,mBAAmB,CAAC,EAAE,MAAM,EAAE,CAAC;CAChC,CAAC;AAIF,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,QAUxC;AAED,wBAAgB,OAAO,CAAC,MAAM,EAAE,MAAM,UAWrC;AAED,wBAAgB,WAAW,CACzB,aAAa,EAAE,WAAW,EAAE,GAAG,UAAU,CAAC,OAAO,CAAC,uCAOnD"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../lib/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,IAAI,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAEvE,MAAM,MAAM,MAAM,GAAG;IACnB,gBAAgB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC5B,mBAAmB,CAAC,EAAE,MAAM,EAAE,CAAC;CAChC,CAAC;AAIF,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,QAUxC;AAED,wBAAgB,mBAAmB,CAAC,IAAI,SAAK,UAE5C;AAED,wBAAgB,OAAO,CAAC,MAAM,EAAE,MAAM,UAWrC;AAED,wBAAgB,WAAW,CACzB,aAAa,EAAE,eAAe,EAAE,GAAG,UAAU,CAAC,OAAO,CAAC,2CAOvD"}
@@ -5,6 +5,9 @@ export function validateText(text) {
5
5
  throw new Error("The text is not a valid string. Please provide a valid string to parse.", { cause: text });
6
6
  }
7
7
  }
8
+ export function normalizeWhitespace(text = "") {
9
+ return text.replace(new RegExp(String.raw `\s+`, "g"), " ").trim();
10
+ }
8
11
  export function getTags(config) {
9
12
  let tags = new Set();
10
13
  if (config.addBlacklistTags) {
package/package.json CHANGED
@@ -1,9 +1,10 @@
1
1
  {
2
2
  "name": "janus-parse",
3
3
  "license": "MIT",
4
- "version": "1.0.3",
4
+ "version": "1.1.1",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
7
+ "packageManager": "pnpm@11.15.1",
7
8
  "keywords": [
8
9
  "html-parser",
9
10
  "text-extractor",
@@ -19,6 +20,17 @@
19
20
  "files": [
20
21
  "dist"
21
22
  ],
23
+ "release": {
24
+ "branches": [
25
+ "main"
26
+ ],
27
+ "plugins": [
28
+ "@semantic-release/commit-analyzer",
29
+ "@semantic-release/release-notes-generator",
30
+ "@semantic-release/npm",
31
+ "@semantic-release/github"
32
+ ]
33
+ },
22
34
  "repository": {
23
35
  "type": "git",
24
36
  "url": "https://github.com/Casneil/janus-parse"
@@ -27,25 +39,42 @@
27
39
  "bugs": {
28
40
  "url": "https://github.com/Casneil/janus-parse/issues"
29
41
  },
42
+ "publishConfig": {
43
+ "registry": "https://registry.npmjs.org"
44
+ },
30
45
  "type": "module",
31
46
  "prepack": "pnpm build",
47
+ "scripts": {
48
+ "janus": "tsx ./lib",
49
+ "test": "vitest",
50
+ "code:lint": "pnpm eslint --flag unstable_native_nodejs_ts_config --cache .",
51
+ "fmt": "prettier --write .",
52
+ "type:check": "tsc --noEmit",
53
+ "build": "tsc",
54
+ "prepublishOnly": "pnpm build"
55
+ },
32
56
  "dependencies": {
33
57
  "node-html-parser": "9.0.0"
34
58
  },
35
59
  "devDependencies": {
60
+ "@eslint/js": "^10.0.1",
61
+ "@semantic-release/commit-analyzer": "^13.0.1",
62
+ "@semantic-release/github": "^12.0.9",
63
+ "@semantic-release/npm": "^13.1.5",
64
+ "@semantic-release/release-notes-generator": "^14.1.1",
36
65
  "@types/node": "^26.1.1",
37
66
  "eslint": "^10.7.0",
67
+ "eslint-import-resolver-typescript": "^4.4.5",
68
+ "eslint-plugin-import-x": "^4.17.1",
69
+ "eslint-plugin-unicorn": "^72.0.0",
38
70
  "happy-dom": "^20.11.0",
39
71
  "prettier": "^3.9.5",
72
+ "semantic-release": "^25.0.8",
40
73
  "tsx": "4.23.1",
41
- "typescript": "5.7.2",
74
+ "typescript": "6.0.3",
75
+ "typescript-eslint": "^8.65.0",
42
76
  "vitest": "^4.1.10"
43
77
  },
44
78
  "prettier": {},
45
- "scripts": {
46
- "janus": "tsx ./lib/index.ts",
47
- "test": "vitest",
48
- "fmt": "prettier --write .",
49
- "build": "tsc"
50
- }
51
- }
79
+ "--Typescript V 7--": "cannot use TS v7 until typescript-eslint adds support"
80
+ }