parse static method

BigInt parse(
  1. dynamic v
)

Parses a dynamic value v into a BigInt.

Tries to convert the dynamic value v into a BigInt. It supports parsing from BigInt, int, List

Parameters:

  • v: The dynamic value to be parsed into a BigInt.

Returns:

  • A BigInt representation of the parsed value.

Throws:

Implementation

static BigInt parse(dynamic v) {
  try {
    if (v is BigInt) return v;
    if (v is int) return BigInt.from(v);
    if (v is List<int>) {
      return fromBytes(v, sign: true);
    }
    if (v is String) {
      BigInt? parse = BigInt.tryParse(v);
      if (parse == null && StringUtils.ixHexaDecimalNumber(v)) {
        parse = BigInt.parse(StringUtils.strip0x(v), radix: 16);
      }
      return parse!;
    }
    // ignore: empty_catches
  } catch (e) {}
  throw const ArgumentException("invalid input for parse bigint");
}