convert-pro is a package to convert between units that works on browser, node & deno
covers:
- temperature
- length
- area
- volume
- time
- mass
- energy
- frequency
- pressure
- degrees
- bytes
// on node (commonjs)
const { default: convert } = require("convert-pro");
// or (es6)
import convert from "convert-pro";
// on deno (replace version with current version)
import convert from "https://x.nest.land/convert-pro@version/mod.ts";
// or
import convert from "https://deno.land/x/convert_pro@version/mod.ts";
// convert from m2 to cm2
convert.area("10 m2", "cm2"); // => 100000
// convert from bit to MiB (1024 base)
convert.bytes([10 ** 15, "bit"], "MiB"); // => 119209289.55078125
// convert degrees to rad
convert.bytes(`10 d`, "r"); // => 0.17453
// convert multiple units
// 10 ft + 100 inch + 1 km + 1 ft = 3300.1732283464567 ft
convert.length([10, "FT", 100, "IN", 1, "KM", 1, "FT"], "FT"); // => 3300.1732283464567
// or
convert.length("10 ft 100 in 1 km", "ft"); // => 3299.1732283464567
- you could write
10.2d1.2'1.3''
or10.2°1.2'1.3''
(the numbers here could be replaced with other numbers) instead of10.2 d 1.2 arcminute 1.3 arcsecond
- you could use multiple units at once
- convert.degrees is the ONLY function allows number and unit names to be directly added together like
10radians
// examples
convert.degrees("10.2d1.2'1.3''", "radians"); // => 0.178378952
convert.degrees("10.2d1.2'1.3'' 10r", "radians"); // => 10.178378952
if true returns output in string (default: false)
example:
import convert from "convert-pro";
convert.length("1 m", "cm", { stringify: true }); // => "100 cm"
convert.length("1 m", "cm"); // => 100
this options is the accuracy of the size or how many digits are there after the dot
example:
import convert from "convert-pro";
convert.bytes("1024 byte", { accuracy: 0, stringify: true }); // => "1 KB"
this option tels the function to use the shortcuts or the words
example:
import convert from "convert-pro";
convert.area("100 m2", "cm2", { stringify: true, shortcut: false }); // => "1000000 Square Centimeters"
this option tels the function to use lower case letters
import convert from "convert-pro";
convert.mass("10 kg", "g", { lowerCase: true }); // => 1 kb
Copyright (c) 2021 AliBasicCoder