ublo-lib 1.9.11 → 1.9.12
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.
|
@@ -1,3 +1,5 @@
|
|
|
1
|
-
export declare
|
|
2
|
-
export declare
|
|
1
|
+
export declare function extractElementsFromHtmlString(htmlString: string, selectors: string): Element[];
|
|
2
|
+
export declare function extractElementFromHtmlString(htmlString: string, selector: string): Element;
|
|
3
|
+
export declare function extractTextFromHtmlString(htmlString: string): string;
|
|
4
|
+
export declare function sanitizeHTML(html: string): string | null;
|
|
3
5
|
//# sourceMappingURL=elements.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"elements.d.ts","sourceRoot":"","sources":["../../../src/common/utils/elements.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"elements.d.ts","sourceRoot":"","sources":["../../../src/common/utils/elements.ts"],"names":[],"mappings":"AAAA,wBAAgB,6BAA6B,CAC3C,UAAU,EAAE,MAAM,EAClB,SAAS,EAAE,MAAM,aAMlB;AAED,wBAAgB,4BAA4B,CAC1C,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,MAAM,WAIjB;AAED,wBAAgB,yBAAyB,CAAC,UAAU,EAAE,MAAM,UAK3D;AAED,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,iBAIxC"}
|
|
@@ -1,10 +1,22 @@
|
|
|
1
|
-
export
|
|
1
|
+
export function extractElementsFromHtmlString(htmlString, selectors) {
|
|
2
2
|
const parser = new DOMParser();
|
|
3
3
|
const html = parser.parseFromString(htmlString, "text/html");
|
|
4
4
|
const element = Array.from(html.querySelectorAll(selectors));
|
|
5
5
|
return element;
|
|
6
|
-
}
|
|
7
|
-
export
|
|
6
|
+
}
|
|
7
|
+
export function extractElementFromHtmlString(htmlString, selector) {
|
|
8
8
|
const [element] = extractElementsFromHtmlString(htmlString, selector);
|
|
9
9
|
return element;
|
|
10
|
-
}
|
|
10
|
+
}
|
|
11
|
+
export function extractTextFromHtmlString(htmlString) {
|
|
12
|
+
if (typeof window === "undefined")
|
|
13
|
+
return "";
|
|
14
|
+
const parser = new DOMParser();
|
|
15
|
+
const html = parser.parseFromString(htmlString, "text/html");
|
|
16
|
+
return html?.body?.textContent?.trim() || "";
|
|
17
|
+
}
|
|
18
|
+
export function sanitizeHTML(html) {
|
|
19
|
+
const element = document.createElement("div");
|
|
20
|
+
element.innerHTML = html;
|
|
21
|
+
return element.textContent;
|
|
22
|
+
}
|