diff --git a/ph_units/converter.py b/ph_units/converter.py index b777d8a..4645aac 100644 --- a/ph_units/converter.py +++ b/ph_units/converter.py @@ -184,6 +184,9 @@ def convert(_value, _input_unit, _target_unit): if _value is None: return None + if str(_value).strip() == "": + return 0 + input_unit, target_unit = _clean_user_inputs( _input_unit, _target_unit, unit_type_alias_dict ) diff --git a/ph_units/unit_types/area.py b/ph_units/unit_types/area.py index 9a8d0b8..fbdb659 100644 --- a/ph_units/unit_types/area.py +++ b/ph_units/unit_types/area.py @@ -8,7 +8,7 @@ class MeterSquare(Base_UnitType): """Meter Square""" __symbol__ = "M2" - __aliases__ = ["SM", "SQM", "SQ.M", "SQ-M", "SQ-METER", "SQ-METERS", "M²"] + __aliases__ = ["SM", "SQM", "SQ.M", "SQ-M", "SQ-METER", "SQ-METERS", "M²", "m²"] __factors__ = { "M2": "{}*1", "CM2": "{}*10_000", @@ -22,7 +22,15 @@ class CentimeterSquare(Base_UnitType): """Centimeter Square""" __symbol__ = "CM2" - __aliases__ = ["SQCM", "SQ.CM", "SQ-CM", "SQ-CENTIMETER", "SQ-CENTIMETERS", "CM²"] + __aliases__ = [ + "SQCM", + "SQ.CM", + "SQ-CM", + "SQ-CENTIMETER", + "SQ-CENTIMETERS", + "CM²", + "cm²", + ] __factors__ = { "MM2": "{}*100", "CM2": "{}*1", @@ -36,7 +44,15 @@ class MillimeterSquare(Base_UnitType): """Millimeter Square""" __symbol__ = "MM2" - __aliases__ = ["SQMM", "SQ.MM", "SQ-MM", "SQ-MILLIMETER", "SQ-MILLIMETERS", "MM²"] + __aliases__ = [ + "SQMM", + "SQ.MM", + "SQ-MM", + "SQ-MILLIMETER", + "SQ-MILLIMETERS", + "MM²", + "mm²", + ] __factors__ = { "MM2": "{}*1", "CM2": "{}*0.01", @@ -58,6 +74,7 @@ class FootSquare(Base_UnitType): "SQ-FT", "SQ-FOOT", "FT²", + "ft²", "SQ-FEET", ] __factors__ = { @@ -81,6 +98,7 @@ class InchSquare(Base_UnitType): "SQ-IN", "SQ-INCH", "IN²", + "in²", "SQ-INCHES", ] __factors__ = { diff --git a/tests/test_areas.py b/tests/test_areas.py index e66afa9..ab885e4 100644 --- a/tests/test_areas.py +++ b/tests/test_areas.py @@ -7,6 +7,10 @@ from ph_units.unit_type import Unit +def test_space(): + assert convert(" ", "M2", "M2") == 0 + + def test_meter_squared(): assert convert(1, "M2", "M2") == 1 assert convert(1, "M²", "M2") == 1