JSFiddle - React, Tailwind, and code Playground

by Alex

HTML

<div id="output">

</div>
<div id="ts">

</div>


<div id="outputMax">

</div>
<div id="tsMax">

</div>

CSS

#output{
  font-size:32px;
  font-family: monospace;
  font-weight: bold;
}

JavaScript

const hash = (text) => {
  //  A string hashing function based on Daniel J. Bernstein's popular 'times 33' hash algorithm.
  let hash = 5381
  let index = text.length
  while (index) {
    hash = (hash * 33) ^ text.charCodeAt(--index)
  }
  return hash >>> 0
}

const optimize = (number) => {
  // convert the base10 number to a short base32 number in uppercase
  const resp = parseInt(number, 10).toString(32).toUpperCase()
  ///... and replace the missleading chars
  resp = resp.replace(/I/g, "Z")
  resp = resp.replace(/O/g, "Y")
  resp = resp.replace(/0/g, "X")
  // letter W is still unused
  return resp
}

const unoptimize = (str, method) => {
  let resp
  ///... and replace the misleading chars
  // letter W is still unused
  str = str.replace(/Z/g, "I")
  str = str.replace(/Y/g, "O")
  str = str.replace(/X/g, "0")

  // convert the base10 number to a short base32 number in uppercase
  if (method === "flat") {
    resp = parseInt(str, 32)
  } else {
    resp =
      parseInt(str.substring(0, 3), 32) + "." + parseInt(str.substring(3), 32)
  }
  return resp
}

// Exported
const toHex = (input) => {
  let hash = "",
    alphabet = "BCDFGHJKLMNPQRTVWXYZ",
    alphabetLength = alphabet.length
  do {
    hash = alphabet[input % alphabetLength] + hash
    input = parseInt(input / alphabetLength, 10)
  } while (input)
  return hash
}

const getBeat = (resolution = 1000, date = Date.now()) => {
  // INFO: 1 beat is 86,4 seconds
  // INFO: 0,1 beat is 8,64 seconds (resolution 10)
  // INFO: 0,01 beat is 0,864 seconds (resolution 100) ca. 1 per second
  // INFO: 0,001 beat is 0,0864 seconds (resolution 1_000) ca 12 per second
  // INFO: 0,0001 beat is 0,00864 seconds (resolution 10_000) ca 115,7 per second
  // INFO: 0,00001 beat is 0,000864 seconds (resolution 100_000) ca 1157 per second
  // INFO: 0,000001 beat is 1 seconds (resolution 1_000_000) ca 11574 per second
  const beat = Math.round(
    ((new Date(date) / 864e2 + 1e3 / 24) % 1e3) * resolution,
  )
  return...