uconvert 0.1.3 → 0.1.4
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/README.md +45 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,14 +2,23 @@
|
|
|
2
2
|
|
|
3
3
|
Lightweight utility for converting common measurement units.
|
|
4
4
|
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
5
8
|
## Installation
|
|
6
9
|
|
|
7
10
|
```bash
|
|
8
11
|
npm install uconvert
|
|
9
12
|
```
|
|
10
13
|
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
11
17
|
## Usage
|
|
12
18
|
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
13
22
|
### `convert(value, options)`
|
|
14
23
|
|
|
15
24
|
Converts a numeric value from one unit to another.
|
|
@@ -42,6 +51,9 @@ convert(100, { fromUnits: MetricUnits.CM, toUnits: MetricUnits.CM });
|
|
|
42
51
|
// => 100
|
|
43
52
|
```
|
|
44
53
|
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
|
|
45
57
|
### `round(value, decimalPlaces?)`
|
|
46
58
|
|
|
47
59
|
Rounds a number to a given number of decimal places.
|
|
@@ -62,10 +74,16 @@ round(1.2345, 2); // => 1.23
|
|
|
62
74
|
round(1.2345); // => 1.2345
|
|
63
75
|
```
|
|
64
76
|
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
|
|
65
80
|
## Supported units
|
|
66
81
|
|
|
67
82
|
Units are grouped by dimension. Use the **Code** value with `convert()`.
|
|
68
83
|
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
|
|
69
87
|
### Length
|
|
70
88
|
|
|
71
89
|
| Unit | Code | System |
|
|
@@ -79,6 +97,9 @@ Units are grouped by dimension. Use the **Code** value with `convert()`.
|
|
|
79
97
|
| yd | `ImperialUnits.YD` | Imperial |
|
|
80
98
|
| mi | `ImperialUnits.MI` | Imperial |
|
|
81
99
|
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
|
|
82
103
|
### Weight
|
|
83
104
|
|
|
84
105
|
| Unit | Code | System |
|
|
@@ -90,6 +111,9 @@ Units are grouped by dimension. Use the **Code** value with `convert()`.
|
|
|
90
111
|
| lb | `ImperialUnits.LB` | Imperial |
|
|
91
112
|
| st | `ImperialUnits.ST` | Imperial |
|
|
92
113
|
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
|
|
93
117
|
### Speed
|
|
94
118
|
|
|
95
119
|
| Unit | Code | System |
|
|
@@ -99,6 +123,9 @@ Units are grouped by dimension. Use the **Code** value with `convert()`.
|
|
|
99
123
|
| ft/s | `ImperialUnits.FT_S` | Imperial |
|
|
100
124
|
| mph | `ImperialUnits.MPH` | Imperial |
|
|
101
125
|
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
|
|
102
129
|
### Temperature
|
|
103
130
|
|
|
104
131
|
| Unit | Code | System |
|
|
@@ -107,6 +134,9 @@ Units are grouped by dimension. Use the **Code** value with `convert()`.
|
|
|
107
134
|
| K | `MetricUnits.KELVIN` | Metric |
|
|
108
135
|
| °F (F) | `ImperialUnits.FAHRENHEIT` | Imperial |
|
|
109
136
|
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
|
|
110
140
|
## Exported types and enums
|
|
111
141
|
|
|
112
142
|
Use these with `convert` for type-safe unit arguments:
|
|
@@ -124,6 +154,9 @@ Use these with `convert` for type-safe unit arguments:
|
|
|
124
154
|
|
|
125
155
|
---
|
|
126
156
|
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
|
|
127
160
|
## Height utility
|
|
128
161
|
|
|
129
162
|
The `height` object provides helpers for converting between centimeters and feet–inches and for parsing feet–inches strings.
|
|
@@ -134,6 +167,9 @@ The `height` object provides helpers for converting between centimeters and feet
|
|
|
134
167
|
import { height } from "uconvert";
|
|
135
168
|
```
|
|
136
169
|
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
|
|
137
173
|
### `height.toFeetInches(valueInCm, roundTo?)`
|
|
138
174
|
|
|
139
175
|
Converts a height in centimeters to feet and inches.
|
|
@@ -152,6 +188,9 @@ height.toFeetInches(170); // => [5, 6.93...]
|
|
|
152
188
|
height.toFeetInches(170, 1); // => [5, 6.9]
|
|
153
189
|
```
|
|
154
190
|
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
|
|
155
194
|
### `height.toCentimeters(feetInches)`
|
|
156
195
|
|
|
157
196
|
Converts a feet–inches tuple to centimeters.
|
|
@@ -168,6 +207,9 @@ Converts a feet–inches tuple to centimeters.
|
|
|
168
207
|
height.toCentimeters([5, 10]); // => 177.8
|
|
169
208
|
```
|
|
170
209
|
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
|
|
171
213
|
### `height.parseFeetInches(input)`
|
|
172
214
|
|
|
173
215
|
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 +228,9 @@ height.parseFeetInches("5'10\""); // => [5, 10]
|
|
|
186
228
|
height.parseFeetInches("6 2"); // => [6, 2]
|
|
187
229
|
```
|
|
188
230
|
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
|
|
189
234
|
### `FeetInches` type
|
|
190
235
|
|
|
191
236
|
Tuple type `[number, number]`: first element is feet, second is inches. Use it when passing or receiving values from `toFeetInches`, `toCentimeters`, and `parseFeetInches`.
|