<commit_before>/**
 * Copyright (c) Tiny Technologies, Inc. All rights reserved.
 * Licensed under the LGPL or a commercial license.
 * For LGPL see License.txt in the project root for license information.
 * For commercial licenses see https://www.tiny.cloud/
 */

import Node from '../api/html/Node';
import { Unicode } from '@ephox/katamari';

const paddEmptyNode = function (settings, args, blockElements, node) {
  const brPreferred = settings.padd_empty_with_br || args.insert;

  if (brPreferred && blockElements[node.name]) {
    node.empty().append(new Node('br', 1)).shortEnded = true;
  } else {
    node.empty().append(new Node('#text', 3)).value = Unicode.nbsp;
  }
};

const isPaddedWithNbsp = function (node) {
  return hasOnlyChild(node, '#text') && node.firstChild.value === Unicode.nbsp;
};

const hasOnlyChild = function (node, name) {
  return node && node.firstChild && node.firstChild === node.lastChild && node.firstChild.name === name;
};

const isPadded = function (schema, node) {
  const rule = schema.getElementRule(node.name);
  return rule && rule.paddEmpty;
};

const isEmpty = function (schema, nonEmptyElements, whitespaceElements, node) {
  return node.isEmpty(nonEmptyElements, whitespaceElements, function (node) {
    return isPadded(schema, node);
  });
};

const isLineBreakNode = (node, blockElements) => node && (blockElements[node.name] || node.name === 'br');

export {
  paddEmptyNode,
  isPaddedWithNbsp,
  hasOnlyChild,
  isEmpty,
  isLineBreakNode
};<commit_msg>TINY-4727: sprinkled some types<commit_after>/**
 * Copyright (c) Tiny Technologies, Inc. All rights reserved.
 * Licensed under the LGPL or a commercial license.
 * For LGPL see License.txt in the project root for license information.
 * For commercial licenses see https://www.tiny.cloud/
 */

import Node from '../api/html/Node';
import { Unicode } from '@ephox/katamari';
import { DomParserSettings, ParserArgs } from '../api/html/DomParser';
import Schema, { SchemaMap } from '../api/html/Schema';

const paddEmptyNode = (settings: DomParserSettings, args: ParserArgs, blockElements: SchemaMap, node: Node) => {
  const brPreferred = settings.padd_empty_with_br || args.insert;

  if (brPreferred && blockElements[node.name]) {
    node.empty().append(new Node('br', 1)).shortEnded = true;
  } else {
    node.empty().append(new Node('#text', 3)).value = Unicode.nbsp;
  }
};

const isPaddedWithNbsp = (node: Node) => {
  return hasOnlyChild(node, '#text') && node.firstChild.value === Unicode.nbsp;
};

const hasOnlyChild = (node: Node, name: string) => {
  return node && node.firstChild && node.firstChild === node.lastChild && node.firstChild.name === name;
};

const isPadded = (schema: Schema, node: Node) => {
  const rule = schema.getElementRule(node.name);
  return rule && rule.paddEmpty;
};

const isEmpty = (schema: Schema, nonEmptyElements: SchemaMap, whitespaceElements: SchemaMap, node: Node) => {
  return node.isEmpty(nonEmptyElements, whitespaceElements, (node) => {
    return isPadded(schema, node);
  });
};

const isLineBreakNode = (node: Node, blockElements: SchemaMap) => node && (blockElements[node.name] || node.name === 'br');

export {
  paddEmptyNode,
  isPaddedWithNbsp,
  hasOnlyChild,
  isEmpty,
  isLineBreakNode
};
{'fraction_non_alphanumeric': 0.14561618638871857, 'fraction_numerical': 0.002452483139178418, 'mean_word_length': 4.568259385665529, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3133852', 'n_tokens_mistral': 1030, 'n_tokens_neox': 1008, 'n_words': 272}