uom-types 2.0.0 → 3.0.1

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.
@@ -0,0 +1,483 @@
1
+ import { mul, div } from './functions.mjs';
2
+
3
+ /**
4
+ * Convert {@link Radian} to {@link Degree}.
5
+ */
6
+ function radiansToDegrees(angle) {
7
+ return mul(angle, (180 / Math.PI));
8
+ }
9
+ /**
10
+ * Convert {@link Radian} to {@link Gradian}.
11
+ */
12
+ function radiansToGradians(angle) {
13
+ return mul(angle, (200 / Math.PI));
14
+ }
15
+ /**
16
+ * Convert {@link Radian} to {@link Turn}.
17
+ */
18
+ function radiansToTurns(angle) {
19
+ return div(angle, Math.PI);
20
+ }
21
+ /**
22
+ * Convert {@link Degree} to {@link Radian}.
23
+ */
24
+ function degreesToRadians(angle) {
25
+ return mul(angle, (Math.PI / 180));
26
+ }
27
+ /**
28
+ * Convert {@link Degree} to {@link Gradian}.
29
+ */
30
+ function degreesToGradians(angle) {
31
+ return mul(angle, (10 / 9));
32
+ }
33
+ /**
34
+ * Convert {@link Degree} to {@link Turn}.
35
+ */
36
+ function degreesToTurns(angle) {
37
+ return div(angle, 360);
38
+ }
39
+ /**
40
+ * Convert {@link Gradian} to {@link Radian}.
41
+ */
42
+ function gradiansToRadians(angle) {
43
+ return mul(angle, (Math.PI / 400));
44
+ }
45
+ /**
46
+ * Convert {@link Gradian} to {@link Degree}.
47
+ */
48
+ function gradiansToDegrees(angle) {
49
+ return mul(angle, (9 / 10));
50
+ }
51
+ /**
52
+ * Convert {@link Gradian} to {@link Turn}.
53
+ */
54
+ function gradiansToTurns(angle) {
55
+ return div(angle, 400);
56
+ }
57
+ /**
58
+ * Convert {@link Turn} to {@link Radian}.
59
+ */
60
+ function turnsToRadians(angle) {
61
+ return mul(angle, (2 * Math.PI));
62
+ }
63
+ /**
64
+ * Convert {@link Turn} to {@link Degree}.
65
+ */
66
+ function turnsToDegrees(angle) {
67
+ return mul(angle, 360);
68
+ }
69
+ /**
70
+ * Convert {@link Turn} to {@link Gradian}.
71
+ */
72
+ function turnsToGradians(angle) {
73
+ return mul(angle, 400);
74
+ }
75
+
76
+ /**
77
+ * Convert {@link Square}<{@link Metre}> to {@link Are}.
78
+ */
79
+ function squareMetresToAres(area) {
80
+ return div(area, 100);
81
+ }
82
+ /**
83
+ * Convert {@link Square}<{@link Metre}> to {@link Hectare}.
84
+ */
85
+ function squareMetresToHectares(area) {
86
+ return div(area, 10_000);
87
+ }
88
+ /**
89
+ * Convert {@link Are} to {@link Square}<{@link Metre}>.
90
+ */
91
+ function aresToSquareMetres(area) {
92
+ return mul(area, 100);
93
+ }
94
+ /**
95
+ * Convert {@link Are} to {@link Hectare}.
96
+ */
97
+ function aresToHectares(area) {
98
+ return div(area, 100);
99
+ }
100
+ /**
101
+ * Convert {@link Hectare} to {@link Square}<{@link Metre}>.
102
+ */
103
+ function hectaresToSquareMetres(area) {
104
+ return mul(area, 10_000);
105
+ }
106
+ /**
107
+ * Convert {@link Hectare} to {@link Are}.
108
+ */
109
+ function hectaresToAres(area) {
110
+ return mul(area, 100);
111
+ }
112
+
113
+ /**
114
+ * Convert {@link Second} to {@link Minute}.
115
+ */
116
+ function secondsToMinutes(duration) {
117
+ return div(duration, 60);
118
+ }
119
+ /**
120
+ * Convert {@link Second} to {@link Hour}.
121
+ */
122
+ function secondsToHours(duration) {
123
+ return div(duration, 3600);
124
+ }
125
+ /**
126
+ * Convert {@link Minute} to {@link Second}.
127
+ */
128
+ function minutesToSeconds(duration) {
129
+ return mul(duration, 60);
130
+ }
131
+ /**
132
+ * Convert {@link Minute} to {@link Hour}.
133
+ */
134
+ function minutesToHours(duration) {
135
+ return div(duration, 60);
136
+ }
137
+ /**
138
+ * Convert {@link Hour} to {@link Second}.
139
+ */
140
+ function hoursToSeconds(duration) {
141
+ return mul(duration, 3600);
142
+ }
143
+ /**
144
+ * Convert {@link Hour} to {@link Minute}.
145
+ */
146
+ function hoursToMinutes(duration) {
147
+ return mul(duration, 60);
148
+ }
149
+ /**
150
+ * Convert {@link Hour} to {@link Day}.
151
+ */
152
+ function hoursToDays(duration) {
153
+ return div(duration, 24);
154
+ }
155
+ /**
156
+ * Convert {@link Day} to {@link Hour}.
157
+ */
158
+ function daysToHours(duration) {
159
+ return mul(duration, 24);
160
+ }
161
+ /**
162
+ * Convert {@link Day} to {@link Week}.
163
+ */
164
+ function daysToWeeks(duration) {
165
+ return div(duration, 7);
166
+ }
167
+ /**
168
+ * Convert {@link Day} to {@link Year}.
169
+ *
170
+ * This function assume that one year is equal to 365.25 Day.
171
+ * Use an actual date/time library if you need more control.
172
+ */
173
+ function daysToYears(duration) {
174
+ return div(duration, 365.25);
175
+ }
176
+ /**
177
+ * Convert {@link Week} to {@link Day}.
178
+ */
179
+ function weeksToDays(duration) {
180
+ return mul(duration, 7);
181
+ }
182
+ /**
183
+ * Convert {@link Week} to {@link Year}.
184
+ */
185
+ function weeksToYears(duration) {
186
+ return daysToYears(weeksToDays(duration));
187
+ }
188
+ /**
189
+ * Convert {@link Year} to {@link Day}.
190
+ *
191
+ * This function assume that one year is equal to 365.25 Day.
192
+ * Use an actual date/time library if you need more control.
193
+ */
194
+ function yearsToDays(duration) {
195
+ return mul(duration, 365.25);
196
+ }
197
+ /**
198
+ * Convert {@link Year} to {@link Week}.
199
+ */
200
+ function yearsToWeeks(duration) {
201
+ return daysToWeeks(yearsToDays(duration));
202
+ }
203
+
204
+ /**
205
+ * Convert {@link Joule} to {@link WattMinute}.
206
+ */
207
+ function joulesToWattMinutes(energy) {
208
+ return div(energy, 60);
209
+ }
210
+ /**
211
+ * Convert {@link Joule} to {@link WattHour}.
212
+ */
213
+ function joulesToWattHours(energy) {
214
+ return div(energy, 3600);
215
+ }
216
+ /**
217
+ * Convert {@link WattMinute} to {@link Joule}.
218
+ */
219
+ function wattMinutesToJoules(energy) {
220
+ return mul(energy, 60);
221
+ }
222
+ /**
223
+ * Convert {@link WattHour} to {@link Joule}.
224
+ */
225
+ function wattHoursToJoules(energy) {
226
+ return mul(energy, 3600);
227
+ }
228
+
229
+ /**
230
+ * Convert {@link Hertz} to {@link PerMinute}.
231
+ */
232
+ function hertzToPerMinute(frequency) {
233
+ return mul(frequency, 60);
234
+ }
235
+ /**
236
+ * Convert {@link Hertz} to {@link PerHour}.
237
+ */
238
+ function hertzToPerHour(frequency) {
239
+ return mul(frequency, 3600);
240
+ }
241
+ /**
242
+ * Convert {@link PerMinute} to {@link Hertz}.
243
+ */
244
+ function perMinuteToHertz(frequency) {
245
+ return div(frequency, 60);
246
+ }
247
+ /**
248
+ * Convert {@link PerMinute} to {@link PerHour}.
249
+ */
250
+ function perMinuteToPerHour(frequency) {
251
+ return mul(frequency, 60);
252
+ }
253
+ /**
254
+ * Convert {@link PerHour} to {@link Hertz}.
255
+ */
256
+ function perHourToHertz(frequency) {
257
+ return div(frequency, 3600);
258
+ }
259
+ /**
260
+ * Convert {@link PerHour} to {@link PerMinute}.
261
+ */
262
+ function perHourToPerMinute(frequency) {
263
+ return div(frequency, 60);
264
+ }
265
+ /**
266
+ * Convert {@link PerHour} to {@link PerDay}.
267
+ */
268
+ function perHourToPerDay(frequency) {
269
+ return mul(frequency, 24);
270
+ }
271
+ /**
272
+ * Convert {@link PerDay} to {@link PerHour}.
273
+ */
274
+ function perDayToPerHour(frequency) {
275
+ return div(frequency, 24);
276
+ }
277
+ /**
278
+ * Convert {@link PerDay} to {@link PerWeek}.
279
+ */
280
+ function perDayToPerWeek(frequency) {
281
+ return mul(frequency, 7);
282
+ }
283
+ /**
284
+ * Convert {@link PerDay} to {@link PerYear}.
285
+ *
286
+ * This function assume that one year is equal to 365.25 Day.
287
+ * Use an actual date/time library if you need more control.
288
+ */
289
+ function perDayToPerYear(frequency) {
290
+ return mul(frequency, 365.25);
291
+ }
292
+ /**
293
+ * Convert {@link PerWeek} to {@link PerDay}.
294
+ */
295
+ function perWeekToPerDay(frequency) {
296
+ return div(frequency, 7);
297
+ }
298
+ /**
299
+ * Convert {@link PerWeek} to {@link PerYear}.
300
+ */
301
+ function perWeekToPerYear(frequency) {
302
+ return perDayToPerYear(perWeekToPerDay(frequency));
303
+ }
304
+ /**
305
+ * Convert {@link PerYear} to {@link PerDay}.
306
+ *
307
+ * This function assume that one year is equal to 365.25 Day.
308
+ * Use an actual date/time library if you need more control.
309
+ */
310
+ function perYearToPerDay(frequency) {
311
+ return div(frequency, 365.25);
312
+ }
313
+ /**
314
+ * Convert {@link PerYear} to {@link PerWeek}.
315
+ */
316
+ function perYearToPerWeek(frequency) {
317
+ return perDayToPerWeek(perYearToPerDay(frequency));
318
+ }
319
+
320
+ /**
321
+ * Convert {@link Gram} to {@link Tonne}.
322
+ */
323
+ function gramsToTonnes(mass) {
324
+ return div(mass, 1_000_000);
325
+ }
326
+ /**
327
+ * Convert {@link Tonne} to {@link Gram}.
328
+ */
329
+ function tonnesToGrams(mass) {
330
+ return mul(mass, 1_000_000);
331
+ }
332
+
333
+ /**
334
+ * @file Autogenerated File - Don't manually edit.
335
+ */
336
+ /**
337
+ * Convert `X` to `dekaX`.
338
+ */
339
+ function toDeka(value) {
340
+ return mul(value, 10);
341
+ }
342
+ /**
343
+ * Convert `dekaX` to `X`.
344
+ */
345
+ const fromDeka = toDeci;
346
+ /**
347
+ * Convert `X` to `deciX`.
348
+ */
349
+ function toDeci(value) {
350
+ return div(value, 10);
351
+ }
352
+ /**
353
+ * Convert `deciX` to `X`.
354
+ */
355
+ const fromDeci = toDeka;
356
+ /**
357
+ * Convert `X` to `hectoX`.
358
+ */
359
+ function toHecto(value) {
360
+ return mul(value, 100);
361
+ }
362
+ /**
363
+ * Convert `hectoX` to `X`.
364
+ */
365
+ const fromHecto = toCenti;
366
+ /**
367
+ * Convert `X` to `centiX`.
368
+ */
369
+ function toCenti(value) {
370
+ return div(value, 100);
371
+ }
372
+ /**
373
+ * Convert `centiX` to `X`.
374
+ */
375
+ const fromCenti = toHecto;
376
+ /**
377
+ * Convert `X` to `kiloX`.
378
+ */
379
+ function toKilo(value) {
380
+ return mul(value, 1000);
381
+ }
382
+ /**
383
+ * Convert `kiloX` to `X`.
384
+ */
385
+ const fromKilo = toMilli;
386
+ /**
387
+ * Convert `X` to `milliX`.
388
+ */
389
+ function toMilli(value) {
390
+ return div(value, 1000);
391
+ }
392
+ /**
393
+ * Convert `milliX` to `X`.
394
+ */
395
+ const fromMilli = toKilo;
396
+ /**
397
+ * Convert `X` to `megaX`.
398
+ */
399
+ function toMega(value) {
400
+ return mul(value, 1000000);
401
+ }
402
+ /**
403
+ * Convert `megaX` to `X`.
404
+ */
405
+ const fromMega = toMicro;
406
+ /**
407
+ * Convert `X` to `microX`.
408
+ */
409
+ function toMicro(value) {
410
+ return div(value, 1000000);
411
+ }
412
+ /**
413
+ * Convert `microX` to `X`.
414
+ */
415
+ const fromMicro = toMega;
416
+ /**
417
+ * Convert `X` to `gigaX`.
418
+ */
419
+ function toGiga(value) {
420
+ return mul(value, 1000000000);
421
+ }
422
+ /**
423
+ * Convert `gigaX` to `X`.
424
+ */
425
+ const fromGiga = toNano;
426
+ /**
427
+ * Convert `X` to `nanoX`.
428
+ */
429
+ function toNano(value) {
430
+ return div(value, 1000000000);
431
+ }
432
+ /**
433
+ * Convert `nanoX` to `X`.
434
+ */
435
+ const fromNano = toGiga;
436
+ /**
437
+ * Convert `X` to `teraX`.
438
+ */
439
+ function toTera(value) {
440
+ return mul(value, 1000000000000);
441
+ }
442
+ /**
443
+ * Convert `teraX` to `X`.
444
+ */
445
+ const fromTera = toPico;
446
+ /**
447
+ * Convert `X` to `picoX`.
448
+ */
449
+ function toPico(value) {
450
+ return div(value, 1000000000000);
451
+ }
452
+ /**
453
+ * Convert `picoX` to `X`.
454
+ */
455
+ const fromPico = toTera;
456
+
457
+ /**
458
+ * Convert {@link Celsius} to {@link Kelvin}.
459
+ */
460
+ function celsiusToKelvin(temperature) {
461
+ return (temperature - 273.15);
462
+ }
463
+ /**
464
+ * Convert {@link Kelvin} to {@link Celsius}.
465
+ */
466
+ function kelvinToCelsius(temperature) {
467
+ return (temperature + 273.15);
468
+ }
469
+
470
+ /**
471
+ * Convert {@link Cubic}<{@link Metre}> to {@link Litre}.
472
+ */
473
+ function cubicMetresToLitres(volume) {
474
+ return mul(volume, 1000);
475
+ }
476
+ /**
477
+ * Convert {@link Litre} to {@link Cubic}<{@link Metre}>.
478
+ */
479
+ function litresToCubicMetres(volume) {
480
+ return div(volume, 1000);
481
+ }
482
+
483
+ export { aresToHectares, aresToSquareMetres, celsiusToKelvin, cubicMetresToLitres, daysToHours, daysToWeeks, daysToYears, degreesToGradians, degreesToRadians, degreesToTurns, fromCenti, fromDeci, fromDeka, fromGiga, fromHecto, fromKilo, fromMega, fromMicro, fromMilli, fromNano, fromPico, fromTera, gradiansToDegrees, gradiansToRadians, gradiansToTurns, gramsToTonnes, hectaresToAres, hectaresToSquareMetres, hertzToPerHour, hertzToPerMinute, hoursToDays, hoursToMinutes, hoursToSeconds, joulesToWattHours, joulesToWattMinutes, kelvinToCelsius, litresToCubicMetres, minutesToHours, minutesToSeconds, perDayToPerHour, perDayToPerWeek, perDayToPerYear, perHourToHertz, perHourToPerDay, perHourToPerMinute, perMinuteToHertz, perMinuteToPerHour, perWeekToPerDay, perWeekToPerYear, perYearToPerDay, perYearToPerWeek, radiansToDegrees, radiansToGradians, radiansToTurns, secondsToHours, secondsToMinutes, squareMetresToAres, squareMetresToHectares, toCenti, toDeci, toDeka, toGiga, toHecto, toKilo, toMega, toMicro, toMilli, toNano, toPico, toTera, tonnesToGrams, turnsToDegrees, turnsToGradians, turnsToRadians, wattHoursToJoules, wattMinutesToJoules, weeksToDays, weeksToYears, yearsToDays, yearsToWeeks };