1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const tools_1 = require("@toba/tools");
|
4 | const xmldom_1 = require("xmldom");
|
5 | const fromText = (text) => new xmldom_1.DOMParser().parseFromString(text);
|
6 | function value(node) {
|
7 | if (tools_1.is.value(node) && node.normalize) {
|
8 | node.normalize();
|
9 | }
|
10 | return node && node.firstChild && node.firstChild.nodeValue;
|
11 | }
|
12 | function firstNode(node, tag) {
|
13 | const n = node.getElementsByTagName(tag);
|
14 | return tools_1.is.value(n) && n.length > 0 ? n[0] : null;
|
15 | }
|
16 | function firstValue(node, tag) {
|
17 | return value(firstNode(node, tag));
|
18 | }
|
19 | const numberAttribute = (dom, name) => {
|
20 | const num = dom.getAttribute(name);
|
21 | return num !== null ? parseFloat(num) : 0;
|
22 | };
|
23 | exports.xml = { value, firstValue, firstNode, numberAttribute, fromText };
|