UNPKG

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