janus-parse 2.3.0 → 2.4.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
@@ -14,7 +14,8 @@ Here is exactly what it handles:
14
14
 
15
15
  1. **Completely removes blocked tags**: If a tag is blacklisted (like `script` or `style`), it doesn't just empty the content, it deletes the entire element so no empty HTML tags are left behind in your final string.
16
16
  2. **Keeps specific HTML intact**: You can pass tags into `tagsToPreserve` (like `<code>` or `<iframe>`). It will keep their full HTML layout exactly as it is while stripping out generic structural tags like `<div>` or `<span>`.
17
- 3. **Cleans up messy whitespace**: It automatically strips out layout code indentations, tabs, and random line breaks, squashing them down into uniform, single spaces.
17
+ 3. **Preserves tags selectively by attribute**: Use `preserveTagsWithAttrs` with `tagsToPreserve` to retain only matching tags.
18
+ 4. **Cleans up messy whitespace**: It automatically strips out layout code indentations, tabs, and random line breaks, squashing them down into uniform, single spaces.
18
19
 
19
20
  > **Note on implementation**: While the underlying `node-html-parser` library is excellent at reading and building HTML trees, it doesn't handle this type of conditional tag removal, selective HTML preservation, or text formatting out of the box. `janus-parse` bridges that gap by adding this specific data-cleaning layer on top of the parser.
20
21
 
@@ -78,8 +79,7 @@ The `janusClient` function is synchronous. It ignores server node environments a
78
79
  ```typescript
79
80
  import { janusClient } from "janus-parse/client";
80
81
 
81
- const webMarkup =
82
- "<div> Dynamic Web App <style>body { display: none; }</style></div>";
82
+ const webMarkup = "<div> Dynamic Web App <style>body { display: none; }</style></div>";
83
83
 
84
84
  const textOnly = janusClient(webMarkup); // Output: " Dynamic Web App"
85
85
  ```
@@ -98,12 +98,16 @@ const cleanText = await janusClientStream({ url: "https://url.com" });
98
98
 
99
99
  #### `Config`
100
100
 
101
- Optionanl second function parameter to fine-tune tag removal behaviors.
101
+ Optional second function parameter to fine-tune tag removal and preservation behaviors.
102
102
 
103
103
  ```typescript
104
- type Config {
104
+ type Config = {
105
105
  tagsToRemove?: string[];
106
106
  tagsToPreserve?: string[];
107
+ preserveTagsWithAttrs?: string[];
108
+ replaceTagContents?: Record<string, string>;
109
+ replaceTagContentsWithAttrs?: string[];
110
+ replaceTagContentsAsHtml?: boolean;
107
111
  };
108
112
 
109
113
  type JanusClientStreamConfig = {
@@ -122,6 +126,46 @@ type JanusServerStreamConfig = {
122
126
  };
123
127
  ```
124
128
 
