Compile-time extraction of CLDR unit data from a pre-built ETF file.
This module loads unit data from priv/unit/unit_data.etf, which is
generated by scripts/extract_unit_data.exs from the CLDR supplemental
units XML and validity XML files. Run that script whenever the CLDR
data is updated.
Summary
Functions
Returns the canonical ordering of base units from unitQuantities.
Returns a map from base unit string to its CLDR quantity name.
Returns the list of known base unit names from CLDR conversion data.
Returns the list of known unit categories.
Returns the base unit for a unit, checking custom registry first.
Returns the conversion factor for a unit, checking custom registry first.
Returns the conversion factor and offset for each source unit.
Returns a map from source unit name to its CLDR base unit string.
Returns all deprecated CLDR unit identifiers.
Returns the list of power components.
Returns the list of unit ID prefix components.
Returns detailed SI prefix data including symbols and powers.
Returns SI prefix multipliers as a map of prefix name to numeric multiplier.
Returns the list of SI prefix names.
Returns the list of fundamental (simple) base units.
Returns the list of unit ID suffix components.
Returns the resolved unit constants as a map of name to float value.
Returns the CLDR unit preference data.
Returns all valid CLDR unit identifiers with regular status.
Functions
@spec base_unit_order() :: [String.t()]
Returns the canonical ordering of base units from unitQuantities.
This ordering is used to reconstruct canonical base unit strings.
Returns
- A list of base unit strings in canonical order.
Returns a map from base unit string to its CLDR quantity name.
Returns
- A map such as
%{"meter" => "length", "kilogram" => "mass", ...}.
@spec base_units() :: [String.t()]
Returns the list of known base unit names from CLDR conversion data.
Returns
- A list of strings such as
["meter", "kilogram", "second", ...].
@spec categories() :: [String.t()]
Returns the list of known unit categories.
Returns
- A list of strings such as
["acceleration", "angle", "area", ...].
Returns the base unit for a unit, checking custom registry first.
Returns the conversion factor for a unit, checking custom registry first.
@spec conversion_factors() :: %{ required(String.t()) => %{factor: float() | :special, offset: float()} }
Returns the conversion factor and offset for each source unit.
The conversion from source to base unit is: base_value = value * factor + offset.
Returns
- A map such as
%{"foot" => %{factor: 0.3048, offset: 0.0}, ...}.
Returns a map from source unit name to its CLDR base unit string.
Returns
- A map such as
%{"foot" => "meter", "newton" => "kilogram-meter-per-square-second", ...}.
@spec deprecated_unit_identifiers() :: [String.t()]
Returns all deprecated CLDR unit identifiers.
Returns
- A list of strings.
@spec power_components() :: [String.t()]
Returns the list of power components.
Returns
- A list of strings such as
["square", "cubic", "pow2", ...].
@spec prefix_components() :: [String.t()]
Returns the list of unit ID prefix components.
Returns
- A list of strings such as
["arc", "british", "dessert", ...].
@spec si_prefix_data() :: [ %{ type: String.t(), symbol: String.t(), power10: String.t(), power2: String.t() }, ... ]
Returns detailed SI prefix data including symbols and powers.
Returns
- A list of maps with keys
:type,:symbol,:power10, and:power2.
Returns SI prefix multipliers as a map of prefix name to numeric multiplier.
Returns
- A map such as
%{"kilo" => 1000.0, "milli" => 0.001, ...}.
@spec si_prefix_names() :: [String.t()]
Returns the list of SI prefix names.
Returns
- A list of strings such as
["kilo", "milli", "mega", ...].
@spec simple_base_units() :: [String.t()]
Returns the list of fundamental (simple) base units.
These are the units with status='simple' in the CLDR unitQuantities
data and form the atoms of the dimensional decomposition system.
Returns
- A list of strings such as
["candela", "kilogram", "meter", "second", ...].
@spec suffix_components() :: [String.t()]
Returns the list of unit ID suffix components.
Returns
- A list of strings such as
["force", "imperial", ...].
Returns the resolved unit constants as a map of name to float value.
Returns
- A map such as
%{"ft_to_m" => 0.3048, "lb_to_kg" => 0.45359237, ...}.
@spec unit_preferences() :: [ %{category: String.t(), usage: String.t(), preferences: [map(), ...]}, ... ]
Returns the CLDR unit preference data.
Each entry specifies preferred units for a category/usage/region combination.
Returns
- A list of maps with keys
:category,:usage, and:preferences.
@spec valid_unit_identifiers() :: [String.t()]
Returns all valid CLDR unit identifiers with regular status.
Returns
- A list of strings such as
["length-kilometer", "mass-kilogram", ...].