function Nat(allegedNum) {
  if (typeof allegedNum === 'bigint') {
    if (allegedNum < 0n) {
      throw RangeError(`${allegedNum} is negative`);
    }
    return allegedNum;
  }

  if (typeof allegedNum === 'number') {
    if (!Number.isSafeInteger(allegedNum)) {
      throw RangeError(`${allegedNum} is not a safe integer`);
    }
    if (allegedNum < 0) {
      throw RangeError(`${allegedNum} is negative`);
    }
    return BigInt(allegedNum);
  }

  throw TypeError(
    `${allegedNum} is a ${typeof allegedNum} but must be a bigint or a number`,
  );
}
If `allegedNumber` passes the `isNat` test, then return it as a bigint.
Otherwise throw an appropriate error.

If `allegedNum` is neither a bigint nor a number, `Nat` throws a `TypeError`.
Otherwise, if it is not a [safely
representable](https://esdiscuss.org/topic/more-numeric-constants-please-especially-epsilon#content-14)
non-negative integer, `Nat` throws a `RangeError`.
Otherwise, it is converted to a bigint if necessary and returned.

@param {unknown} allegedNum
@returns {bigint}