LitDev Extension API
LDUnits
A general editable unit conversion system.
All units and dimensions are case sensitive.
A base unit consists of a single dimension and name, and are all independent.
A derived unit consists of a description, name and units definition consisting of base or other derived units, and optional additive term, usually 0.
A unit is parsed by separting . / + - and *, then recursively resolving derived unit conversions, bracketed () terms first.
Values (especially those with a decimal point '.' or minus '-') should be contained in ().
A unit may be prefixed by a prefix or number value (e.g. m is mili 0.001, K is kilo 1000 etc).
Any unit may be postfixed by a power.
A typical unit may be "mile/hr", "m/s2" or "MJ/day" etc and can be any combination of base and derived units.
Any pair of unis that are dimensionally the same can be converted.
An additive value is only used for non-compound unit conversions (e.g. C to F).
To avoid obscure prefix unit conflicts use a full prefix name (e.g. min could be 60 seconds or 0.001 inches, the latter should be milliin).
Currency conversions are updated daily.
AddBaseUnit | AddConstant | AddDerivedUnit |
Convert | Export | GetBaseUnits |
GetConstants | GetDerivedUnits | GetDimensions |
GetErrors | GetPrefixes | Import |
AddBaseUnit(dimension,name)
Add a base unit to the system.
dimension The base unit dimension (e.g. TEMPERATURE).
name The unit name (be careful it doesn't confict with existing unit names).
AddConstant(description,name,value)
Add a dimensionless constant to the system.
description An optional long name or description of the constant.
name The constant name (be careful it doesn't confict with existing constant names).
value The derived constant value.
AddDerivedUnit(description,name,units,add)
Add a derived unit to the system.
description An optional long name or description of the derived unit.
name The unit name (be careful it doesn't confict with existing unit names).
units The derived unit definition.
add An optional addition term.
Convert(value,fromUnit,toUnit)
Convert a value from one unit to another.
value The value to convert.
fromUnit The units to convert from.
toUnit The units to convert to.
returns The converted value or "FAILED" (usually non-existant unit or inconsistant dimensions).
Export()
Export the current unit system to a file (units.txt in the current program folder).
GetBaseUnits()
Get a list of current base units.
returns An array of available base units, indexed by unit dimension.
The array values are the base unit names.
GetConstants()
Get a list of current constants.
returns An array of available constants, indexed by constant name with (description).
The array values are the constant values.
GetDerivedUnits()
Get a list of current derived units.
returns An array of available derived units, indexed by unit name with (description).
The array values are the base (or derived units) used for conversion.
GetDimensions(unit)
Get an array of dimensions for a unit.
unit The unit to get dimensins of.
returns An array indexed by dimension and value of the dimension power or "".
GetErrors()
Get an array of error messages if a Convert fails or conflicts are found for added units or constants.
returns Array of error messages or "".
GetPrefixes()
Get a list of current prefixes.
returns An array of available prefices, indexed by prefix name.
The array value is the prefix value.
Import()
Import a unit system from a file (units.txt in the current program folder).