parseBigInt static method
Tries to parse a BigInt.
- Returns
def
ifvalue
is invalid.
Implementation
static BigInt? parseBigInt(Object? value, [BigInt? def]) {
if (value == null) return def;
if (value is BigInt) {
return value;
} else if (value is num) {
return BigInt.from(value);
} else if (value is DateTime) {
return BigInt.from(value.millisecondsSinceEpoch);
} else {
var s = _valueAsString(value);
if (s.isEmpty) {
return def;
}
var n = BigInt.tryParse(s);
if (n == null) {
s = s.replaceAll(_regExpNotNumber, '');
n = BigInt.tryParse(s);
}
return n ?? def;
}
}