Skip to main content
Deno 2 is finally here 🎉️
Learn more

convert-pro

nest badge npm npm

GitHub issues GitHub forks GitHub stars GitHub license

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

Usage

// 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 = 3299.1732283464567 ft
convert.length([10, "FT", 100, "IN", 1, "KM"], "FT"); // => 3299.1732283464567

options

stringify

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

accuracy

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"

shortcut

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"

lowerCase

this option tels the function to use lower case letters

import convert from "convert-pro";

convert.mass("10 kg", "g", { lowerCase: true }); // => 1 kb

License

Copyright (c) 2021 AliBasicCoder