@jsenv/ast 6.2.3 → 6.2.4
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/package.json +1 -1
- package/src/html/html_node_attributes.js +17 -4
- package/src/html/html_parse.js +1 -5
- package/src/main.js +1 -0
package/package.json
CHANGED
|
@@ -3,6 +3,18 @@ export const getHtmlNodeAttribute = (htmlNode, attributeName) => {
|
|
|
3
3
|
return attribute ? attribute.value || "" : undefined;
|
|
4
4
|
};
|
|
5
5
|
|
|
6
|
+
export const getHtmlNodeAttributes = (htmlNode) => {
|
|
7
|
+
const { attrs } = htmlNode;
|
|
8
|
+
if (!attrs) {
|
|
9
|
+
return {};
|
|
10
|
+
}
|
|
11
|
+
const attributes = {};
|
|
12
|
+
for (const attr of attrs) {
|
|
13
|
+
attributes[attr.name] = attr.value;
|
|
14
|
+
}
|
|
15
|
+
return attributes;
|
|
16
|
+
};
|
|
17
|
+
|
|
6
18
|
export const setHtmlNodeAttributes = (htmlNode, attributesToAssign) => {
|
|
7
19
|
if (typeof attributesToAssign !== "object") {
|
|
8
20
|
throw new TypeError(`attributesToAssign must be an object`);
|
|
@@ -35,9 +47,10 @@ export const setHtmlNodeAttributes = (htmlNode, attributesToAssign) => {
|
|
|
35
47
|
};
|
|
36
48
|
|
|
37
49
|
const getHtmlAttributeByName = (htmlNode, attributeName) => {
|
|
38
|
-
const attrs = htmlNode
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
50
|
+
const { attrs } = htmlNode;
|
|
51
|
+
if (!attrs) {
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
const attribute = attrs.find((attr) => attr.name === attributeName);
|
|
42
55
|
return attribute;
|
|
43
56
|
};
|
package/src/html/html_parse.js
CHANGED
|
@@ -13,11 +13,7 @@ import {
|
|
|
13
13
|
import { findHtmlChildNode, visitHtmlNodes } from "./html_search.js";
|
|
14
14
|
import { getHtmlNodeText } from "./html_node_text.js";
|
|
15
15
|
|
|
16
|
-
export const parseHtml = ({
|
|
17
|
-
html,
|
|
18
|
-
url,
|
|
19
|
-
storeOriginalPositions = true,
|
|
20
|
-
} = {}) => {
|
|
16
|
+
export const parseHtml = ({ html, url, storeOriginalPositions = true }) => {
|
|
21
17
|
const htmlAst = parse(html, {
|
|
22
18
|
sourceCodeLocationInfo: true,
|
|
23
19
|
onParseError: (parse5Error) => {
|