unit-converter-package-roshan
v1.0.0
Published
Simple unit conversion utilities
Maintainers
Readme
unit-converter-package-roshan
A lightweight, type-safe unit conversion utility for JavaScript and TypeScript projects.
Supports length and temperature conversions with zero dependencies and full tree-shaking support.
✨ Features
- 📏 Length conversion (
cm,m,km) - 🌡️ Temperature conversion (
celsius,fahrenheit,kelvin) - ⚡ Fast and lightweight
- 🧠 Fully typed (TypeScript)
- 🌳 Tree-shakeable
- 🚫 No external dependencies
- 🧪 Tested with Jest
📦 Installation
npm install unit-converter-package-roshanor
yarn add unit-converter-package-roshan🚀 Usage
Importing
import {
convertLength,
convertTemperature,
LengthUnit,
TemperatureUnit
} from "unit-converter-package-roshan";📏 Length Conversion
Supported Units
cmmkm
Example
convertLength(100, "cm", "m"); // 1
convertLength(2, "km", "m"); // 2000
convertLength(1500, "m", "km"); // 1.5Type Safety
const unit: LengthUnit = "cm"; // ✅
const wrongUnit: LengthUnit = "mm"; // ❌ TypeScript error🌡️ Temperature Conversion
Supported Units
celsiusfahrenheitkelvin
Example
convertTemperature(0, "celsius", "fahrenheit"); // 32
convertTemperature(32, "fahrenheit", "celsius"); // 0
convertTemperature(0, "celsius", "kelvin"); // 273.15Floating Point Precision
For temperature conversions, floating-point math is used. Use rounding if required:
const value = convertTemperature(32, "fahrenheit", "kelvin");
value.toFixed(2); // "273.15"🧠 API Reference
convertLength
convertLength(
value: number,
from: LengthUnit,
to: LengthUnit
): numberconvertTemperature
convertTemperature(
value: number,
from: TemperatureUnit,
to: TemperatureUnit
): number🧪 Testing
This package is tested using Jest.
npm test🌳 Tree Shaking
This package uses ES Modules and supports tree-shaking:
import { convertLength } from "unit-converter-package-roshan";Unused functions are excluded from the final bundle.
🛠️ Built With
- TypeScript
- Jest
- Zero runtime dependencies
🧩 Roadmap
Planned enhancements:
- Weight units (
g,kg,lb) - Time units (
s,min,hr) - Speed units (
m/s,km/h) - Chainable API
- Optional rounding helpers
🤝 Contributing
Pull requests are welcome.
- Fork the repository
- Create a feature branch
- Add tests for your changes
- Submit a pull request
📄 License
MIT License © Roshan
