source: trip-planner-front/node_modules/critters/src/dom_temp.js@ fa375fe

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

initial commit

  • Property mode set to 100644
File size: 1.4 KB
Line 
1/**
2 * Copyright 2018 Google LLC
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 * use this file except in compliance with the License. You may obtain a copy of
6 * the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 * License for the specific language governing permissions and limitations under
14 * the License.
15 */
16import { JSDOM } from 'jsdom';
17
18/**
19 * Parse HTML into a mutable, serializable DOM Document, provided by JSDOM.
20 * @private
21 * @param {String} html HTML to parse into a Document instance
22 */
23export function createDocument (html) {
24 const jsdom = new JSDOM(html, {
25 contentType: 'text/html'
26 });
27 const { window } = jsdom;
28 const document = window.document;
29 document.$jsdom = jsdom;
30 return document;
31}
32/**
33 * Serialize a Document to an HTML String
34 * @private
35 * @param {Document} document A Document, such as one created via `createDocument()`
36 */
37export function serializeDocument (document) {
38 return document.$jsdom.serialize();
39}
40
41/** Like node.textContent, except it works */
42export function setNodeText (node, text) {
43 while (node.lastChild) {
44 node.removeChild(node.lastChild);
45 }
46 node.appendChild(node.ownerDocument.createTextNode(text));
47}
Note: See TracBrowser for help on using the repository browser.