<commit_before>/**
 * @packageDocumentation
 * @module Utils
 */

import { BooruError, sites } from './Constants'

import { parse as xml2json } from 'fast-xml-parser'

/**
 * Check if `site` is a supported site (and check if it's an alias and return the sites's true name)
 *
 * @param  {String} domain The site to resolveSite
 * @return {String?} null if site is not supported, the site otherwise
 */
export function resolveSite(domain: string): string | null {
  if (typeof domain !== 'string') {
    return null
  }

  domain = domain.toLowerCase()

  for (const site in sites) {
    if (site === domain || sites[site].aliases.includes(domain)) {
      return site
    }
  }

  return null
}

interface XMLPage {
  html: any
}

interface XMLPosts {
  post?: any[]
  tag?: any | any[]
}

interface BooruXML {
  html?: XMLPage
  '!doctype'?: XMLPage
  posts: XMLPosts
}

/**
 * Parses xml to json, which can be used with js
 *
 * @private
 * @param  {String} xml The xml to convert to json
 * @return {Object[]} A Promise with an array of objects created from the xml
 */<commit_msg>fix(Utils): resolveSite can now resolve subdomains<commit_after>/**
 * @packageDocumentation
 * @module Utils
 */

import { BooruError, sites } from './Constants'

import { parse as xml2json } from 'fast-xml-parser'

/**
 * Check if `site` is a supported site (and check if it's an alias and return the sites's true name)
 *
 * @param  {String} domain The site to resolveSite
 * @return {String?} null if site is not supported, the site otherwise
 */
export function resolveSite(domain: string): string | null {
  if (typeof domain !== 'string') {
    return null
  }

  domain = domain.toLowerCase()

  for (const site in sites) {
    if (
      site === domain ||
      sites[site].domain === domain ||
      sites[site].aliases.includes(domain)
    ) {
      return site
    }
  }

  return null
}

interface XMLPage {
  html: any
}

interface XMLPosts {
  post?: any[]
  tag?: any | any[]
}

interface BooruXML {
  html?: XMLPage
  '!doctype'?: XMLPage
  posts: XMLPosts
}

/**
 * Parses xml to json, which can be used with js
 *
 * @private
 * @param  {String} xml The xml to convert to json
 * @return {Object[]} A Promise with an array of objects created from the xml
 */
{'fraction_non_alphanumeric': 0.1206896551724138, 'fraction_numerical': 0.0008841732979664014, 'mean_word_length': 3.2141527001862196, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 12}, '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': '3568737', 'n_tokens_mistral': 713, 'n_tokens_neox': 699, 'n_words': 269}