129
+ When `preserveTagsWithAttrs` is provided, a preserved tag is kept only if its attributes contain one of the specified strings; otherwise, the tag's markup is removed but its contents remain. Attribute matching ignores extra whitespace and treats single and double quotes as equivalent.
130
+
131
+ Use `replaceTagContents` to replace the contents of matching tag names. By default, every occurrence of those tag names is replaced; set `replaceTagContentsWithAttrs` to restrict replacement to elements whose attributes contain one of the specified strings. Replacement values are treated as plain text by default; set `replaceTagContentsAsHtml` to `true` to parse them as HTML.
132
+
133
+ All four APIs support these configuration options: `janusServer`, `janusClient`, `janusServerStream`, and `janusClientStream`.
134
+
135
+ For example, preserve only links with `data-keep="true"`:
136
+
137
+ ```typescript
138
+ const cleanText = await janusServer(
139
+ '<a href="/about">About</a> <a data-keep="true">Keep this link</a>',
140
+ {
141
+ tagsToPreserve: ["a"],
142
+ preserveTagsWithAttrs: ['data-keep="true"'],
143
+ },
144
+ );
145
+ // Output: 'About <a data-keep="true">Keep this link</a>'
146
+ ```
147
+
148
+ Replace the contents of `div` tags with `data-keep="true"`, leaving other `div` elements unchanged:
149
+
150
+ ```typescript
151
+ const cleanText = await janusServer("<div data-keep='true'>Original</div> <div>Keep this</div>", {
152
+ replaceTagContents: { div: "New content." },
153
+ replaceTagContentsWithAttrs: ["data-keep='true'"],
154
+ });
155
+ // Output: "New content. Keep this"
156
+ ```
157
+
158
+ For HTML replacement content, enable `replaceTagContentsAsHtml`:
159
+
160
+ ```typescript
161
+ const cleanText = await janusServer("<div data-keep='true'>Original <span>content.</span></div>", {
162
+ replaceTagContents: { div: "<strong>Updated</strong>" },
163
+ replaceTagContentsAsHtml: true,
164
+ tagsToPreserve: ["strong"],
165
+ });
166
+ // Output: <strong>Updated</strong> content.
167
+ ```
168
+
125
169
  ---
126
170
 
127
171
  - `rawHtml`: The input HTML string.
package/package.json CHANGED
@@ -1,20 +1,28 @@
1
1
  {
2
2
  "name": "janus-parse",
3
- "license": "MIT",
4
- "version": "2.3.0",
5
- "packageManager": "pnpm@12.18.0",
3
+ "version": "2.4.0",
6
4
  "keywords": [
5
+ "clean-text",
7
6
  "html-parser",
8
- "text-extractor",
9
- "html-to-text",
10
7
  "html-sanitizer",
11
- "clean-text",
12
- "strip-tags"
8
+ "html-to-text",
9
+ "strip-tags",
10
+ "text-extractor"
13
11
  ],
12
+ "homepage": "https://github.com/Casneil/janus-parse",
13
+ "bugs": {
14
+ "url": "https://github.com/Casneil/janus-parse/issues"
15
+ },
16
+ "license": "MIT",
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "https://github.com/Casneil/janus-parse"
20
+ },
14
21
  "files": [
15
22
  "dist",
16
23
  "THIRD-PARTY-NOTICES.md"
17
24
  ],
25
+ "type": "module",
18
26
  "exports": {
19
27
  ".": {
20
28
  "types": "./dist/client/client.d.js",
@@ -37,64 +45,48 @@
37
45
  "import": "./dist/client/client.js"
38
46
  }
39
47
  },
40
- "release": {
41
- "branches": [
42
- "main"
43
- ],
44
- "plugins": [
45
- "@semantic-release/commit-analyzer",
46
- "@semantic-release/release-notes-generator",
47
- "@semantic-release/npm",
48
- "@semantic-release/github"
49
- ]
50
- },
51
- "repository": {
52
- "type": "git",
53
- "url": "https://github.com/Casneil/janus-parse"
54
- },
55
- "homepage": "https://github.com/Casneil/janus-parse",
56
- "bugs": {
57
- "url": "https://github.com/Casneil/janus-parse/issues"
58
- },
59
48
  "publishConfig": {
60
49
  "registry": "https://registry.npmjs.org"
61
50
  },
62
- "type": "module",
63
- "prepack": "pnpm build",
64
51
  "scripts": {
65
- "janus": "tsx ./lib/server.ts",
66
52
  "test": "vitest",
67
- "code:lint": "pnpm eslint --flag unstable_native_nodejs_ts_config --cache .",
68
- "fmt": "prettier --write .",
53
+ "lint:fix": "oxlint --fix",
54
+ "fmt": "oxfmt",
55
+ "fmt:check": "oxfmt --check",
69
56
  "type:check": "tsc --noEmit",
70
57
  "build": "rm -rf ./dist && tsc --project tsconfig.lib.json",
71
58
  "build:lib": "tsc --project tsconfig.lib.json",
72
59
  "prepublishOnly": "pnpm build",
73
- "bundle:size": "tsx scripts/bundle-size.ts"
60
+ "bundle:size": "node ./scripts/bundle-size.ts"
74
61
  },
