unit-converter-package-roshan 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Roshan Patil
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,186 @@
1
+ # unit-converter-package-roshan
2
+
3
+ A lightweight, type-safe unit conversion utility for JavaScript and TypeScript projects.
4
+
5
+ Supports **length** and **temperature** conversions with zero dependencies and full tree-shaking support.
6
+
7
+ ---
8
+
9
+ ## โœจ Features
10
+
11
+ - ๐Ÿ“ Length conversion (`cm`, `m`, `km`)
12
+ - ๐ŸŒก๏ธ Temperature conversion (`celsius`, `fahrenheit`, `kelvin`)
13
+ - โšก Fast and lightweight
14
+ - ๐Ÿง  Fully typed (TypeScript)
15
+ - ๐ŸŒณ Tree-shakeable
16
+ - ๐Ÿšซ No external dependencies
17
+ - ๐Ÿงช Tested with Jest
18
+
19
+ ---
20
+
21
+ ## ๐Ÿ“ฆ Installation
22
+
23
+ ```bash
24
+ npm install unit-converter-package-roshan
25
+ ````
26
+
27
+ or
28
+
29
+ ```bash
30
+ yarn add unit-converter-package-roshan
31
+ ```
32
+
33
+ ---
34
+
35
+ ## ๐Ÿš€ Usage
36
+
37
+ ### Importing
38
+
39
+ ```ts
40
+ import {
41
+ convertLength,
42
+ convertTemperature,
43
+ LengthUnit,
44
+ TemperatureUnit
45
+ } from "unit-converter-package-roshan";
46
+ ```
47
+
48
+ ---
49
+
50
+ ## ๐Ÿ“ Length Conversion
51
+
52
+ ### Supported Units
53
+
54
+ * `cm`
55
+ * `m`
56
+ * `km`
57
+
58
+ ### Example
59
+
60
+ ```ts
61
+ convertLength(100, "cm", "m"); // 1
62
+ convertLength(2, "km", "m"); // 2000
63
+ convertLength(1500, "m", "km"); // 1.5
64
+ ```
65
+
66
+ ### Type Safety
67
+
68
+ ```ts
69
+ const unit: LengthUnit = "cm"; // โœ…
70
+ const wrongUnit: LengthUnit = "mm"; // โŒ TypeScript error
71
+ ```
72
+
73
+ ---
74
+
75
+ ## ๐ŸŒก๏ธ Temperature Conversion
76
+
77
+ ### Supported Units
78
+
79
+ * `celsius`
80
+ * `fahrenheit`
81
+ * `kelvin`
82
+
83
+ ### Example
84
+
85
+ ```ts
86
+ convertTemperature(0, "celsius", "fahrenheit"); // 32
87
+ convertTemperature(32, "fahrenheit", "celsius"); // 0
88
+ convertTemperature(0, "celsius", "kelvin"); // 273.15
89
+ ```
90
+
91
+ ### Floating Point Precision
92
+
93
+ For temperature conversions, floating-point math is used.
94
+ Use rounding if required:
95
+
96
+ ```ts
97
+ const value = convertTemperature(32, "fahrenheit", "kelvin");
98
+ value.toFixed(2); // "273.15"
99
+ ```
100
+
101
+ ---
102
+
103
+ ## ๐Ÿง  API Reference
104
+
105
+ ### `convertLength`
106
+
107
+ ```ts
108
+ convertLength(
109
+ value: number,
110
+ from: LengthUnit,
111
+ to: LengthUnit
112
+ ): number
113
+ ```
114
+
115
+ ---
116
+
117
+ ### `convertTemperature`
118
+
119
+ ```ts
120
+ convertTemperature(
121
+ value: number,
122
+ from: TemperatureUnit,
123
+ to: TemperatureUnit
124
+ ): number
125
+ ```
126
+
127
+ ---
128
+
129
+ ## ๐Ÿงช Testing
130
+
131
+ This package is tested using **Jest**.
132
+
133
+ ```bash
134
+ npm test
135
+ ```
136
+
137
+ ---
138
+
139
+ ## ๐ŸŒณ Tree Shaking
140
+
141
+ This package uses ES Modules and supports tree-shaking:
142
+
143
+ ```ts
144
+ import { convertLength } from "unit-converter-package-roshan";
145
+ ```
146
+
147
+ Unused functions are excluded from the final bundle.
148
+
149
+ ---
150
+
151
+ ## ๐Ÿ› ๏ธ Built With
152
+
153
+ * TypeScript
154
+ * Jest
155
+ * Zero runtime dependencies
156
+
157
+ ---
158
+
159
+ ## ๐Ÿงฉ Roadmap
160
+
161
+ Planned enhancements:
162
+
163
+ * Weight units (`g`, `kg`, `lb`)
164
+ * Time units (`s`, `min`, `hr`)
165
+ * Speed units (`m/s`, `km/h`)
166
+ * Chainable API
167
+ * Optional rounding helpers
168
+
169
+ ---
170
+
171
+ ## ๐Ÿค Contributing
172
+
173
+ Pull requests are welcome.
174
+
175
+ 1. Fork the repository
176
+ 2. Create a feature branch
177
+ 3. Add tests for your changes
178
+ 4. Submit a pull request
179
+
180
+ ---
181
+
182
+ ## ๐Ÿ“„ License
183
+
184
+ MIT License ยฉ Roshan
185
+
186
+ ---
@@ -0,0 +1,3 @@
1
+ export { convertLength } from "./length";
2
+ export { convertTemperature } from "./temperature";
3
+ export type { LengthUnit, TemperatureUnit, } from "./types";
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export { convertLength } from "./length";
2
+ export { convertTemperature } from "./temperature";
@@ -0,0 +1,2 @@
1
+ import type { LengthUnit } from "./types";
2
+ export declare function convertLength(value: number, from: LengthUnit, to: LengthUnit): number;
package/dist/length.js ADDED
@@ -0,0 +1,8 @@
1
+ const TO_METERS = {
2
+ cm: 0.01,
3
+ m: 1,
4
+ km: 1000,
5
+ };
6
+ export function convertLength(value, from, to) {
7
+ return (value * TO_METERS[from]) / TO_METERS[to];
8
+ }
@@ -0,0 +1,2 @@
1
+ import type { TemperatureUnit } from "./types";
2
+ export declare function convertTemperature(value: number, from: TemperatureUnit, to: TemperatureUnit): number;
@@ -0,0 +1,13 @@
1
+ const TO_CELSIUS = {
2
+ celsius: (v) => v,
3
+ fahrenheit: (v) => (v - 32) * (5 / 9),
4
+ kelvin: (v) => v - 273.15,
5
+ };
6
+ const FROM_CELSIUS = {
7
+ celsius: (v) => v,
8
+ fahrenheit: (v) => v * (9 / 5) + 32,
9
+ kelvin: (v) => v + 273.15,
10
+ };
11
+ export function convertTemperature(value, from, to) {
12
+ return FROM_CELSIUS[to](TO_CELSIUS[from](value));
13
+ }
@@ -0,0 +1,4 @@
1
+ export declare const LENGTH_UNITS: readonly ["cm", "m", "km"];
2
+ export type LengthUnit = typeof LENGTH_UNITS[number];
3
+ export declare const TEMPERATURE_UNITS: readonly ["celsius", "fahrenheit", "kelvin"];
4
+ export type TemperatureUnit = typeof TEMPERATURE_UNITS[number];
package/dist/types.js ADDED
@@ -0,0 +1,6 @@
1
+ export const LENGTH_UNITS = ["cm", "m", "km"];
2
+ export const TEMPERATURE_UNITS = [
3
+ "celsius",
4
+ "fahrenheit",
5
+ "kelvin",
6
+ ];
package/package.json ADDED
@@ -0,0 +1,29 @@
1
+ {
2
+ "name": "unit-converter-package-roshan",
3
+ "version": "1.0.0",
4
+ "description": "Simple unit conversion utilities",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "files": [
8
+ "dist"
9
+ ],
10
+ "scripts": {
11
+ "build": "tsc",
12
+ "test": "jest",
13
+ "test:watch": "jest --watch",
14
+ "prepublishOnly": "npm run build"
15
+ },
16
+ "keywords": [
17
+ "unit",
18
+ "conversion",
19
+ "temperature",
20
+ "length"
21
+ ],
22
+ "author": "Roshan Patil",
23
+ "license": "MIT",
24
+ "devDependencies": {
25
+ "@types/jest": "^30.0.0",
26
+ "jest": "^30.2.0",
27
+ "ts-jest": "^29.4.6"
28
+ }
29
+ }