uconvert 0.1.3 → 0.1.5

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.
Files changed (2) hide show
  1. package/README.md +69 -11
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -2,14 +2,40 @@
2
2
 
3
3
  Lightweight utility for converting common measurement units.
4
4
 
5
+ <br />
6
+
7
+ ## Table of contents
8
+
9
+ - [Installation](#installation)
10
+ - [Usage](#usage)
11
+ - [`convert(value, options)`](#convertvalue-options)
12
+ - [`round(value, decimalPlaces?)`](#roundvalue-decimalplaces)
13
+ - [Exported types and enums](#exported-types-and-enums)
14
+ - [Supported units](#supported-units)
15
+ - [Length](#length)
16
+ - [Weight](#weight)
17
+ - [Speed](#speed)
18
+ - [Temperature](#temperature)
19
+ - [Height utility](#height-utility)
20
+ - [`height.toFeetInches(valueInCm, roundTo?)`](#heighttofeetinchesvalueincm-roundto)
21
+ - [`height.toCentimeters(feetInches)`](#heighttocentimetersfeetinches)
22
+ - [`height.parseFeetInches(input)`](#heightparsefeetinchesinput)
23
+ - [`FeetInches` type](#feetinches-type)
24
+
25
+ <br />
26
+
5
27
  ## Installation
6
28
 
7
29
  ```bash
8
30
  npm install uconvert
9
31
  ```
10
32
 
33
+ <br />
34
+
11
35
  ## Usage
12
36
 
37
+ <br />
38
+
13
39
  ### `convert(value, options)`
14
40
 
15
41
  Converts a numeric value from one unit to another.
@@ -42,6 +68,8 @@ convert(100, { fromUnits: MetricUnits.CM, toUnits: MetricUnits.CM });
42
68
  // => 100
43
69
  ```
44
70
 
71
+ <br />
72
+
45
73
  ### `round(value, decimalPlaces?)`
46
74
 
47
75
  Rounds a number to a given number of decimal places.
@@ -62,10 +90,33 @@ round(1.2345, 2); // => 1.23
62
90
  round(1.2345); // => 1.2345
63
91
  ```
64
92
 
93
+ <br />
94
+
95
+ ## Exported types and enums
96
+
97
+ Use these with `convert` for type-safe unit arguments:
98
+
99
+ | Export | Description |
100
+ | ---------------- | ------------------------------------------------------------------------------------ |
101
+ | `ConvertOptions` | Options object for `convert`: `{ fromUnits, toUnits, roundTo? }`. |
102
+ | `Units` | Union type: `MetricUnits \| ImperialUnits`. |
103
+ | `MetricUnits` | Enum: `MM`, `CM`, `M`, `KM`, `G`, `KG`, `TONNE`, `CELSIUS`, `KELVIN`, `M_S`, `KM_H`. |
104
+ | `ImperialUnits` | Enum: `IN`, `FT`, `YD`, `MI`, `OZ`, `LB`, `ST`, `FAHRENHEIT`, `FT_S`, `MPH`. |
105
+ | `UnitSystem` | Enum: `METRIC`, `IMPERIAL`. |
106
+ | `Dimension` | Enum: `LENGTH`, `WEIGHT`, `SPEED`, `TEMPERATURE`. |
107
+
108
+ `fromUnits` and `toUnits` must use the same dimension (e.g. both length, or both weight); otherwise `convert` throws.
109
+
110
+ ---
111
+
112
+ <br />
113
+
65
114
  ## Supported units
66
115
 
67
116
  Units are grouped by dimension. Use the **Code** value with `convert()`.
68
117
 
118
+ <br />
119
+
69
120
  ### Length
70
121
 
71
122
  | Unit | Code | System |
@@ -79,6 +130,8 @@ Units are grouped by dimension. Use the **Code** value with `convert()`.
79
130
  | yd | `ImperialUnits.YD` | Imperial |
80
131
  | mi | `ImperialUnits.MI` | Imperial |
81
132
 
133
+ <br />
134
+
82
135
  ### Weight
83
136
 
84
137
  | Unit | Code | System |
@@ -90,6 +143,8 @@ Units are grouped by dimension. Use the **Code** value with `convert()`.
90
143
  | lb | `ImperialUnits.LB` | Imperial |
91
144
  | st | `ImperialUnits.ST` | Imperial |
92
145
 
146
+ <br />
147
+
93
148
  ### Speed
94
149
 
95
150
  | Unit | Code | System |
@@ -99,6 +154,8 @@ Units are grouped by dimension. Use the **Code** value with `convert()`.
99
154
  | ft/s | `ImperialUnits.FT_S` | Imperial |
100
155
  | mph | `ImperialUnits.MPH` | Imperial |
101
156
 
157
+ <br />
158
+
102
159
  ### Temperature
103
160
 
104
161
  | Unit | Code | System |
@@ -107,23 +164,16 @@ Units are grouped by dimension. Use the **Code** value with `convert()`.
107
164
  | K | `MetricUnits.KELVIN` | Metric |
108
165
  | °F (F) | `ImperialUnits.FAHRENHEIT` | Imperial |
109
166
 
110
- ## Exported types and enums
111
167
 
112
- Use these with `convert` for type-safe unit arguments:
113
168
 
114
- | Export | Description |
115
- | ---------------- | ------------------------------------------------------------------------------------ |
116
- | `ConvertOptions` | Options object for `convert`: `{ fromUnits, toUnits, roundTo? }`. |
117
- | `Units` | Union type: `MetricUnits \| ImperialUnits`. |
118
- | `MetricUnits` | Enum: `MM`, `CM`, `M`, `KM`, `G`, `KG`, `TONNE`, `CELSIUS`, `KELVIN`, `M_S`, `KM_H`. |
119
- | `ImperialUnits` | Enum: `IN`, `FT`, `YD`, `MI`, `OZ`, `LB`, `ST`, `FAHRENHEIT`, `FT_S`, `MPH`. |
120
- | `UnitSystem` | Enum: `METRIC`, `IMPERIAL`. |
121
- | `Dimension` | Enum: `LENGTH`, `WEIGHT`, `SPEED`, `TEMPERATURE`. |
122
169
 
123
- `fromUnits` and `toUnits` must use the same dimension (e.g. both length, or both weight); otherwise `convert` throws.
170
+ <br />
124
171
 
125
172
  ---
126
173
 
174
+ <br />
175
+
176
+
127
177
  ## Height utility
128
178
 
129
179
  The `height` object provides helpers for converting between centimeters and feet–inches and for parsing feet–inches strings.
@@ -134,6 +184,8 @@ The `height` object provides helpers for converting between centimeters and feet
134
184
  import { height } from "uconvert";
135
185
  ```
136
186
 
187
+ <br />
188
+
137
189
  ### `height.toFeetInches(valueInCm, roundTo?)`
138
190
 
139
191
  Converts a height in centimeters to feet and inches.
@@ -152,6 +204,8 @@ height.toFeetInches(170); // => [5, 6.93...]
152
204
  height.toFeetInches(170, 1); // => [5, 6.9]
153
205
  ```
154
206
 
207
+ <br />
208
+
155
209
  ### `height.toCentimeters(feetInches)`
156
210
 
157
211
  Converts a feet–inches tuple to centimeters.
@@ -168,6 +222,8 @@ Converts a feet–inches tuple to centimeters.
168
222
  height.toCentimeters([5, 10]); // => 177.8
169
223
  ```
170
224
 
225
+ <br />
226
+
171
227
  ### `height.parseFeetInches(input)`
172
228
 
173
229
  Parses a string into a `[feet, inches]` tuple. Accepts formats like `"5 ft 10 in"`, `"5'10\""`, `"5 10"`, and variations with "feet"/"foot"/"inches"/"inch".
@@ -186,6 +242,8 @@ height.parseFeetInches("5'10\""); // => [5, 10]
186
242
  height.parseFeetInches("6 2"); // => [6, 2]
187
243
  ```
188
244
 
245
+ <br />
246
+
189
247
  ### `FeetInches` type
190
248
 
191
249
  Tuple type `[number, number]`: first element is feet, second is inches. Use it when passing or receiving values from `toFeetInches`, `toCentimeters`, and `parseFeetInches`.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "uconvert",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",