parseBigInt function

BigInt? parseBigInt(
  1. dynamic o, [
  2. BigInt? def
])

Parses o as BigInt. If can't parse returns def.

Implementation

BigInt? parseBigInt(dynamic o, [BigInt? def]) {
  if (o == null) return def;
  if (o is BigInt) return o;
  if (o is num) return BigInt.from(o);

  var s = o.toString().trim();
  return BigInt.tryParse(s) ?? parseNum(s)?.toBigInt() ?? def;
}