toNumber = (x, min = Number.MIN_SAFE_INTEGER, max = Number.MAX_SAFE_INTEGER) => {
  if (typeof x === 'undefined') {
    throw new Error('value is required')
  }
  if (typeof x === 'bigint') {
    if (x < BigInt(min) || x > BigInt(max)) {
      throw new Error(`value ${x} must be between ${min} and ${max}`)
    }
    return Number(x)
  } else {
    const n = Number(x)
    if (isNumber(n)) {
      if (x < min || x > max) {
        throw new Error(`value ${x} must be between ${min} and ${max}`)
      }
      return n
    }
  }
  throw new Error(`value ${x} is not a number`)
}
@param {any | bigint} x
@param {number} min
@param {number} max
@returns {number}