Simple unit conversion utilities
npm install unit-converter-package-roshanA lightweight, type-safe unit conversion utility for JavaScript and TypeScript projects.
Supports length and temperature conversions with zero dependencies and full tree-shaking support.
---
- ๐ Length conversion (cm, m, km)
- ๐ก๏ธ Temperature conversion (celsius, fahrenheit, kelvin)
- โก Fast and lightweight
- ๐ง Fully typed (TypeScript)
- ๐ณ Tree-shakeable
- ๐ซ No external dependencies
- ๐งช Tested with Jest
---
``bash``
npm install unit-converter-package-roshan
or
`bash`
yarn add unit-converter-package-roshan
---
`ts`
import {
convertLength,
convertTemperature,
LengthUnit,
TemperatureUnit
} from "unit-converter-package-roshan";
---
* cmm
* km
*
`ts`
convertLength(100, "cm", "m"); // 1
convertLength(2, "km", "m"); // 2000
convertLength(1500, "m", "km"); // 1.5
`ts`
const unit: LengthUnit = "cm"; // โ
const wrongUnit: LengthUnit = "mm"; // โ TypeScript error
---
* celsiusfahrenheit
* kelvin
*
`ts`
convertTemperature(0, "celsius", "fahrenheit"); // 32
convertTemperature(32, "fahrenheit", "celsius"); // 0
convertTemperature(0, "celsius", "kelvin"); // 273.15
For temperature conversions, floating-point math is used.
Use rounding if required:
`ts`
const value = convertTemperature(32, "fahrenheit", "kelvin");
value.toFixed(2); // "273.15"
---
`ts`
convertLength(
value: number,
from: LengthUnit,
to: LengthUnit
): number
---
`ts`
convertTemperature(
value: number,
from: TemperatureUnit,
to: TemperatureUnit
): number
---
This package is tested using Jest.
`bash`
npm test
---
This package uses ES Modules and supports tree-shaking:
`ts`
import { convertLength } from "unit-converter-package-roshan";
Unused functions are excluded from the final bundle.
---
* TypeScript
* Jest
* Zero runtime dependencies
---
Planned enhancements:
* Weight units (g, kg, lb)s
* Time units (, min, hr)m/s
* Speed units (, km/h`)
* Chainable API
* Optional rounding helpers
---
Pull requests are welcome.
1. Fork the repository
2. Create a feature branch
3. Add tests for your changes
4. Submit a pull request
---
MIT License ยฉ Roshan
---