<commit_before>import { prop, map, filter, pipe, apply } from './functional-util.js'

/**
 * @typedef {Object} HeaderObject
 * @property {string} link
 * @property {number} level
 * @property {string} text
 */

/**
 * @typedef {HeaderObject[]} HeaderList
 */

/**
 * @param {string} link
 * @param {number} level
 * @param {string} text
 * @returns {HeaderObject}
 */
export function createHeader (link, level, text) {
  return {
    link,
    level,
    text
  }
}

/**
 * @param {string} query
 * @returns {function(root: Element): NodeList}
 */
export function querySelectorAll (query) {
  return function querySelectorAllInner (root) {
    return root.querySelectorAll(query)
  }
}

/**
 * @param {string} query
 * @returns {function(root: Element): Element[]}
 */
export function querySelectorAllArray (query) {
  return pipe(querySelectorAll(query), Array.from)
}

/**
 * @function
 * @param {Node}
 * @returns {boolean}
 */
export const hasText = pipe(prop('textContent'), Boolean)

/**
 * @function
 * @param {Node[]}
 * @returns {Node[]}
 */
export const filterEmptyText = filter(hasText)

export function createHeaders (...fun) {
  return pipe(filterEmptyText, ...fun, map(apply(createHeader)))
}

/**
 * @function
 * @param {Element}
 * @returns {Element[]}
 */
export const selectAllHeaderElement = querySelectorAllArray('h1, h2, h3, h4, h5, h6')<commit_msg>add missing JSDoc comment<commit_after>import { prop, map, filter, pipe, apply } from './functional-util.js'

/**
 * @typedef {Object} HeaderObject
 * @property {string} link
 * @property {number} level
 * @property {string} text
 */

/**
 * @typedef {HeaderObject[]} HeaderList
 */

/**
 * @param {string} link
 * @param {number} level
 * @param {string} text
 * @returns {HeaderObject}
 */
export function createHeader (link, level, text) {
  return {
    link,
    level,
    text
  }
}

/**
 * @param {string} query
 * @returns {function(root: Element): NodeList}
 */
export function querySelectorAll (query) {
  return function querySelectorAllInner (root) {
    return root.querySelectorAll(query)
  }
}

/**
 * @param {string} query
 * @returns {function(root: Element): Element[]}
 */
export function querySelectorAllArray (query) {
  return pipe(querySelectorAll(query), Array.from)
}

/**
 * @function
 * @param {Node}
 * @returns {boolean}
 */
export const hasText = pipe(prop('textContent'), Boolean)

/**
 * @function
 * @param {Node[]}
 * @returns {Node[]}
 */
export const filterEmptyText = filter(hasText)

/**
 * @param {...function} fun
 * @returns {function(root: Element): HeaderList}
 */
export function createHeaders (...fun) {
  return pipe(filterEmptyText, ...fun, map(apply(createHeader)))
}

/**
 * @function
 * @param {Element}
 * @returns {Element[]}
 */
export const selectAllHeaderElement = querySelectorAllArray('h1, h2, h3, h4, h5, h6')
{'fraction_non_alphanumeric': 0.16560958421423538, 'fraction_numerical': 0.004228329809725159, 'mean_word_length': 4.1338155515370705, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7083002', 'n_tokens_mistral': 907, 'n_tokens_neox': 900, 'n_words': 241}