app.unit

Unit conversion utility. This help us convert unit (as example dp to px) easily.

Constants#

NameTypeDescription
TypesobjectUnit constants. We use this for parameters of app.unit.convert

Methods#

NameReturn TypeDescription
convertnumberScale a number based on two units.
resolvenumberResolve unit suffix of a string then convert it to px.

convert#

app.unit.convert(value, fromUnit, toUnit?);

Scale a number based on two units. If toUnit ignored, then destination unit assumed as px.

Parameters:

  1. value: (number type) a Number to be converted
  2. fromUnit: (number type) Unit of value. Use app.unit.Types.* for this parameter.
  3. toUnit: (number type, Optional) Unit of result. Use app.unit.Types.* for this parameter.

Return: number


resolve#

app.unit.resolve(value, percentFactor?);

Resolve unit suffix of a string then convert it to px. However, if the value is number then returns that value.

Parameters:

  1. value: (string or number type) a String that contains number with unit or just a plain number.
  2. percentFactor: (number type, Optional) This parameter tells "100%" is equals what pixels. If ignored, then "100%" == "100px".

Return: number