Members
dimension :string
- Source:
Dimension of this Quantity, e.g. [L]
for metres or [L]²
for cubic-metres
Type:
- string
unit :string|null
- Source:
Unit of this Quantity, e.g. Metre
, or null
if not available
Type:
- string | null
symbol :string|null
- Source:
Unit symbol of this Quantity, e.g. m
, or null
if not available
Type:
- string | null
float :number
- Source:
Float (decimal number) value of this Quantity
Type:
- number
int :number
- Source:
Integer (non-decimal number) value of this Quantity
Type:
- number
Methods
add(value) → {Quantity}
- Source:
Add the given value to this Quantity.
Parameters:
Name | Type | Description |
---|---|---|
value |
Item | string | Quantity | Quantity-compatible |
Returns:
result as new Quantity
- Type
- Quantity
divide(value) → {Quantity}
- Source:
Divide this Quantity by the given value.
Example
Quantity('20 W').divide(4); // is 5 W
Quantity('20 W').divide('4 W') // is 5
Parameters:
Name | Type | Description |
---|---|---|
value |
Item | number | string | Quantity | usually a number; may also be an |
Returns:
result as new Quantity
- Type
- Quantity
multiply(value) → {Quantity}
- Source:
Multiply this Quantity by the given value.
Example
Quantity('20 W').multiply(4); // is 80 W
Quantity('20 W').multiply('4 W') // is 80 W^2
Parameters:
Name | Type | Description |
---|---|---|
value |
Item | number | string | Quantity | usually a number; may also be an |
Returns:
result as new Quantity
- Type
- Quantity
subtract(value) → {Quantity}
- Source:
Subtract the given value from this Quantity.
Parameters:
Name | Type | Description |
---|---|---|
value |
Item | string | Quantity | Quantity-compatible |
Returns:
result as new Quantity
- Type
- Quantity
toUnit(unit) → {Quantity|null}
- Source:
Convert this Quantity to the given unit.
Parameters:
Name | Type | Description |
---|---|---|
unit |
string |
Throws:
-
when unit cannot be parsed because it is invalid
- Type
- QuantityError
Returns:
a new Quantity with the given unit or null
if conversion to this unit is not possible
- Type
- Quantity | null
equal(value) → {boolean}
- Source:
Checks whether this Quantity is equal to the passed in value.
Parameters:
Name | Type | Description |
---|---|---|
value |
Item | string | Quantity | Quantity-compatible |
Returns:
- Type
- boolean
greaterThan(value) → {boolean}
- Source:
Checks whether this Quantity is larger than the passed in value.
Parameters:
Name | Type | Description |
---|---|---|
value |
Item | string | Quantity | Quantity-compatible |
Returns:
- Type
- boolean
greaterThanOrEqual(value) → {boolean}
- Source:
Checks whether this Quantity is larger than or equal to the passed in value.
Parameters:
Name | Type | Description |
---|---|---|
value |
Item | string | Quantity | Quantity-compatible |
Returns:
- Type
- boolean
lessThan(value) → {boolean}
- Source:
Checks whether this Quantity is smaller than the passed in value.
Parameters:
Name | Type | Description |
---|---|---|
value |
Item | string | Quantity | Quantity-compatible |
Returns:
- Type
- boolean
lessThanOrEqual(value) → {boolean}
- Source:
Checks whether this Quantity is smaller than or equal to the passed in value.
Parameters:
Name | Type | Description |
---|---|---|
value |
Item | string | Quantity | Quantity-compatible |
Returns:
- Type
- boolean