Lightweight Full-featured Unit Conversion Library – convert.js

Category: Javascript , Recommended | September 25, 2022
Author:jonahsnider
Views Total:38 views
Official Page:Go to website
Last Update:September 25, 2022
License:MIT

Preview:

Lightweight Full-featured Unit Conversion Library – convert.js

Description:

A tiny yet full-featured unit (angle, area, data, force, length, mass, pressure, temperature, and time) conversion library written in javascript (Typescript).

Supported Units:

  • “square meter”, “square meters”, “square metre”, “square metres”, “m²”, “m2”, “square petameter”, “square petametre”, “square petameters”, “square petametres”, “Pm²”, “Pm2”, “square terameter”, “square terametre”, “square terameters”, “square terametres”, “Tm²”, “Tm2”, “square gigameter”, “square gigametre”, “square gigameters”, “square gigametres”, “Gm²”, “Gm2”, “square megameter”, “square megametre”, “square megameters”, “square megametres”, “Mm²”, “Mm2”, “square kilometer”, “square kilometre”, “square kilometers”, “square kilometres”, “km²”, “km2”, “square hectometer”, “square hectometre”, “square hectometers”, “square hectometres”, “hm²”, “hm2”, “square decameter”, “square decametre”, “square decameters”, “square decametres”, “dam²”, “dam2”, “square decimeter”, “square decimetre”, “square decimeters”, “square decimetres”, “dm²”, “dm2”, “square centimeter”, “square centimetre”, “square centimeters”, “square centimetres”, “cm²”, “cm2”, “square millimeter”, “square millimetre”, “square millimeters”, “square millimetres”, “mm²”, “mm2”, “square micrometer”, “square micrometre”, “square micrometers”, “square micrometres”, “μm²”, “μm2”, “square nanometer”, “square nanometre”, “square nanometers”, “square nanometres”, “nm²”, “nm2”, “square picometer”, “square picometre”, “square picometers”, “square picometres”, “pm²”, “pm2”, “square femtometer”, “square femtometre”, “square femtometers”, “square femtometres”, “fm²”, “fm2”, “acre”, “acres”, “ac”, “centiare”, “centiares”, “ca”, “deciare”, “deciares”, “da”, “are”, “ares”, “decare”, “decares”, “daa”, “hectare”, “hectares”, “ha”, “square foot”, “square feet”, “sq ft”, “square inch”, “square inches”, “sq in”, “square yard”, “square yards”, “sq yd”, “square mile”, “square miles”, “sq mi”
  • “bit”, “bits”, “b”, “pebibit”, “pebibits”, “Pib”, “tebibit”, “tebibits”, “Tib”, “gibibit”, “gibibits”, “Gib”, “mebibit”, “mebibits”, “Mib”, “kibibit”, “kibibits”, “Kib”, “petabit”, “petabits”, “Pb”, “terabit”, “terabits”, “Tb”, “gigabit”, “gigabits”, “Gb”, “megabit”, “megabits”, “Mb”, “kilobit”, “kilobits”, “kb”, “hectobit”, “hectobits”, “hb”, “decabit”, “decabits”, “dab”, “decibit”, “decibits”, “db”, “centibit”, “centibits”, “cb”, “millibit”, “millibits”, “mb”, “microbit”, “microbits”, “μb”, “nanobit”, “nanobits”, “nb”, “picobit”, “picobits”, “pb”, “femtobit”, “femtobits”, “fb”, “nibble”, “nibbles”, “semioctet”, “semioctets”, “halfbyte”, “halfbytes”, “byte”, “bytes”, “octect”, “octects”, “B”, “pebibyte”, “pebibytes”, “PiB”, “tebibyte”, “tebibytes”, “TiB”, “gibibyte”, “gibibytes”, “GiB”, “mebibyte”, “mebibytes”, “MiB”, “kibibyte”, “kibibytes”, “KiB”, “petabyte”, “petabytes”, “PB”, “terabyte”, “terabytes”, “TB”, “gigabyte”, “gigabytes”, “GB”, “megabyte”, “megabytes”, “MB”, “kilobyte”, “kilobytes”, “kB”, “hectobyte”, “hectobytes”, “hB”, “decabyte”, “decabytes”, “daB”, “decibyte”, “decibytes”, “dB”, “centibyte”, “centibytes”, “cB”, “millibyte”, “millibytes”, “mB”, “microbyte”, “microbytes”, “μB”, “nanobyte”, “nanobytes”, “nB”, “picobyte”, “picobytes”, “pB”, “femtobyte”, “femtobytes”, “fB”, “hextet”, “hextets”
  • “newton”, “newtons”, “N”, “dyne”, “dynes”, “dyn”, “kilogram-force”, “kgf”, “kilopond”, “kiloponds”, “kp”, “pound of force”, “pound-force”, “lbf”, “poundal”, “poundals”, “pdl”
  • “meter”, “meters”, “metre”, “metres”, “m”, “petameter”, “petametre”, “petameters”, “petametres”, “Pm”, “terameter”, “terametre”, “terameters”, “terametres”, “Tm”, “gigameter”, “gigametre”, “gigameters”, “gigametres”, “Gm”, “megameter”, “megametre”, “megameters”, “megametres”, “Mm”, “kilometer”, “kilometre”, “kilometers”, “kilometres”, “km”, “hectometer”, “hectometre”, “hectometers”, “hectometres”, “hm”, “decameter”, “decametre”, “decameters”, “decametres”, “dam”, “decimeter”, “decimetre”, “decimeters”, “decimetres”, “dm”, “centimeter”, “centimetre”, “centimeters”, “centimetres”, “cm”, “millimeter”, “millimetre”, “millimeters”, “millimetres”, “mm”, “micrometer”, “micrometre”, “micrometers”, “micrometres”, “μm”, “nanometer”, “nanometre”, “nanometers”, “nanometres”, “nm”, “picometer”, “picometre”, “picometers”, “picometres”, “pm”, “femtometer”, “femtometre”, “femtometers”, “femtometres”, “fm”, “foot”, “feet”, “ft”, “‘”, “inch”, “inches”, “in”, “\””, “yard”, “yards”, “yd”, “mile”, “miles”, “mi”, “nautical mile”, “nautical miles”, “M”, “NM”, “nmi”
  • “gram”, “grams”, “g”, “petagram”, “petagrams”, “Pg”, “teragram”, “teragrams”, “Tg”, “gigagram”, “gigagrams”, “Gg”, “megagram”, “megagrams”, “Mg”, “kilogram”, “kilograms”, “kg”, “hectogram”, “hectograms”, “hg”, “decagram”, “decagrams”, “dag”, “decigram”, “decigrams”, “dg”, “centigram”, “centigrams”, “cg”, “milligram”, “milligrams”, “mg”, “microgram”, “micrograms”, “μg”, “nanogram”, “nanograms”, “ng”, “picogram”, “picograms”, “pg”, “femtogram”, “femtograms”, “fg”, “tonne”, “tonnes”, “metric ton”, “metric tons”, “t”, “pound”, “pounds”, “lb”, “stone”, “stones”, “st”, “ounce”, “ounces”, “oz”, “℥”, “short ton”, “short tons”, “US ton”, “US tons”, “long ton”, “long tons”, “imperial ton”, “imperial tons”, “displacement ton”, “displacement tons”
  • “pascal”, “pascals”, “Pa”, “petapascal”, “petapascals”, “PPa”, “terapascal”, “terapascals”, “TPa”, “gigapascal”, “gigapascals”, “GPa”, “megapascal”, “megapascals”, “MPa”, “kilopascal”, “kilopascals”, “kPa”, “hectopascal”, “hectopascals”, “hPa”, “decapascal”, “decapascals”, “daPa”, “decipascal”, “decipascals”, “dPa”, “centipascal”, “centipascals”, “cPa”, “millipascal”, “millipascals”, “mPa”, “micropascal”, “micropascals”, “μPa”, “nanopascal”, “nanopascals”, “nPa”, “picopascal”, “picopascals”, “pPa”, “femtopascal”, “femtopascals”, “fPa”, “bar”, “bars”, “petabar”, “petabars”, “Pbar”, “terabar”, “terabars”, “Tbar”, “gigabar”, “gigabars”, “Gbar”, “megabar”, “megabars”, “Mbar”, “kilobar”, “kilobars”, “kbar”, “hectobar”, “hectobars”, “hbar”, “decabar”, “decabars”, “dabar”, “decibar”, “decibars”, “dbar”, “centibar”, “centibars”, “cbar”, “millibar”, “millibars”, “mbar”, “microbar”, “microbars”, “μbar”, “nanobar”, “nanobars”, “nbar”, “picobar”, “picobars”, “pbar”, “femtobar”, “femtobars”, “fbar”, “torr”, “torrs”, “Torr”, “millitorr”, “mTorr”, “atmosphere”, “atmospheres”, “atm”
  • kelvin”, “kelvins”, “K”, “petakelvin”, “petakelvins”, “PK”, “terakelvin”, “terakelvins”, “TK”, “gigakelvin”, “gigakelvins”, “GK”, “megakelvin”, “megakelvins”, “MK”, “kilokelvin”, “kilokelvins”, “kK”, “hectokelvin”, “hectokelvins”, “hK”, “decakelvin”, “decakelvins”, “daK”, “decikelvin”, “decikelvins”, “dK”, “centikelvin”, “centikelvins”, “cK”, “millikelvin”, “millikelvins”, “mK”, “microkelvin”, “microkelvins”, “μK”, “nanokelvin”, “nanokelvins”, “nK”, “picokelvin”, “picokelvins”, “pK”, “femtokelvin”, “femtokelvins”, “fK”, “fahrenheit”, “F”, “celsius”, “C”, “rankine”, “R”
  • “second”, “seconds”, “s”, “petasecond”, “petaseconds”, “Ps”, “terasecond”, “teraseconds”, “Ts”, “gigasecond”, “gigaseconds”, “Gs”, “megasecond”, “megaseconds”, “Ms”, “kilosecond”, “kiloseconds”, “ks”, “hectosecond”, “hectoseconds”, “hs”, “decasecond”, “decaseconds”, “das”, “decisecond”, “deciseconds”, “ds”, “centisecond”, “centiseconds”, “cs”, “millisecond”, “milliseconds”, “ms”, “microsecond”, “microseconds”, “μs”, “nanosecond”, “nanoseconds”, “ns”, “picosecond”, “picoseconds”, “ps”, “femtosecond”, “femtoseconds”, “fs”, “minute”, “minutes”, “min”, “hour”, “hours”, “h”, “milliday”, “millidays”, “md”, “day”, “days”, “d”, “week”, “weeks”, “wk”, “fortnight”, “fortnights”, “fn”, “month”, “months”, “mo”, “year”, “years”, “a”, “y”, “yr”, “decade”, “decades”, “dec”, “century”, “centuries”, “millennium”, “millennia”, “moment”, “moments”, “shake”, “shakes”, “time unit”, “TU”, “svedberg”, “svedbergs”, “S”
  • “cubic meter”, “cubic meters”, “cubic metre”, “cubic metres”, “stere”, “steres”, “m³”, “m3”, “cubic petameter”, “cubic petameters”, “Pm3”, “Pm³”, “cubic terameter”, “cubic terameters”, “Tm3”, “Tm³”, “cubic gigameter”, “cubic gigameters”, “Gm3”, “Gm³”, “cubic megameter”, “cubic megameters”, “Mm3”, “Mm³”, “cubic kilometer”, “cubic kilometers”, “km3”, “km³”, “cubic hectometer”, “cubic hectometers”, “hm3”, “hm³”, “cubic decameter”, “cubic decameters”, “dam3”, “dam³”, “cubic decimeter”, “cubic decimeters”, “dm3”, “dm³”, “cubic centimeter”, “cubic centimeters”, “cm3”, “cm³”, “cubic millimeter”, “cubic millimeters”, “mm3”, “mm³”, “cubic micrometer”, “cubic micrometers”, “μm3”, “μm³”, “cubic nanometer”, “cubic nanometers”, “nm3”, “nm³”, “cubic picometer”, “cubic picometers”, “pm3”, “pm³”, “cubic femtometer”, “cubic femtometers”, “fm3”, “fm³”, “liter”, “liters”, “litre”, “litres”, “l”, “L”, “petaliter”, “petaliters”, “petalitre”, “petalitres”, “Pl”, “PL”, “teraliter”, “teraliters”, “teralitre”, “teralitres”, “Tl”, “TL”, “gigaliter”, “gigaliters”, “gigalitre”, “gigalitres”, “Gl”, “GL”, “megaliter”, “megaliters”, “megalitre”, “megalitres”, “Ml”, “ML”, “kiloliter”, “kiloliters”, “kilolitre”, “kilolitres”, “kl”, “kL”, “hectoliter”, “hectoliters”, “hectolitre”, “hectolitres”, “hl”, “hL”, “decaliter”, “decaliters”, “decalitre”, “decalitres”, “dal”, “daL”, “deciliter”, “deciliters”, “decilitre”, “decilitres”, “dl”, “dL”, “centiliter”, “centiliters”, “centilitre”, “centilitres”, “cl”, “cL”, “milliliter”, “milliliters”, “millilitre”, “millilitres”, “ml”, “mL”, “microliter”, “microliters”, “microlitre”, “microlitres”, “μl”, “μL”, “nanoliter”, “nanoliters”, “nanolitre”, “nanolitres”, “nl”, “nL”, “picoliter”, “picoliters”, “picolitre”, “picolitres”, “pl”, “pL”, “femtoliter”, “femtoliters”, “femtolitre”, “femtolitres”, “fl”, “fL”, “cubic mile”, “cubic miles”, “cu mi”, “mi3”, “mi³”, “acre-foot”, “acre-feet”, “ac⋅ft”, “ac ft”, “cubic yard”, “cubic yards”, “cu yd”, “yd3”, “yd³”, “cubic foot”, “cubic feet”, “cu ft”, “ft3”, “ft³”, “board foot”, “board feet”, “cubic inch”, “cubic inches”, “cu in”, “in3”, “in³”, “measurement ton”, “measurement tons”, “MTON”, “imperial barrel”, “imperial barrels”, “imp bbl”, “imperial bushel”, “imperial bushels”, “imp bsh”, “imp bu”, “imperial peck”, “imperial pecks”, “pk”, “imp pk”, “imperial gallon”, “imperial gallons”, “imp gal”, “imperial quart”, “imperial quarts”, “imp qt”, “imperial pint”, “imperial pints”, “imp pt”, “imperial fluid ounce”, “imperial fluid ounces”, “imp fl oz”, “teaspoon”, “teaspoons”, “US teaspoon”, “US teaspoons”, “tsp”, “tablespoon”, “tablespoons”, “US tablespoon”, “US tablespoons”, “tbsp”, “US fluid ounce”, “US fluid ounces”, “fl oz”, “fl. oz.”, “oz. fl.”, “cup”, “cups”, “US legal cup”, “US legal cups”, “c”, “pint”, “pints”, “US liquid pint”, “US liquid pints”, “pt”, “p”, “quart”, “quarts”, “US liquid quart”, “US liquid quarts”, “qt”, “gallon”, “gallons”, “US liquid gallon”, “US liquid gallons”, “gal”, “US bushel”, “US bushels”, “US bsh”, “US bu”, “US peck”, “US pk”, “US dry gallon”, “US dry gal”, “US dry barrel”, “US dry barrels”, “US dry bbl”, “US dry quart”, “US dry qt”, “US dry pint”, “US dry pt”
  • “radian”, “radians”, “rad”, “rads”, “r”, “turn”, “turns”, “degree”, “degrees”, “deg”, “degs”, “°”, “gradian”, “gradians”, “gon”, “gons”, “grad”, “grads”, “grade”, “grades”

How to use it:

1. Install & import the Convert.

# Yarn
$ yarn add convert
# NPM
$ npm i convert
// ES Module
import convert from 'convert';
// CommonJS
const {convert} = require('convert');
// Browser
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/convert.prod.js"></script>

2. Convert a unit to another.

convert(480, 'seconds').to('minutes');
// -> 8
convert(20n, 'hours').to('minutes');
// -> 1200n
convert(6600, 'meters').to('best');
// -> { quantity: 6.6, unit: 'km', toString: () => '6.6km' }
convert(3.5, 'km').to('best', 'imperial');
// -> { quantity: 2.17, unit: 'mi', toString: () => '3.5mi' }

3. Convert multiple units.

// ES Module
import {convertMany} from 'convert';
// CommonJS
const {convertMany} = require('convert');
convertMany('1d 12h').to('hours')
// -> 95400000

4. Convert a given duration of milliseconds to a string.

// ES Module
import {ms} from 'convert';
// CommonJS
const {ms} = require('convert');
ms(-3 * 60000);
// -> '-3min'
ms('1d 2h 30min');
// -> 95400000

You Might Be Interested In:


Leave a Reply