This module provides SiType enumeration and utilities for working with it.
The SiType enumeration consists of a set of predefined values representing
various units of measurement according to the International System of Units (SI).
The module also provides functions for parsing, stringifying, and checking
the validity of these values.
Once you have imported the SiType enumeration, you can use the constants it
defines in your code. For example, you could use the SiType.KILO constant in
a function like this:
functionconvertToKilometers (distanceInMeters: number): number { returndistanceInMeters / 1000; } consttranslations = { [SiType.KILO]:"kilometers", // ...add more translations for other SiType values as needed }; constdistanceInKilometers = convertToKilometers(5000); // 5 console.log(`The distance is ${distanceInKilometers}${translations[SiType.KILO]}.`); // The distance is 5 kilometers. *
// Check if a value is a valid SiType if (isSiType(SiType.MEGA)) { console.log("This is a valid SiType value."); } else { console.log("This is not a valid SiType value."); }
// Convert an SiType value to a string constsiTypeString = stringifySiType(SiType.MEGA); // "MEGA"
// Parse a value into an SiType constsiTypeValue = parseSiType("mega"); // SiType.MEGA
Overview
This module provides
SiType
enumeration and utilities for working with it.The
SiType
enumeration consists of a set of predefined values representing various units of measurement according to the International System of Units (SI).The module also provides functions for parsing, stringifying, and checking the validity of these values.
Using the SiType Enumeration
To use the
SiType
enumeration in your code, you will first need to import it from the module that defines it.You can do this by adding the following line at the top of your file:
Once you have imported the SiType enumeration, you can use the constants it defines in your code. For example, you could use the SiType.KILO constant in a function like this:
Using the Utility Functions
The module provides three utility functions that you can use to work with
SiType
values:isSiType
,stringifySiType
, andparseSiType
.Here's an example of how you might use these functions in your code: