<commit_before>/* eslint-env browser */
'use strict'

const input = document.getElementById('chars')
const template = document.getElementById('char--template')
const display = document.querySelector('main')

let names
fetch('/json/names.json')
  .then(response => response.json())
  .then(json => { names = json })
  .then(updateUi)

input.addEventListener('input', updateUi)

function updateUi () {
  clearChildren(display)

  for (const char of input.value) {
    const details = createCharDetails(char, template)

    display.appendChild(details)
  }
}

function clearChildren (node) {
  while (node.firstChild) {
    node.removeChild(node.firstChild)
  }
}

function createCharDetails (char, template) {
  const code = char.charCodeAt().toString(16).toUpperCase()
  const name = (names) ? names[code] || 'Unknown' : 'Loading...'
  const bytes = [...new TextEncoder().encode(char)]
    .map(bytes => bytes.toString(16).toUpperCase())
    .join(' ')

  template.content.querySelector('.char--literal').textContent = char
  template.content.querySelector('.char--name').textContent = name
  template.content.querySelector('.char--code').textContent = code
  template.content.querySelector('.char--bytes').textContent = bytes

  return document.importNode(template.content, true)
}<commit_msg>Workaround for firefox not being able to handle for const of<commit_after>/* eslint-env browser */
'use strict'

const input = document.getElementById('chars')
const template = document.getElementById('char--template')
const display = document.querySelector('main')

let names
fetch('/json/names.json')
  .then(response => response.json())
  .then(json => { names = json })
  .then(updateUi)

input.addEventListener('input', updateUi)

function updateUi () {
  clearChildren(display)

  for (let char of input.value) {
    const details = createCharDetails(char, template)

    display.appendChild(details)
  }
}

function clearChildren (node) {
  while (node.firstChild) {
    node.removeChild(node.firstChild)
  }
}

function createCharDetails (char, template) {
  const code = char.charCodeAt().toString(16).toUpperCase()
  const name = (names) ? names[code] || 'Unknown' : 'Loading...'
  const bytes = [...new TextEncoder().encode(char)]
    .map(bytes => bytes.toString(16).toUpperCase())
    .join(' ')

  template.content.querySelector('.char--literal').textContent = char
  template.content.querySelector('.char--name').textContent = name
  template.content.querySelector('.char--code').textContent = code
  template.content.querySelector('.char--bytes').textContent = bytes

  return document.importNode(template.content, true)
}
{'fraction_non_alphanumeric': 0.15203344735841884, 'fraction_numerical': 0.003040668947168377, 'mean_word_length': 4.588110403397027, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '1018310', 'n_tokens_mistral': 755, 'n_tokens_neox': 752, 'n_words': 160}