UNPKG

1.49 kBJavaScriptView Raw
1/*
2 * Licensed under the Apache License, Version 2.0 (the "License");
3 * you may not use this file except in compliance with the License.
4 * You may obtain a copy of the License at
5 *
6 * http://www.apache.org/licenses/LICENSE-2.0
7 *
8 * Unless required by applicable law or agreed to in writing, software
9 * distributed under the License is distributed on an "AS IS" BASIS,
10 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 * See the License for the specific language governing permissions and
12 * limitations under the License.
13 */
14'use strict';
15/**
16 * Determine whether a node's text content is entirely whitespace.
17 *
18 * @param {object} node A node implementing the |CharacterData| interface
19 * (i.e. a |Text|, |Comment|, or |CDATASection| node
20 * @return {boolean} True if all of the text content of |nod| is whitespace,
21 * otherwise false.
22 */
23
24function isAllWhitespace(node) {
25 return !/[^\t\n\r ]/.test(node.textContent);
26}
27/**
28 * Determine if a node should be ignored by the iterator functions.
29 *
30 * @param {object} node An object implementing the DOM1 |Node| interface.
31 * @return {boolean} true if the node is:
32 * 1) A |Text| node that is all whitespace
33 * 2) A |Comment| node
34 * and otherwise false.
35 */
36
37
38function isIgnorable(node) {
39 return node.nodeType === 8 || // A comment node
40 node.nodeType === 3 && isAllWhitespace(node); // a text node, all ws
41}
42
43module.exports = {
44 isAllWhitespace,
45 isIgnorable
46};
\No newline at end of file