uconvert 0.1.4 → 0.1.6
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 +52 -39
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -2,8 +2,27 @@
|
|
|
2
2
|
|
|
3
3
|
Lightweight utility for converting common measurement units.
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
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 />
|
|
7
26
|
|
|
8
27
|
## Installation
|
|
9
28
|
|
|
@@ -11,13 +30,11 @@ Lightweight utility for converting common measurement units.
|
|
|
11
30
|
npm install uconvert
|
|
12
31
|
```
|
|
13
32
|
|
|
14
|
-
|
|
15
|
-
|
|
33
|
+
<br />
|
|
16
34
|
|
|
17
35
|
## Usage
|
|
18
36
|
|
|
19
|
-
|
|
20
|
-
|
|
37
|
+
<br />
|
|
21
38
|
|
|
22
39
|
### `convert(value, options)`
|
|
23
40
|
|
|
@@ -51,8 +68,7 @@ convert(100, { fromUnits: MetricUnits.CM, toUnits: MetricUnits.CM });
|
|
|
51
68
|
// => 100
|
|
52
69
|
```
|
|
53
70
|
|
|
54
|
-
|
|
55
|
-
|
|
71
|
+
<br />
|
|
56
72
|
|
|
57
73
|
### `round(value, decimalPlaces?)`
|
|
58
74
|
|
|
@@ -74,15 +90,32 @@ round(1.2345, 2); // => 1.23
|
|
|
74
90
|
round(1.2345); // => 1.2345
|
|
75
91
|
```
|
|
76
92
|
|
|
93
|
+
<br />
|
|
77
94
|
|
|
95
|
+
## Exported types and enums
|
|
78
96
|
|
|
97
|
+
Use these with `convert` for type-safe unit arguments:
|
|
79
98
|
|
|
80
|
-
|
|
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`. |
|
|
81
107
|
|
|
82
|
-
|
|
108
|
+
`fromUnits` and `toUnits` must use the same dimension (e.g. both length, or both weight); otherwise `convert` throws.
|
|
83
109
|
|
|
110
|
+
---
|
|
111
|
+
|
|
112
|
+
<br />
|
|
84
113
|
|
|
114
|
+
## Supported units
|
|
85
115
|
|
|
116
|
+
Units are grouped by dimension. Use the **Code** value with `convert()`.
|
|
117
|
+
|
|
118
|
+
<br />
|
|
86
119
|
|
|
87
120
|
### Length
|
|
88
121
|
|
|
@@ -97,8 +130,7 @@ Units are grouped by dimension. Use the **Code** value with `convert()`.
|
|
|
97
130
|
| yd | `ImperialUnits.YD` | Imperial |
|
|
98
131
|
| mi | `ImperialUnits.MI` | Imperial |
|
|
99
132
|
|
|
100
|
-
|
|
101
|
-
|
|
133
|
+
<br />
|
|
102
134
|
|
|
103
135
|
### Weight
|
|
104
136
|
|
|
@@ -111,8 +143,7 @@ Units are grouped by dimension. Use the **Code** value with `convert()`.
|
|
|
111
143
|
| lb | `ImperialUnits.LB` | Imperial |
|
|
112
144
|
| st | `ImperialUnits.ST` | Imperial |
|
|
113
145
|
|
|
114
|
-
|
|
115
|
-
|
|
146
|
+
<br />
|
|
116
147
|
|
|
117
148
|
### Speed
|
|
118
149
|
|
|
@@ -123,8 +154,7 @@ Units are grouped by dimension. Use the **Code** value with `convert()`.
|
|
|
123
154
|
| ft/s | `ImperialUnits.FT_S` | Imperial |
|
|
124
155
|
| mph | `ImperialUnits.MPH` | Imperial |
|
|
125
156
|
|
|
126
|
-
|
|
127
|
-
|
|
157
|
+
<br />
|
|
128
158
|
|
|
129
159
|
### Temperature
|
|
130
160
|
|
|
@@ -137,24 +167,11 @@ Units are grouped by dimension. Use the **Code** value with `convert()`.
|
|
|
137
167
|
|
|
138
168
|
|
|
139
169
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
Use these with `convert` for type-safe unit arguments:
|
|
143
|
-
|
|
144
|
-
| Export | Description |
|
|
145
|
-
| ---------------- | ------------------------------------------------------------------------------------ |
|
|
146
|
-
| `ConvertOptions` | Options object for `convert`: `{ fromUnits, toUnits, roundTo? }`. |
|
|
147
|
-
| `Units` | Union type: `MetricUnits \| ImperialUnits`. |
|
|
148
|
-
| `MetricUnits` | Enum: `MM`, `CM`, `M`, `KM`, `G`, `KG`, `TONNE`, `CELSIUS`, `KELVIN`, `M_S`, `KM_H`. |
|
|
149
|
-
| `ImperialUnits` | Enum: `IN`, `FT`, `YD`, `MI`, `OZ`, `LB`, `ST`, `FAHRENHEIT`, `FT_S`, `MPH`. |
|
|
150
|
-
| `UnitSystem` | Enum: `METRIC`, `IMPERIAL`. |
|
|
151
|
-
| `Dimension` | Enum: `LENGTH`, `WEIGHT`, `SPEED`, `TEMPERATURE`. |
|
|
152
|
-
|
|
153
|
-
`fromUnits` and `toUnits` must use the same dimension (e.g. both length, or both weight); otherwise `convert` throws.
|
|
170
|
+
<br />
|
|
154
171
|
|
|
155
172
|
---
|
|
156
173
|
|
|
157
|
-
|
|
174
|
+
<br />
|
|
158
175
|
|
|
159
176
|
|
|
160
177
|
## Height utility
|
|
@@ -167,8 +184,7 @@ The `height` object provides helpers for converting between centimeters and feet
|
|
|
167
184
|
import { height } from "uconvert";
|
|
168
185
|
```
|
|
169
186
|
|
|
170
|
-
|
|
171
|
-
|
|
187
|
+
<br />
|
|
172
188
|
|
|
173
189
|
### `height.toFeetInches(valueInCm, roundTo?)`
|
|
174
190
|
|
|
@@ -188,8 +204,7 @@ height.toFeetInches(170); // => [5, 6.93...]
|
|
|
188
204
|
height.toFeetInches(170, 1); // => [5, 6.9]
|
|
189
205
|
```
|
|
190
206
|
|
|
191
|
-
|
|
192
|
-
|
|
207
|
+
<br />
|
|
193
208
|
|
|
194
209
|
### `height.toCentimeters(feetInches)`
|
|
195
210
|
|
|
@@ -207,8 +222,7 @@ Converts a feet–inches tuple to centimeters.
|
|
|
207
222
|
height.toCentimeters([5, 10]); // => 177.8
|
|
208
223
|
```
|
|
209
224
|
|
|
210
|
-
|
|
211
|
-
|
|
225
|
+
<br />
|
|
212
226
|
|
|
213
227
|
### `height.parseFeetInches(input)`
|
|
214
228
|
|
|
@@ -228,8 +242,7 @@ height.parseFeetInches("5'10\""); // => [5, 10]
|
|
|
228
242
|
height.parseFeetInches("6 2"); // => [6, 2]
|
|
229
243
|
```
|
|
230
244
|
|
|
231
|
-
|
|
232
|
-
|
|
245
|
+
<br />
|
|
233
246
|
|
|
234
247
|
### `FeetInches` type
|
|
235
248
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "uconvert",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"description": "",
|
|
3
|
+
"version": "0.1.6",
|
|
4
|
+
"description": "A lightweight TypeScript utility to convert measurements between unit systems like metric and imperial.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
@@ -58,7 +58,7 @@
|
|
|
58
58
|
"precision",
|
|
59
59
|
"cross-units"
|
|
60
60
|
],
|
|
61
|
-
"author": "",
|
|
61
|
+
"author": "Andrii Tkachuk",
|
|
62
62
|
"license": "MIT",
|
|
63
63
|
"type": "commonjs",
|
|
64
64
|
"bugs": {
|