75
62
  "dependencies": {
76
- "node-html-parser": "9.0.7"
63
+ "node-html-parser": "9.0.10"
77
64
  },
78
65
  "devDependencies": {
79
- "@eslint/js": "^10.0.1",
80
- "@semantic-release/commit-analyzer": "^13.0.1",
66
+ "@semantic-release/commit-analyzer": "13.0.1",
81
67
  "@semantic-release/github": "12.0.11",
82
68
  "@semantic-release/npm": "13.2.0",
83
- "@semantic-release/release-notes-generator": "^14.1.1",
84
- "@types/node": "26.6.6",
85
- "eslint": "10.15.0",
69
+ "@semantic-release/release-notes-generator": "14.1.1",
70
+ "@types/node": "26.6.11",
86
71
  "esbuild": "^0.28.2",
87
- "eslint-import-resolver-typescript": "^4.4.5",
88
- "eslint-plugin-import-x": "^4.17.1",
89
72
  "happy-dom": "21.0.4",
90
- "eslint-plugin-unicorn": "79.0.0",
91
- "prettier": "3.9.10",
92
- "semantic-release": "^25.0.8",
93
- "tsx": "4.23.15",
94
- "typescript": "6.0.3",
95
- "typescript-eslint": "8.72.1",
96
- "vitest": "5.1.0"
73
+ "oxfmt": "0.81.0",
74
+ "oxlint": "1.96.0",
75
+ "semantic-release": "26.0.1",
76
+ "typescript": "7.0.2",
77
+ "vitest": "5.1.2"
78
+ },
79
+ "release": {
80
+ "branches": [
81
+ "main"
82
+ ],
83
+ "plugins": [
84
+ "@semantic-release/commit-analyzer",
85
+ "@semantic-release/release-notes-generator",
86
+ "@semantic-release/npm",
87
+ "@semantic-release/github"
88
+ ]
97
89
  },
98
- "prettier": {},
99
- "--Typescript V 7--": "cannot use TS v7 until typescript-eslint adds support"
90
+ "packageManager": "pnpm@12.26.0",
91
+ "prepack": "pnpm build"
100
92
  }
