When calling .to("best"), Convert returns an object containing the quantity, the unit, and a toString() method. You can optionally specify a unit system as the second argument to to(): either "metric" (default) or "imperial".
import convert from "convert";
// Convert into the best unit
const duration = convert(36, "h").to("best");
// -> { quantity: 1.5, unit: 'd', toString: () => '1.5 d' }
// The toString() method allows automatic casting to string
"duration is " + duration;
// -> "duration is 1.5 d"
// Specify unit system
convert(3.5, "km").to("best", "metric"); // -> { quantity: 3.5, unit: 'km', ... }
convert(3.5, "km").to("best", "imperial"); // -> { quantity: 2.17, unit: 'mi', ... }
import convert from "convert";
// Convert into the best unit
const duration = convert(36, "h").to("best");
// -> { quantity: 1.5, unit: 'd', toString: () => '1.5 d' }
// The toString() method means you can automatically cast the object to a string without any issues
"duration is " + duration;
// -> duration is 1.5d
// You can also specify to use a specific kind of units (metric or imperial, metric is default)
convert(3.5, "km").to("best"); // -> { quantity: 3.5, unit: 'km', toString: () => '3.5 km' }
convert(3.5, "km").to("best", "metric"); // -> { quantity: 3.5, unit: 'km', toString: () => '3.5 km' }
convert(3.5, "km").to("best", "imperial"); // -> { quantity: 2.17, unit: 'mi', toString: () => '3.5 mi' }