toBigInt = (x, min, max) => {
  if (typeof x === 'undefined') throw new Error('value is required')

  const n = BigInt(x)
  if (min !== undefined && n < BigInt(min)) {
    throw new Error(`value ${x} must be at least ${min}`)
  }

  if (max !== undefined && n > BigInt(max)) {
    throw new Error(`value ${x} must be at most ${max}`)
  }

  return n
}
@param {any} x
@param {bigint | number} [min]
@param {bigint | number} [max]
@returns {bigint}