source: trip-planner-front/node_modules/domutils/lib/stringify.js@ 571e0df

Last change on this file since 571e0df was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 2.9 KB
Line 
1"use strict";
2var __importDefault = (this && this.__importDefault) || function (mod) {
3 return (mod && mod.__esModule) ? mod : { "default": mod };
4};
5Object.defineProperty(exports, "__esModule", { value: true });
6exports.innerText = exports.textContent = exports.getText = exports.getInnerHTML = exports.getOuterHTML = void 0;
7var domhandler_1 = require("domhandler");
8var dom_serializer_1 = __importDefault(require("dom-serializer"));
9var domelementtype_1 = require("domelementtype");
10/**
11 * @param node Node to get the outer HTML of.
12 * @param options Options for serialization.
13 * @deprecated Use the `dom-serializer` module directly.
14 * @returns `node`'s outer HTML.
15 */
16function getOuterHTML(node, options) {
17 return (0, dom_serializer_1.default)(node, options);
18}
19exports.getOuterHTML = getOuterHTML;
20/**
21 * @param node Node to get the inner HTML of.
22 * @param options Options for serialization.
23 * @deprecated Use the `dom-serializer` module directly.
24 * @returns `node`'s inner HTML.
25 */
26function getInnerHTML(node, options) {
27 return (0, domhandler_1.hasChildren)(node)
28 ? node.children.map(function (node) { return getOuterHTML(node, options); }).join("")
29 : "";
30}
31exports.getInnerHTML = getInnerHTML;
32/**
33 * Get a node's inner text. Same as `textContent`, but inserts newlines for `<br>` tags.
34 *
35 * @deprecated Use `textContent` instead.
36 * @param node Node to get the inner text of.
37 * @returns `node`'s inner text.
38 */
39function getText(node) {
40 if (Array.isArray(node))
41 return node.map(getText).join("");
42 if ((0, domhandler_1.isTag)(node))
43 return node.name === "br" ? "\n" : getText(node.children);
44 if ((0, domhandler_1.isCDATA)(node))
45 return getText(node.children);
46 if ((0, domhandler_1.isText)(node))
47 return node.data;
48 return "";
49}
50exports.getText = getText;
51/**
52 * Get a node's text content.
53 *
54 * @param node Node to get the text content of.
55 * @returns `node`'s text content.
56 * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Node/textContent}
57 */
58function textContent(node) {
59 if (Array.isArray(node))
60 return node.map(textContent).join("");
61 if ((0, domhandler_1.hasChildren)(node) && !(0, domhandler_1.isComment)(node)) {
62 return textContent(node.children);
63 }
64 if ((0, domhandler_1.isText)(node))
65 return node.data;
66 return "";
67}
68exports.textContent = textContent;
69/**
70 * Get a node's inner text.
71 *
72 * @param node Node to get the inner text of.
73 * @returns `node`'s inner text.
74 * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Node/innerText}
75 */
76function innerText(node) {
77 if (Array.isArray(node))
78 return node.map(innerText).join("");
79 if ((0, domhandler_1.hasChildren)(node) && (node.type === domelementtype_1.ElementType.Tag || (0, domhandler_1.isCDATA)(node))) {
80 return innerText(node.children);
81 }
82 if ((0, domhandler_1.isText)(node))
83 return node.data;
84 return "";
85}
86exports.innerText = innerText;
Note: See TracBrowser for help on using the repository browser.