A highly modular unit conversion library.
For full API docs, visit https://units.js.org
yarn add @stak-digital/units
- OR -
npm install --save @stak-digital/units
The library is split into three tiers:
- Library (index.js)
- Conversion category (weight.js, length.js)
- Individual function (poundsToKilograms.js)
import units from '@stak-digital/units';
const amountInPounds = 60;
const amountInKilograms = units.poundsToKilograms(amountInPounds);
// 27.2155
const amountInInches = 30;
const amountInMeters = units.inchesToMeters(amountInInches);
// 0.762
import convertWeight from '@stak-digital/units/weight';
import convertLength from '@stak-digital/units/length';
const amountInPounds = 60;
const amountInKilograms = convertWeight.poundsToKilograms(amountInPounds);
// 27.2155
const amountInInches = 30;
const amountInMeters = convertLength.inchesToMeters(amountInInches);
// 0.762
import poundsToKilograms from '@stak-digital/units/pounds-to-kilograms';
import inchesToMeters from '@stak-digital/units/inches-to-meters';
const amountInPounds = 60;
const amountInKilograms = poundsToKilograms(amountInPounds);
// 27.2155
const amountInInches = 30;
const amountInMeters = inchesToMeters(amountInInches);
// 0.762
- Acres (ac)
- Hectares (ha)
- Square Feet (ft²)
- Square Kilometers (km²)
- Square Meters (m²)
- Square Yards (yd²)
- Kelvin (K)
- Celsius (˚C)
- Fahrenheit (˚F)
- Rankine (˚R)
- bit
- byte
- kilobit
- kilobyte
- megabit
- megabyte
- gigabit
- gigabyte
- terabit
- terabyte
- petabit
- petabyte
- Feet (ft)
- Meters (m)
- Inches (in)
- Days
- Hours
- Minutes
- Seconds
- Milliseconds
- Microseconds
- Nanoseconds
- Kilograms
- Pounds
- Stones
- Tonnes
- Hertz (Hz)
- Kilohertz (kHz)
- Megahertz (mHz)
- Gigahertz (gHz)
- Revolutions per minute (rpm)
- newton (N)
- dyne (dyn)
- kilopond (kp)
- poundal (pdl)
- pound-force (lbf)
- ounce-force (ozf)
- If the unit belongs to an existing category, add the unit to that category; otherwise
- Create a new category file in
./src/data/
- Each category should have a name and units array
- Create a new category file in
- If the unit exists already, add your desired conversion in the
convertTo
property; otherwise- Create a new unit under the category with a name, symbol and convert to property. Each unit should have at least one convertTo
- Additionally, a convertTo needs to have a respective unit in the given category to allow interoperability between the units (see below)
{
"units": [
{
"name": "fahrenheit",
"symbol": "F",
"convertTo": {
"celsius": {
"formula": "(n - 32) * (5/9)",
"nEqualsOne": -17.22222222222222
}
}
},
{
"name": "celsius",
"symbol": "C",
"convertTo": {
"fahrenheit": {
"formula": "(n * (9/5)) + 32",
"nEqualsOne": 33.8
}
}
}
]
}
- Each conversion must have a formula property where the input unit is represented by
n
and an nEqualsOne value which represents the return value when an input of1
is put through the formula.
- Convert existing functions into json version
- Add expand collapse to each category in the sub-nav and main of docs site
- Add roadmap to docs site
- add typescript typings
- Radian (rad)
- Degree (deg)
- Arcminute (amin)
- Arcsecond (asec)
- Cubic meter (m^3)
- liters (L)
- milliliters (mL)
- cubic feet (cu ft)
- cubic inches (cu in)
- gallons (gal)
- quarts (qt)
- pints (pt)
- fluid ounces (fl oz)
- tablespoons (tbsp)
- teaspoons (tsp)
- meters per second (m/s)
- mile per hour (mph)
- kilometer per hour (km/h)
- feet per second (fps)
- knot (kn)
- speed of light (c)
- speed of sound (s)
- Kilometers per liter (km/L)
- miles per gallon (mi/gal)
- liter per 100 kilometers (L/100km)
- gallons per 100 miles (gal/100mi)
- kilograms per cubic meter (kg/m^3)
- kilograms per liter (kg/L)
- grams per cubic centimeter (g/cm^3)
- ounces per cubic foot (oz/ft^3)
- ounces per cubic inch (oz/in^3)
- pounds per cubic foot (lb/ft^3)
- pounds per cubic inch (lb/in^3)
- ounces per gallon (oz/gal)
- pounds per gallon (lb/gal)
- cubic meters per second (m^3/s)
- liters per minute (L/min)
- gallons per minute (gal/min)
- cubic meters per hour (m^3/h)
- Meters per second squared (m/s^2)
- galileo (Gal)
- standard gravity (g)
- mile per hour per second (mph/s)
- knot per second (kn/s)
- pascal (Pa)
- pounds per square inch (psi)
- atmosphere (atm)
- bar (bar)
- millibar (mbar)
- millimeter of mercury (mmHg)
- kilopascal (kPa)
- megapascal (MPa)
- Foot-pound (ft·lbf)
- Inch-pound (in·lbf)
- Newton meter (N·m)
- Kilopond-meter (kp·m)
- joule (J)
- erg (erg)
- kilowatt-hour (kW·h)
- megawatt-hour (MW·h)
- calorie (cal)
- kilocalorie (kcal)
- British thermal unit (Btu)
- pascal seconds (Pa·s)
- poise (P)
- pounds per foot hour (lb/(ft·h))
- pounds per foot second (lb/(ft·s))
- ampere (A)
- abampere (abA)
- statampere (statA)
- coulomb (C)
- abcoulomb (abC)
- statcoulomb (statC)
- faraday (F)
- milliampere hour (mA·h)
- volt (V)
- abvolt (abV)
- statvolt (statV)
- candela per square meter (cd/m^3)
- stilb (sb)
- lambert (L)
- footlambert (fL)
- lux (lx)
- phot (ph)
- footcandle (fc)
- gray (Gy)
- rad (rad)
- sievert (Sv)
- rem (rem)
- becquerel (Bq)
- curie (Ci)
- rutherford (rd)
- bit per second (bit/s)
- kilobit per second (kbit/s)
- kilobyte per second (kB/s)
- kibibit per second (Kibit/s)
- megabit per second (Mbit/s)
- megabyte per second (MB/s)
- mebibit per second (Mibit)
- Gigabit per second (Gbit/s)
- Gigabyte per second (GB/s)
- Gibibit per second (Gibit/s)
- Terabit per second (Tbit/s)
- Terabyte per second (TB/s)
- Tebibit per second (Tibit/s)
- Petabit per second (Pbit/s)
- Petabyte per second (PB/s)
- Pebibit per second (Pibit/s)
- Convert to TypeScript
- Add frequency category
- Update docs site with accordions on sections
- Add support for microseconds and nanoseconds
- Add full support for weight units
- Add support for major computer data units
- Add support for square meters
- Add support for square feet
- Add support for square kilometers
- Add support for hectares
- Add styles to docs site and update internal links
- Update development documentation
- Update docs site https://units.js.org
- Add support for Kelvin, Fahrenheit and Celsius conversions
- Add poundsToTonnes function
- Add tonnesToPounds function
- Update docs site
- Replace docs with link to js.org
- Add dynamic docs generation
- Add documentation for time functions
- Add codecov integration
- Add travis-ci integration
- add time functions to time.js
- add millisecondsToSeconds function
- add millisecondsToMinutes function
- add millisecondsToHours function
- add millisecondsToDays function
- add secondsToMilliseconds function
- add minutesToMilliseconds function
- add hoursToMilliseconds function
- add daysToMilliseconds function
- Add stonesToPounds function
- Add poundsToStones function