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Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/cruid@1.0.0/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","const os = require('os')\n\nconst DEFAULT_FILL = '0'\nconst DEFAULT_BASE = 36\nconst DEFAULT_HALF_FP_LEN = 2\n\nconst DEFAULT_HOSTNAME = os.hostname()\nconst DEFAULT_PID = process.pid\n\nclass Cruid {\n  static pad (string, fill, length) {\n    string = String(string)\n    length = parseInt(length, 10) || DEFAULT_HALF_FP_LEN\n    return ((fill || DEFAULT_FILL).repeat(Math.max(length - string.length, 0)) + string).slice(-length)\n  }\n\n  static hostId (hostname) {\n    hostname = String(hostname || DEFAULT_HOSTNAME)\n    const hlen = hostname.length\n    let int = hlen + DEFAULT_BASE\n    for (let i = 0; i < hlen; i++) {\n      int += hostname.charCodeAt(i)\n    }\n    return Cruid.pad(int.toString(DEFAULT_BASE), DEFAULT_FILL, DEFAULT_HALF_FP_LEN)\n  }\n\n  static fingerprint (pid, hostname, base) {\n    pid = parseInt(pid, 10)\n    if (Number.isNaN(pid)) pid = DEFAULT_PID\n    return Cruid.pad(pid.toString(parseInt(base, 10) || DEFAULT_BASE), DEFAULT_FILL, DEFAULT_HALF_FP_LEN) + Cruid.hostId(hostname)\n  }\n\n  static defaults () {\n    return {\n      prefix: 'c',\n      base: DEFAULT_BASE,\n      blockSize: 4,\n      fill: DEFAULT_FILL,\n      pid: DEFAULT_PID,\n      hostname: DEFAULT_HOSTNAME,\n      rng: Math,\n      timestampSize: 8\n    }\n  }\n\n  static get (opts) {\n    return new Cruid(opts)\n  }\n\n  constructor (opts) {\n    const d = Cruid.defaults()\n    this.prefix = opts?.prefix || d.prefix\n    this.base = opts?.base || d.base\n    this.blockSize = opts?.blockSize || d.blockSize\n    this.discreteValues = Math.pow(this.base, this.blockSize)\n    this.pid = opts?.pid || d.pid\n    this.hostname = opts?.hostname || d.hostname\n    this.fill = opts?.fill || d.fill\n    this.rng = opts?.rng || d.rng\n    this.timestampSize = opts?.timestampSize || d.timestampSize\n\n    this._fingerprint = Cruid.fingerprint(this.pid, this.hostname, this.base)\n    this._counter = 0\n  }\n\n  count () {\n    this._counter = this._counter < this.discreteValues ? this._counter : 0\n    return this._counter++\n  }\n\n  counter () {\n    return Cruid.pad(this.count().toString(this.base), this.fill, this.blockSize)\n  }\n\n  randomBlock () {\n    const block = this.rng.random() * this.discreteValues << 0\n    return Cruid.pad(block.toString(this.base), this.fill, this.blockSize)\n  }\n\n  timestamp () {\n    return Cruid.pad(Date.now().toString(this.base), this.fill, this.timestampSize)\n  }\n\n  fingerprint () {\n    return this._fingerprint\n  }\n\n  id () {\n    // default: 'c' + 4 random chars + 4 random chars + 8 ts chars + 4 counter chars + 4 fingerprint chars\n    return this.prefix + this.randomBlock() + this.randomBlock() + this.timestamp() + this.counter() + this._fingerprint\n  }\n\n  slug () {\n    // default: 2 random chars + 2 ts chars + (1 to 4 counter chars) + 2 fingerprint chars\n    return this.randomBlock().slice(-2) + this.timestamp().slice(-2) + this.count().toString(this.base).slice(-4) + this._fingerprint[0] + this._fingerprint[this._fingerprint.length - 1]\n  }\n}\n\nconst singleton = Cruid.get()\n\nmodule.exports = function cruid () {\n  return singleton.id()\n}\n\nmodule.exports.slug = function slug () {\n  return singleton.slug()\n}\n\nmodule.exports.fingerprint = function fingerprint () {\n  return singleton.fingerprint()\n}\n\nmodule.exports.createFingerprint = function createFingerprint (pid, hostname, base) {\n  return Cruid.fingerprint(pid, hostname, base)\n}\n\nmodule.exports.Cruid = Cruid\n"]}