parseUnit function
Implementation
Unit? parseUnit(Object? unit, [Unit? def]) {
if (unit == null) {
return def;
} else if (unit is Unit) {
return unit;
} else if (unit is String) {
return getUnitByName(unit);
} else if (unit is int) {
return getUnitByIndex(unit);
} else {
return def;
}
}