@oqton/utils-units
v1.2.1
Published
A library for parsing and formatting unit values.
Downloads
171
Keywords
Readme
@oqton/utils-units
A library for formatting unit values.
Basic Usage
import { Area, EUR, getUnitDefinition } from '@oqton/utils-units';
console.log(Area.formatAsString(200)); // '200 mm²'
console.log(EUR.formatAsString(123.456)); // '€ 123.46'
console.log(getUnitDefinition('MILLIMETER/SECOND^2').formatAsString(200)); // '200 mm/s²'
API
Table of Contents
- EUR
- CNY
- Units
- Amperes
- Celsius
- Count
- Decibels
- Degrees
- DegreesSecond
- DegreesSecondSquared
- Hertz
- Joules
- Kilograms
- Liters
- LitersSecond
- MicroRadians
- Millimeters
- MillimetersSecond
- MillimetersSecondSquared
- Millimeter3D
- Newtons
- NewtonMeters
- Ohms
- Pascals
- MegaPascals
- PascalSeconds
- Percent
- FractionalPercent
- PH
- RPM
- Seconds
- SiemensMeter
- Volts
- VoltAmperes
- VoltAmpereReactive
- Watts
- WattSeconds
- DateTime
- Milliseconds
- Other
- Length
- Area
- Volume
- formatCurrencyAsTokens
- formatCurrencyAsString
- formatTimeAsTokens
- formatTimeAsString
- formatDateTimeAsTokens
- formatDateTimeAsString
- formatDateAsTokens
- formatDateAsString
- formatDurationAsTokens
- formatDurationAsString
- formatNumberAsTokens
- formatNumberAsString
- formatPointAsTokens
- formatPointAsString
- CurrencyUnitDefinition
- DateTimeUnitDefinition
- DurationUnitDefinition
- NumberUnitDefinition
- PercentUnitDefinition
- PointUnitDefinition
EUR
EUR Currency
CNY
CNY Currency
Units
All the supported units.
Amperes
Amps
Celsius
Degrees Celsius
Count
A counted event
Decibels
Sound Level
Degrees
Angle in degrees
DegreesSecond
Angular degrees per second
DegreesSecondSquared
Angular acceleration in degrees per second squared
Hertz
Frequency measured in cycles per second
Joules
A measurement of energy
Kilograms
Kilograms
Liters
Liters
LitersSecond
Liters per second
MicroRadians
Measurement of Tilt
Millimeters
Millimeters
MillimetersSecond
Millimeters per second
MillimetersSecondSquared
Acceleration in millimeters per second squared
Millimeter3D
A point in space identified by X, Y, and Z positions and represented by a space-delimited set of numbers each expressed in millimeters.
Newtons
Force in Newtons
NewtonMeters
Torque, a unit for force times distance.
Ohms
Measure of Electrical Resistance
Pascals
Pressure in Newtons per square meter
MegaPascals
Pressure in Newtons per square millimeter
PascalSeconds
Measurement of Viscosity
Percent
Percentage
FractionalPercent
Fractional percentage
PH
A measure of the acidity or alkalinity of a solution
RPM
Revolutions per minute
Seconds
A measurement of time.
SiemensMeter
A measurement of Electrical Conductivity
Volts
Volts
VoltAmperes
Volt-Ampere (VA)
VoltAmpereReactive
Volt-Ampere Reactive (VAR)
Watts
Watts
WattSeconds
Measurement of electrical energy, equal to one Joule
DateTime
An ISO formatted Date /Time
Milliseconds
A measurement of time
Other
Unknown Units
Length
Length
Area
Area
Volume
Volume
formatCurrencyAsTokens
Format a currency amount as tokens.
Parameters
input
(null | undefined | number) The input to format.precision
(undefined | null | number)? The precision with which to format the input.symbol
(undefined | null | string)? The symbol to use.
Returns Array<FormatToken>
formatCurrencyAsString
Format a currency amount as string.
Parameters
input
(null | undefined | number) The input to format.precision
(undefined | null | number)? The precision with which to format the input.symbol
(undefined | null | string)? The symbol to use.
Returns string
formatTimeAsTokens
Format a time as tokens.
Parameters
input
(undefined | null | number | string | Date | Moment) The input to format.precision
TimePrecision The precision with which to format the input. (optional, defaultTIME_PRECISION.MINUTE
)
Returns Array<FormatToken>
formatTimeAsString
Format a time as a string.
Parameters
input
(undefined | null | number | string | Date | Moment) The input to format.precision
TimePrecision The precision with which to format the input. (optional, defaultTIME_PRECISION.MINUTE
)
Returns string
formatDateTimeAsTokens
Format a date-time as tokens.
Parameters
input
(undefined | null | number | string | Date | Moment) The input to format.precision
DateTimePrecision The precision with which to format the input. (optional, defaultTIME_PRECISION.MINUTE
)
Returns Array<FormatToken>
formatDateTimeAsString
Format a date-time as a string.
Parameters
input
(undefined | null | number | string | Date | Moment) The input to format.precision
DateTimePrecision The precision with which to format the input. (optional, defaultTIME_PRECISION.MINUTE
)
Returns string
formatDateAsTokens
Format a date as tokens.
Parameters
input
(undefined | null | number | string | Date | Moment) The input to format.precision
DateTimePrecision The precision with which to format the input. (optional, defaultDATE_TIME_PRECISION.DAY
)
Returns Array<FormatToken>
formatDateAsString
Format a date as a string.
Parameters
input
(undefined | null | number | string | Date | Moment) The input to format.precision
DateTimePrecision The precision with which to format the input. (optional, defaultDATE_TIME_PRECISION.DAY
)
Returns string
formatDurationAsTokens
Format a duration as tokens.
Parameters
Returns Array<FormatToken>
formatDurationAsString
Format a duration as a string.
Parameters
Returns string
formatNumberAsTokens
Format a number as tokens.
Parameters
input
(null | undefined | number | string) The input to format.precision
(undefined | null | number)? The precision with which to format the input.symbol
(undefined | null | string)? The symbol for the number.
Returns Array<FormatToken>
formatNumberAsString
Format a number as a string.
Parameters
input
(null | undefined | number | string) The input to format.precision
(undefined | null | number)? The precision with which to format the input.symbol
(undefined | null | string)? The symbol for the number.
Returns string
formatPointAsTokens
Format a point as tokens.
Parameters
input
(null | undefined | [number, number, number]) The input to format.precision
(undefined | null | number)? The precision with which to format the input.symbol
(undefined | null | string)? The symbol for the point.
Returns Array<FormatToken>
formatPointAsString
Format a point as a string.
Parameters
input
(null | undefined | [number, number, number]) The input to format.precision
(undefined | null | number)? The precision with which to format the input.symbol
(undefined | null | string)? The symbol for the point.
Returns string
CurrencyUnitDefinition
Extends UnitDefinition
Currency Unit Definition.
Parameters
config
CurrencyUnitDefinitionConfig
DateTimeUnitDefinition
Extends UnitDefinition
Date/Time Unit Definition.
DurationUnitDefinition
Extends UnitDefinition
Duration Unit Definition.
Parameters
config
DurationUnitDefinitionConfig
NumberUnitDefinition
Extends UnitDefinition
Numeric Unit Definition.
Parameters
config
NumberUnitDefinitionConfig
PercentUnitDefinition
Extends NumberUnitDefinition
Percentage Unit Definition.
PointUnitDefinition
Extends UnitDefinition
Point Unit Definition.