Module: units

Tools for working with units.

License:
  • MIT
Source:

Interfaces

ElementContainer

Methods

(static) convertAttrs(element) → {void}

Converts all applicable attributes to the configured baseUnit.

Parameters:
Name Type Description
element Element

A DOM element whose attributes should be converted

Source:
Returns:
Type
void

(static) convertToNum(attr, val) → {Float}

Converts given values to numbers. Attributes must be supplied in case a percentage is given.

Parameters:
Name Type Description
attr string

Name of the attribute associated with the value

val string

Attribute value to convert

Source:
Returns:

The converted number

Type
Float

(static) convertUnit(val, unitopt) → {Float}

Converts the number to given unit or baseUnit.

Parameters:
Name Type Attributes Description
val string | Float
unit "em" | "ex" | "in" | "cm" | "mm" | "pt" | "pc" | "px" | "%" <optional>
Source:
Returns:
Type
Float

(static) getTypeMap() → {module:units.TypeMap}

Source:
Returns:

The unit object with values for each unit

Type
module:units.TypeMap

(static) init(elementContainer) → {void}

Initializes this module.

Parameters:
Name Type Description
elementContainer module:units.ElementContainer

An object implementing the ElementContainer interface.

Source:
Returns:
Type
void

(static) isValidUnit(attr, val, selectedElement) → {boolean}

Check if an attribute's value is in a valid format.

Parameters:
Name Type Description
attr string

The name of the attribute associated with the value

val string

The attribute value to check

selectedElement Element
Source:
Returns:

Whether the unit is valid

Type
boolean

(static) setUnitAttr(elem, attr, val) → {void}

Sets an element's attribute based on the unit in its current value.

Parameters:
Name Type Description
elem Element

DOM element to be changed

attr string

Name of the attribute associated with the value

val string

Attribute value to convert

Source:
Returns:
Type
void

(static) shortFloat(val) → {Float|string}

Rounds a given value to a float with number of digits defined in round_digits of saveOptions

Parameters:
Name Type Description
val string | Float | module:units.CompareNumbers

The value (or Array of two numbers) to be rounded

Source:
Returns:

If a string/number was given, returns a Float. If an array, return a string with comma-separated floats

Type
Float | string

Type Definitions

CompareNumbers

Type:
Properties:
Name Type Description
length Integer

2

0 Float
1 Float
Source:

TypeMap

Type:
Properties:
Name Type Description
em Float
ex Float
in Float
cm Float
mm Float
pt Float
pc Float
px Integer
% 0
Source: