parse static method

BigInt parse(
  1. dynamic number, {
  2. bool allowHex = true,
})

Parses a dynamic value number into a BigInt.

Throws:

Implementation

static BigInt parse(dynamic number, {bool allowHex = true}) {
  if (number is BigInt) return number;
  if (number is int) return BigInt.from(number);
  if (number is String) {
    BigInt? parse = BigInt.tryParse(number);
    if (parse == null && allowHex) {
      parse = BigInt.tryParse(StringUtils.strip0x(number), radix: 16);
    }
    if (parse != null) return parse;
  }
  throw ArgumentException.invalidOperationArguments(
    "parse",
    name: "number",
    reason: "Failed to parse value as BigInt",
  );
}