new Unitz.Group(mainUnit, baseUnit, baseScale, units, singular, plural, denominators)
Instantiates a new unit group. A unit group is a single unit and all of it's aliases, singular & plural versions, and all valid denominators when converting to a fraction.
Name | Type | Description |
---|---|---|
mainUnit |
String |
The main unit for the group. This is typically the most common short version for the unit. |
baseUnit |
String |
The unit this group is calculated relative to. |
baseScale |
Number |
The value used to calculate between this group and the base group. |
units |
Array.<String> |
The aliases for this unit, each are valid ways to represent this group. These MUST be in lowercase form. |
singular |
String |
The singular unit (when a |value| is 1) to use. |
plural |
String |
The plural unit (when a |value| is not 1) to use. |
denominators |
Array.<Number> |
The denominators that are valid for this group. This is used so you don't see odd fractions that don't make sense for the given unit. |
- See:
Members
-
baseScaleNumber
-
The value used to calculate between this group and the base group.
-
baseUnitString
-
The unit this group is calculated relative to.
-
denominatorsArray.<Number>
-
The denominators that are valid for this group. This is used so you don't see odd fractions that don't make sense for the given unit.
-
pluralString
-
The plural unit (when a |value| is not 1) to use.
-
singularString
-
The singular unit (when a |value| is 1) to use.
-
unitString
-
The main unit for the group. This is typically the most common short version for the unit.
-
unitsArray.<String>
-
The aliases for this unit, each are valid ways to represent this group. These MUST be in lowercase form.
Methods
-
addUnit(x, abbreviations){String}
-
Adds the appropriate unit to the given number based on whether its a singular or plural value.
group.addUnit( 1 ); // '1 unit' group.addUnit( 2 ); // '2 units' group.addUnit( 0.5 ); // '0.5 units'
Name Type Default Description x
Number The number to add the appropriate unit to.
abbreviations
Boolean true optional Whether to return the abbrevation instead of the long units.
-
getUnit(x, abbreviations){String}
-
Gets the appropriate unit for the given number based on whether its a singular or plural value.
group.getUnit( 1 ); // 'unit' group.getUnit( 2 ); // 'units' group.getUnit( 0.5 ); // 'units'
Name Type Default Description x
Number The number to determine the appropriate unit for.
abbreviations
Boolean true optional Whether to return the abbrevation instead of the long units.
- See: