JSFiddle - React, Tailwind, and code Playground

by Alex

HTML

<h2 contenteditable>
Alexander Schedler
</h2>
<h1>

</h1>

JavaScript

const Helper = {
  _leftPad (i, n, pad) {
    return Array(n - String(i).length + 1).join(pad || '0') + i
  },
  // UUID Helper from https://stackoverflow.com/questions/105034/create-guid-uuid-in-javascript
  uuid () {
    const prefix = arguments[0] || ''
    return (
      prefix +
      'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
        const r = (Math.random() * 16) | 0
        const v = c === 'x' ? r : (r & 0x3) | 0x8
        return v.toString(16)
      })
    )
  },
  // tracking
  lastId: ' ',
  hash (text) {
    let hash = 5381
    let index = text.length
    while (index) {
      hash = (hash * 33) ^ text.charCodeAt(--index)
    }
    return hash >>> 0
  },
  optimize (number) {
    // convert the base10 number to a short base32 number in uppercase
    let resp = parseInt(number, 10)
      .toString(32)
      .toUpperCase() /// ... and replace the missleading chars
    resp = resp.replace('I', 'Z')
    resp = resp.replace('O', 'Y')
    resp = resp.replace('0', 'X')
    // letter W is still unused
    return resp
  },
  beat () {
    // generate the beat with the desired resolution
    const resolution = arguments[0] || 1000
    const beat = Math.round(((new Date() / 864e2 + 1e3 / 24) % 1e3) * resolution)
    return beat
  },
  day () {
    // generate day of the year with leading zeros
    const day =
      (Date.UTC(new Date().getFullYear(), new Date().getMonth(), new Date().getDate()) -
        Date.UTC(new Date().getFullYear(), 0, 0)) /
      24 /
      60 /
      60 /
      1000
    return this._leftPad(day, 2, 0)
  },
  generateClientHash (name) {
    const hash = this.optimize(this.hash(name))
    return this._leftPad(hash, 7, 0)
  },
  generateUnified () {
    const tag = arguments[0] || '000' // tag is the customer id if no tag is given we take 000
    const shortYear = new Date()
      .getFullYear()
      .toString()
      .substring(2)
    const day = this.day()
    const seq = this.beat(1000)
    this.lastId = [
  ...