Skip to main content

MetricUnitDisplayUnitUtils

Which unit to display a value in when the caller does not name one: for each dimension, the units to choose from by size (2500 m displays as 2.5 km), the time unit a rate is displayed per, and the SI symbols for an unnamed compound. Used by MetricUnitFormatUtils.

Functions​

getDisplayUnits​

MetricUnitDisplayUnitUtils.getDisplayUnits(
dimensions: Dimensions,
absolute: boolean?
) → {UnitDefinition}?

The units a value of dimensions is shown in, largest first, from system and its fallbacks (MetricUnitSystems.METRIC by default), or nil when none lists the dimension. An absolute value is shown on a scale people read, °C rather than kelvin, where the system has one.

pickDisplayUnit​

MetricUnitDisplayUnitUtils.pickDisplayUnit(
amount: number,
units: {UnitDefinition}
) → UnitDefinition

The largest unit on units that amount base units fills at least once, the smallest when it fills none, or MetricUnitDisplayUnitUtils.getBaseUnit when amount is zero.

getBaseUnit​

MetricUnitDisplayUnitUtils.getBaseUnit(units: {UnitDefinition}) → UnitDefinition

The unit on units that is one SI base unit, or the smallest when none is.

pickDisplayPerUnit​

MetricUnitDisplayUnitUtils.pickDisplayPerUnit(
amount: number--

per second

) → UnitDefinition

The shortest time unit that a rate of amount per second reaches at least once over, or a year when none does.

getBaseSymbol​

MetricUnitDisplayUnitUtils.getBaseSymbol(name: string) → string

The SI base unit symbol for a dimension name, such as "m" for "length", or the name itself when it has none.

Show raw api
{
    "functions": [
        {
            "name": "getDisplayUnits",
            "desc": "The units a value of `dimensions` is shown in, largest first, from `system` and its fallbacks ([MetricUnitSystems.METRIC]\nby default), or nil when none lists the dimension. An absolute value is shown on a scale people read, °C rather\nthan kelvin, where the system has one.",
            "params": [
                {
                    "name": "dimensions",
                    "desc": "",
                    "lua_type": "Dimensions"
                },
                {
                    "name": "system",
                    "desc": "",
                    "lua_type": "MetricUnitSystem?"
                },
                {
                    "name": "absolute",
                    "desc": "",
                    "lua_type": "boolean?"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "{ UnitDefinition }?"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 46,
                "path": "src/metricutils/src/Shared/Formatting/MetricUnitDisplayUnitUtils.lua"
            }
        },
        {
            "name": "pickDisplayUnit",
            "desc": "The largest unit on `units` that `amount` base units fills at least once, the smallest when it fills none, or\n[MetricUnitDisplayUnitUtils.getBaseUnit] when `amount` is zero.",
            "params": [
                {
                    "name": "amount",
                    "desc": "",
                    "lua_type": "number"
                },
                {
                    "name": "units",
                    "desc": "",
                    "lua_type": "{ UnitDefinition }"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "UnitDefinition"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 62,
                "path": "src/metricutils/src/Shared/Formatting/MetricUnitDisplayUnitUtils.lua"
            }
        },
        {
            "name": "getBaseUnit",
            "desc": "The unit on `units` that is one SI base unit, or the smallest when none is.",
            "params": [
                {
                    "name": "units",
                    "desc": "",
                    "lua_type": "{ UnitDefinition }"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "UnitDefinition"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 80,
                "path": "src/metricutils/src/Shared/Formatting/MetricUnitDisplayUnitUtils.lua"
            }
        },
        {
            "name": "pickDisplayPerUnit",
            "desc": "The shortest time unit that a rate of `amount` per second reaches at least once over, or a year when none does.",
            "params": [
                {
                    "name": "amount",
                    "desc": "per second",
                    "lua_type": "number"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "UnitDefinition"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 95,
                "path": "src/metricutils/src/Shared/Formatting/MetricUnitDisplayUnitUtils.lua"
            }
        },
        {
            "name": "getBaseSymbol",
            "desc": "The SI base unit symbol for a dimension name, such as `\"m\"` for `\"length\"`, or the name itself when it has none.",
            "params": [
                {
                    "name": "name",
                    "desc": "",
                    "lua_type": "string"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "string"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 125,
                "path": "src/metricutils/src/Shared/Formatting/MetricUnitDisplayUnitUtils.lua"
            }
        }
    ],
    "properties": [],
    "types": [],
    "name": "MetricUnitDisplayUnitUtils",
    "desc": "Which unit to display a value in when the caller does not name one: for each dimension, the units to choose from\nby size (`2500 m` displays as `2.5 km`), the time unit a rate is displayed per, and the SI symbols for an unnamed\ncompound. Used by [MetricUnitFormatUtils].",
    "source": {
        "line": 9,
        "path": "src/metricutils/src/Shared/Formatting/MetricUnitDisplayUnitUtils.lua"
    }
}