@@ -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/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAa7C,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,GAAE,MAAsB,UAcvE"}
@@ -1,17 +0,0 @@
1
- import { validateText, getTags, normalizeWhitespace, serialize, } from "../utils/index.js";
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, preserveTagsWithAttrs } = getTags(config);
10
- const root = parser.parseFromString(text, "text/html").body;
11
- return normalizeWhitespace(serialize({
12
- node: root,
13
- removedTags,
14
- preservedTags,
15
- preserveTagsWithAttrs,
16
- }));
17
- }
@@ -1,10 +0,0 @@
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
@@ -1 +0,0 @@
1
- {"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../../lib/client/stream.ts"],"names":[],"mappings":"AAAA,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"}
@@ -1,26 +0,0 @@
1
- export async function janusClientStream({ url, config, encoding, fetchOptions, }) {
2
- const response = await fetch(url, fetchOptions);
3
- if (!response.ok || !response.body) {
4
- throw new Error(`Failed downloading stream.\n====\nURL: ${url}\n====\n
5
- Status:${response.status}`);
6
- }
7
- return await _janusClient(response.body, config, encoding);
8
- }
9
- async function _janusClient(inputStream, config, encoding = "utf8") {
10
- const decodedStream = inputStream.pipeThrough(new TextDecoderStream(encoding));
11
- const reader = decodedStream.getReader();
12
- let text = "";
13
- try {
14
- while (true) {
15
- const { done, value } = await reader.read();
16
- if (done)
17
- break;
18
- text += value;
19
- }
20
- }
21
- finally {
22
- reader.releaseLock();
23
- }
24
- const { janusClient } = await import("./client.js");
25
- return janusClient(text, config);
26
- }
@@ -1,3 +0,0 @@
1
- import type { Config } from "../utils/index";
2
- export declare function janusServer(text: string, config?: Config): Promise<string>;
3
- //# sourceMappingURL=server.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../lib/server/server.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAc7C,wBAAsB,WAAW,CAC/B,IAAI,EAAE,MAAM,EACZ,MAAM,GAAE,MAAsB,mBAc/B"}
@@ -1,18 +0,0 @@
1
- import { validateText, getTags, normalizeWhitespace, serialize, } from "../utils/index.js";
2
- const defaultConfig = {
3
- tagsToRemove: [],
4
- tagsToPreserve: [],
5
- preserveTagsWithAttrs: [],
6
- };
7
- export async function janusServer(text, config = defaultConfig) {
8
- validateText(text);
9
- const { parse } = await import("node-html-parser");
10
- const root = parse(text);
11
- const { removedTags, preservedTags, preserveTagsWithAttrs } = getTags(config);
12
- return normalizeWhitespace(serialize({
13
- node: root,
14
- removedTags,
15
- preservedTags,
16
- preserveTagsWithAttrs,
17
- }));
18
- }
@@ -1,16 +0,0 @@
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
@@ -1 +0,0 @@
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"}
@@ -1,32 +0,0 @@
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
- }
@@ -1,23 +0,0 @@
1
- import type { HTMLElement as NodeHTMLElement } from "node-html-parser";
2
- export type Config = {
3
- tagsToRemove?: string[];
4
- tagsToPreserve?: string[];
5
- preserveTagsWithAttrs?: string[];
6
- };
7
- export declare function validateText(text: string): void;
8
- export declare function normalizeWhitespace(text?: string): string;
9
- export declare function getTags(config: Config): {
10
- removedTags: Set<string>;
11
- preservedTags: Set<string>;
12
- preserveTagsWithAttrs: Set<string>;
13
- };
14
- type SerializableNode = NodeHTMLElement | HTMLElement;
15
- type SerializeParameters = {
16
- node: SerializableNode;
17
- removedTags: Set<string>;
18
- preservedTags: Set<string>;
19
- preserveTagsWithAttrs?: Set<string>;
20
- };
21
- export declare function serialize({ node, removedTags, preservedTags, preserveTagsWithAttrs, }: SerializeParameters): string;
22
- export {};
23
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
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,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;IAC1B,qBAAqB,CAAC,EAAE,MAAM,EAAE,CAAC;CAClC,CAAC;AAIF,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,QAOxC;AAED,wBAAgB,mBAAmB,CAAC,IAAI,SAAK,UAE5C;AAED,wBAAgB,OAAO,CAAC,MAAM,EAAE,MAAM;;;;EAwBrC;AACD,KAAK,gBAAgB,GAAG,eAAe,GAAG,WAAW,CAAC;AAEtD,KAAK,mBAAmB,GAAG;IACzB,IAAI,EAAE,gBAAgB,CAAC;IACvB,WAAW,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IACzB,aAAa,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IAC3B,qBAAqB,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;CACrC,CAAC;AACF,wBAAgB,SAAS,CAAC,EACxB,IAAI,EACJ,WAAW,EACX,aAAa,EACb,qBAAqB,GACtB,EAAE,mBAAmB,GAAG,MAAM,CAiD9B"}
@@ -1,101 +0,0 @@
1
- const defaultBlacklistTags = new Set(["script", "style"]);
2
- export function validateText(text) {
3
- if (typeof text !== "string") {
4
- throw new TypeError(`\n======================================================\n=> ${text} recieved. String expected.\n======================================================`, { cause: `${text} is not of type string.` });
5
- }
6
- }
7
- export function normalizeWhitespace(text = "") {
8
- return text.replace(new RegExp(String.raw `\s+`, "g"), " ").trim();
9
- }
10
- export function getTags(config) {
11
- const removedTags = new Set(defaultBlacklistTags);
12
- const preservedTags = new Set();
13
- const preserveTagsWithAttributes = new Set(config.preserveTagsWithAttrs);
14
- if (config.tagsToRemove) {
15
- addBlackListTags(removedTags, config.tagsToRemove);
16
- }
17
- if (config.tagsToPreserve) {
18
- removeBlackListTags({
19
- removedTags,
20
- preservedTags,
21
- tagsToPreserve: config.tagsToPreserve,
22
- });
23
- }
24
- return {
25
- removedTags,
26
- preservedTags,
27
- preserveTagsWithAttrs: preserveTagsWithAttributes,
28
- };
29
- }
30
- export function serialize({ node, removedTags, preservedTags, preserveTagsWithAttrs, }) {
31
- if (!node)
32
- return "";
33
- if (node.nodeType === 3) {
34
- // DOM Text node => 3
35
- const rawText = getNodeProperty(node, "rawText");
36
- const text = getNodeProperty(node, "text");
37
- return rawText ?? text ?? node.textContent ?? "";
38
- }
39
- const tagName = getNodeProperty(node, "tagName") ?? "";
40
- const tag = tagName.toLowerCase();
41
- // Completely ignore blacklisted tags
42
- if (removedTags.has(tag))
43
- return "";
44
- const children = [...node.childNodes];
45
- function serializeChildren() {
46
- return children
47
- .map((child) => serialize({
48
- node: child,
49
- removedTags,
50
- preservedTags,
51
- preserveTagsWithAttrs,
52
- }))
53
- .join("");
54
- }
55
- if (preservedTags.has(tag)) {
56
- if (preserveTagsWithAttrs &&
57
- preserveTagsWithAttrs.size > 0 &&
58
- !hasPreservedAttribute(node, preserveTagsWithAttrs)) {
59
- return serializeChildren();
60
- }
61
- const outerHTML = getNodeProperty(node, "outerHTML");
62
- return (outerHTML ??
63
- (typeof String(node) === "function" ? String(node) : undefined) ??
64
- "");
65
- }
66
- return serializeChildren();
67
- }
68
- function sanitizeAttribute(attribute) {
69
- return attribute.replace(/\s+/g, " ").replace(/'/g, '"').trim();
70
- }
71
- function hasPreservedAttribute(node, preserveTagsWithAttributes) {
72
- const nodeType = "nodeType" in node ? node.nodeType : undefined;
73
- const rawAttributes = "rawAttrs" in node
74
- ? (node.rawAttrs ?? "")
75
- : (nodeType === 1
76
- ? [...node.attributes]
77
- .map(({ name, value }) => `${name}="${value}"`)
78
- .join(" ")
79
- : "");
80
- const normalizedAttributes = sanitizeAttribute(rawAttributes);
81
- return (rawAttributes &&
82
- [...preserveTagsWithAttributes].some((attribute) => Boolean(attribute.trim()) &&
83
- normalizedAttributes.includes(sanitizeAttribute(attribute))));
84
- }
85
- function removeBlackListTags({ removedTags, preservedTags, tagsToPreserve, }) {
86
- for (const tag of tagsToPreserve) {
87
- const normalized = tag.toLowerCase();
88
- removedTags.delete(normalized);
89
- preservedTags.add(normalized);
90
- }
91
- }
92
- function addBlackListTags(preserveTags, tagsToRemove) {
93
- for (const tag of tagsToRemove) {
94
- preserveTags.add(tag.toLowerCase());
95
- }
96
- }
97
- function getNodeProperty(node, lookup = "outerHTML") {
98
- const targetNode = node;
99
- const value = targetNode[lookup];
100
- return value ?? undefined;
101
- }