Module talk:Sandbox/Johnuniq/unit

The following demonstrates use of the _unit function exported from Module:Convert/sandbox.

Each ">" line shows the function call (renamed as unit) with parameters:

  • unitcode
  • options table (value for sort key; flags for linking, showing name instead of symbol, using US spelling of name)

The result line shows:

  • the unit symbol or name, optionally linked
  • "(unknown)" if convert did not recognize the unitcode
  • sort key based on value from converting input to a base unit (so 99 feet will sort before 1 kilometer)
> unit('kg')
                                      kg           

> unit('kg', {value=12.3, link=true})
                         [[Kilogram|kg]]           

> unit('m')
                                       m           

> unit('m', {value=-1, sort=on})
                                       m           <span data-sort-value="2999900000000000000♠"></span>

> unit('m', {value=12, link=true, sort=on})
                             [[Metre|m]]           <span data-sort-value="7001120000000000000♠"></span>

> unit('km', {link=true})
                        [[Kilometre|km]]           

> unit('ft', {value=99, link=true})
                      [[Foot (unit)|ft]]           

> unit('km3', {link=true})
      [[Cubic kilometre|km<sup>3</sup>]]           

> unit('km3', {value=12.3, name=true})
                        cubic kilometres           

> unit('km3', {value=12.3, link=true, name=true})
                    [[cubic kilometre]]s           

> unit('km3', {value=12.3, link=true, name=true, us=true})
    [[Cubic kilometre|cubic kilometers]]           

> unit('km3', {value=12.3, link=true, name=true, us=true, sort=on})
    [[Cubic kilometre|cubic kilometers]]           <span data-sort-value="7010123000000000000♠"></span>

> unit('foo')
                                     foo (unknown) 

> unit('foo', {link=true, sort=on})
                                 [[foo]] (unknown) <span data-sort-value="7000100000000000000♠"></span>

Start a discussion about improving the Module:Sandbox/Johnuniq/unit page

Start a discussion