measure-x
Version:
A lightweight and efficient **conversion utility** that supports various **number system conversions**, unit conversions, and more. 🚀
13 lines (11 loc) • 465 B
text/typescript
import { Converter } from "../../utils/converters";
import { WEIGHT_CONVERSION } from "./constants";
import { WeightUnit } from "./type";
export const weightConverter: Converter = {
category: "length",
units: Object.keys(WEIGHT_CONVERSION) as WeightUnit[],
convert: (value: number, from: string, to: string): number => {
const baseValue = value * WEIGHT_CONVERSION[from as WeightUnit];
return baseValue / WEIGHT_CONVERSION[to as WeightUnit];
},
};