engineering-unit-converter 0.0.9 → 0.0.11

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.
@@ -1,11 +1,11 @@
1
- var c = Object.defineProperty;
2
- var l = (t, e, a) => e in t ? c(t, e, { enumerable: !0, configurable: !0, writable: !0, value: a }) : t[e] = a;
3
- var r = (t, e, a) => (l(t, typeof e != "symbol" ? e + "" : e, a), a);
4
- class u {
1
+ var l = Object.defineProperty;
2
+ var u = (t, e, a) => e in t ? l(t, e, { enumerable: !0, configurable: !0, writable: !0, value: a }) : t[e] = a;
3
+ var c = (t, e, a) => (u(t, typeof e != "symbol" ? e + "" : e, a), a);
4
+ class m {
5
5
  constructor(e, a) {
6
- r(this, "_definitions");
7
- r(this, "_val");
8
- r(this, "_fromUnit", null);
6
+ c(this, "_definitions");
7
+ c(this, "_val");
8
+ c(this, "_fromUnit", null);
9
9
  this._definitions = a, this._val = e;
10
10
  }
11
11
  from(e) {
@@ -15,11 +15,13 @@ class u {
15
15
  if (!this._fromUnit)
16
16
  throw new Error('Please specify the "from" unit using the from() method before calling to().');
17
17
  this._checkUnit(e);
18
- const a = this._getUnit(e), o = this._getUnit(this._fromUnit);
19
- return this._val * o / a;
18
+ const a = this._getUnit(this._fromUnit), r = this._getUnit(e);
19
+ let o = this._val;
20
+ return a.offset !== 0 && (o -= a.offset), o = o * a.convertValue / r.convertValue, r.offset !== 0 && (o += r.offset), o;
20
21
  }
21
22
  _getUnit(e) {
22
- return this._definitions.units[e].convertValue;
23
+ const a = this._definitions.units[e], r = a.offset ?? 0;
24
+ return { convertValue: a.convertValue, offset: r };
23
25
  }
24
26
  _checkUnit(e) {
25
27
  const a = Object.keys(this._definitions.units);
@@ -27,16 +29,16 @@ class u {
27
29
  throw new Error(`Invalid unit "${e}". Available units: ${a.join(", ")}`);
28
30
  }
29
31
  }
30
- class m {
32
+ class s {
31
33
  constructor(e, a) {
32
- r(this, "_internalConverter");
33
- this._internalConverter = new u(e, a);
34
+ c(this, "_internalConverter");
35
+ this._internalConverter = new m(e, a);
34
36
  }
35
37
  from(e) {
36
- return this._internalConverter.from(e), new s(this._internalConverter);
38
+ return this._internalConverter.from(e), new i(this._internalConverter);
37
39
  }
38
40
  }
39
- class s {
41
+ class i {
40
42
  constructor(e) {
41
43
  this._internalConverter = e;
42
44
  }
@@ -44,7 +46,7 @@ class s {
44
46
  return this._internalConverter.to(e);
45
47
  }
46
48
  }
47
- const n = (t) => (e) => new m(e, t), i = {
49
+ const n = (t) => (e) => new s(e, t), v = {
48
50
  baseUnit: "m/s2",
49
51
  units: {
50
52
  "m/s2": {
@@ -64,7 +66,7 @@ const n = (t) => (e) => new m(e, t), i = {
64
66
  convertValue: 1 / 3.28084
65
67
  }
66
68
  }
67
- }, A = n(i), v = {
69
+ }, I = n(v), V = {
68
70
  baseUnit: "m2",
69
71
  units: {
70
72
  m2: {
@@ -112,7 +114,7 @@ const n = (t) => (e) => new m(e, t), i = {
112
114
  // Conversion factor from m2 to hectare
113
115
  }
114
116
  }
115
- }, N = n(v), V = {
117
+ }, N = n(V), p = {
116
118
  baseUnit: "kg/m3",
117
119
  units: {
118
120
  "kg/m3": {
@@ -136,7 +138,7 @@ const n = (t) => (e) => new m(e, t), i = {
136
138
  convertValue: 1 / 2.20462
137
139
  }
138
140
  }
139
- }, G = n(V), p = {
141
+ }, B = n(p), d = {
140
142
  baseUnit: "C",
141
143
  units: {
142
144
  C: {
@@ -164,7 +166,7 @@ const n = (t) => (e) => new m(e, t), i = {
164
166
  // Conversion factor from C to pC
165
167
  }
166
168
  }
167
- }, I = n(p), d = {
169
+ }, G = n(d), f = {
168
170
  baseUnit: "A",
169
171
  units: {
170
172
  A: {
@@ -192,7 +194,7 @@ const n = (t) => (e) => new m(e, t), i = {
192
194
  // Conversion factor from A to pA
193
195
  }
194
196
  }
195
- }, T = n(d), h = {
197
+ }, T = n(f), h = {
196
198
  baseUnit: "J",
197
199
  units: {
198
200
  J: {
@@ -230,7 +232,7 @@ const n = (t) => (e) => new m(e, t), i = {
230
232
  // Conversion factor from J to BTU
231
233
  }
232
234
  }
233
- }, W = n(h), b = {
235
+ }, W = n(h), g = {
234
236
  baseUnit: "N",
235
237
  units: {
236
238
  N: {
@@ -253,13 +255,17 @@ const n = (t) => (e) => new m(e, t), i = {
253
255
  // Conversion factor from N to kgf
254
256
  }
255
257
  }
256
- }, B = n(b), C = {
258
+ }, H = n(g), b = {
257
259
  baseUnit: "m",
258
260
  units: {
259
261
  m: {
260
262
  name: "Meter",
261
263
  convertValue: 1
262
264
  },
265
+ km: {
266
+ name: "Kilometer",
267
+ convertValue: 1e3
268
+ },
263
269
  mm: {
264
270
  name: "Millimeter",
265
271
  convertValue: 1e-3
@@ -279,9 +285,17 @@ const n = (t) => (e) => new m(e, t), i = {
279
285
  name: "Foot",
280
286
  convertValue: 0.3048
281
287
  // Conversion factor from m to ft
288
+ },
289
+ um: {
290
+ name: "Micrometer",
291
+ convertValue: 1e-6
292
+ },
293
+ nm: {
294
+ name: "Nanometer",
295
+ convertValue: 1e-9
282
296
  }
283
297
  }
284
- }, J = n(C), g = {
298
+ }, J = n(b), C = {
285
299
  baseUnit: "kg/s",
286
300
  units: {
287
301
  "kg/s": {
@@ -326,7 +340,7 @@ const n = (t) => (e) => new m(e, t), i = {
326
340
  // 1 day = 86400 seconds
327
341
  }
328
342
  }
329
- }, j = n(g), f = {
343
+ }, O = n(C), M = {
330
344
  baseUnit: "kg",
331
345
  units: {
332
346
  kg: {
@@ -354,7 +368,7 @@ const n = (t) => (e) => new m(e, t), i = {
354
368
  // Conversion factor from kg to ton
355
369
  }
356
370
  }
357
- }, H = n(f), M = {
371
+ }, j = n(M), S = {
358
372
  baseUnit: "W",
359
373
  units: {
360
374
  W: {
@@ -382,8 +396,8 @@ const n = (t) => (e) => new m(e, t), i = {
382
396
  // Conversion factor from W to cal/s
383
397
  }
384
398
  }
385
- }, O = n(M), y = {
386
- baseUnit: "Pa",
399
+ }, z = n(S), y = {
400
+ baseUnit: "Pag",
387
401
  units: {
388
402
  Pag: {
389
403
  name: "Pascal",
@@ -420,7 +434,7 @@ const n = (t) => (e) => new m(e, t), i = {
420
434
  // Conversion factor from Pa to kg/cm²
421
435
  }
422
436
  }
423
- }, z = n(y), U = {
437
+ }, E = n(y), P = {
424
438
  baseUnit: "Pa",
425
439
  units: {
426
440
  Pa: {
@@ -456,9 +470,50 @@ const n = (t) => (e) => new m(e, t), i = {
456
470
  name: "Kilogram per Square Centimeter",
457
471
  convertValue: 98066.5
458
472
  // Conversion factor from Pa to kg/cm²
473
+ },
474
+ Pag: {
475
+ name: "Pascal",
476
+ convertValue: 1,
477
+ offset: -1
478
+ },
479
+ kPag: {
480
+ name: "Kilopascal",
481
+ convertValue: 1e3,
482
+ offset: -1
483
+ // Conversion factor from Pa to kPa
484
+ },
485
+ MPag: {
486
+ name: "Megapascal",
487
+ convertValue: 1e6,
488
+ offset: -1
489
+ // Conversion factor from Pa to MPa
490
+ },
491
+ barg: {
492
+ name: "Bar",
493
+ convertValue: 1e5,
494
+ offset: -1
495
+ // Conversion factor from Pa to Bar
496
+ },
497
+ atmg: {
498
+ name: "Atmosphere",
499
+ convertValue: 101325,
500
+ offset: -1
501
+ // Standard atmospheric pressure in Pa
502
+ },
503
+ psig: {
504
+ name: "Pound per Square Inch",
505
+ convertValue: 6894.76,
506
+ offset: -1
507
+ // Conversion factor from Pa to psi
508
+ },
509
+ "kg/cm2g": {
510
+ name: "Kilogram per Square Centimeter",
511
+ convertValue: 98066.5,
512
+ offset: -1
513
+ // Conversion factor from Pa to kg/cm²
459
514
  }
460
515
  }
461
- }, E = n(U), S = {
516
+ }, x = n(P), U = {
462
517
  baseUnit: "m/s",
463
518
  units: {
464
519
  "m/s": {
@@ -488,9 +543,13 @@ const n = (t) => (e) => new m(e, t), i = {
488
543
  "ft/h": {
489
544
  name: "Foot per hour",
490
545
  convertValue: 1 / 11811
546
+ },
547
+ mph: {
548
+ name: "Miles per hour",
549
+ convertValue: 2.23694
491
550
  }
492
551
  }
493
- }, x = n(S), P = {
552
+ }, L = n(U), k = {
494
553
  baseUnit: "SCMD",
495
554
  units: {
496
555
  SCMD: {
@@ -521,9 +580,19 @@ const n = (t) => (e) => new m(e, t), i = {
521
580
  name: "Million Million Standard Cubic Feet per Day",
522
581
  convertValue: 1 / 35.3147 * 1e6
523
582
  // Conversion factor from SCMD to MMSCFD
583
+ },
584
+ "Sm3/h": {
585
+ name: "Standard Cubic Meter per Hour",
586
+ convertValue: 24
587
+ // Conversion factor from SCMD to MMSCFD
588
+ },
589
+ "Sft3/h": {
590
+ name: "Standard Cubic Feet per Hour",
591
+ convertValue: 1 / 35.3147 * 24
592
+ // Conversion factor from SCMD to MMSCFD
524
593
  }
525
594
  }
526
- }, L = n(P), k = {
595
+ }, Q = n(k), K = {
527
596
  baseUnit: "N/m",
528
597
  units: {
529
598
  "N/m": {
@@ -536,14 +605,22 @@ const n = (t) => (e) => new m(e, t), i = {
536
605
  },
537
606
  "lbf/ft": {
538
607
  name: "Pound-force per Foot",
539
- convertValue: 1.35582
608
+ convertValue: 14.5939
540
609
  },
541
610
  "mN/m": {
542
611
  name: "Millinewton per Meter",
543
612
  convertValue: 1e-3
613
+ },
614
+ "lbf/in": {
615
+ name: "Pound-force per Inch",
616
+ convertValue: 175.126836
617
+ },
618
+ "ozf/in": {
619
+ name: "Ounce-force per Inch",
620
+ convertValue: 10.945427
544
621
  }
545
622
  }
546
- }, Q = n(k), w = {
623
+ }, Y = n(K), w = {
547
624
  baseUnit: "s",
548
625
  units: {
549
626
  s: {
@@ -566,7 +643,7 @@ const n = (t) => (e) => new m(e, t), i = {
566
643
  // Conversion factor from seconds to days
567
644
  }
568
645
  }
569
- }, Y = n(w), _ = {
646
+ }, R = n(w), q = {
570
647
  baseUnit: "cP",
571
648
  units: {
572
649
  cP: {
@@ -594,7 +671,7 @@ const n = (t) => (e) => new m(e, t), i = {
594
671
  convertValue: 1 / 3.6
595
672
  }
596
673
  }
597
- }, R = n(_), $ = {
674
+ }, X = n(q), F = {
598
675
  baseUnit: "V",
599
676
  // transform: (val) => val * baseValue,
600
677
  units: {
@@ -611,7 +688,7 @@ const n = (t) => (e) => new m(e, t), i = {
611
688
  convertValue: 1e3
612
689
  }
613
690
  }
614
- }, X = n($), q = {
691
+ }, Z = n(F), $ = {
615
692
  baseUnit: "m3",
616
693
  units: {
617
694
  m3: {
@@ -639,7 +716,7 @@ const n = (t) => (e) => new m(e, t), i = {
639
716
  convertValue: 1 / 879.877
640
717
  }
641
718
  }
642
- }, Z = n(q), K = {
719
+ }, ee = n($), _ = {
643
720
  baseUnit: "m3/h",
644
721
  units: {
645
722
  "m3/h": {
@@ -679,27 +756,49 @@ const n = (t) => (e) => new m(e, t), i = {
679
756
  convertValue: 378541e-8 * 3600
680
757
  }
681
758
  }
682
- }, ee = n(K);
759
+ }, ne = n(_), D = {
760
+ baseUnit: "C",
761
+ units: {
762
+ C: {
763
+ name: "Celsius",
764
+ convertValue: 1,
765
+ offset: 0
766
+ },
767
+ F: {
768
+ name: "Fahrenheit",
769
+ convertValue: 5 / 9,
770
+ // Inverse of 9/5
771
+ offset: 32
772
+ },
773
+ K: {
774
+ name: "Kelvin",
775
+ convertValue: 1,
776
+ offset: 273.15
777
+ // Subtract 273.15 to convert from K to C
778
+ }
779
+ }
780
+ }, ae = n(D);
683
781
  export {
684
- A as acceleration,
782
+ I as acceleration,
685
783
  N as area,
686
- G as density,
687
- I as electricCharge,
784
+ B as density,
785
+ G as electricCharge,
688
786
  T as electricCurrent,
689
787
  W as energy,
690
- B as force,
788
+ H as force,
691
789
  J as length,
692
- H as mass,
693
- j as massFlow,
694
- O as power,
695
- E as pressure,
696
- z as pressureManometric,
697
- x as speed,
698
- L as standardVolumetricFlow,
699
- Y as time,
700
- Q as torque,
701
- R as viscosity,
702
- X as voltage,
703
- Z as volume,
704
- ee as volumetricFlow
790
+ j as mass,
791
+ O as massFlow,
792
+ z as power,
793
+ x as pressure,
794
+ E as pressureManometric,
795
+ L as speed,
796
+ Q as standardVolumetricFlow,
797
+ ae as temperature,
798
+ R as time,
799
+ Y as torque,
800
+ X as viscosity,
801
+ Z as voltage,
802
+ ee as volume,
803
+ ne as volumetricFlow
705
804
  };
@@ -1 +1 @@
1
- (function(e,t){typeof exports=="object"&&typeof module<"u"?t(exports):typeof define=="function"&&define.amd?define(["exports"],t):(e=typeof globalThis<"u"?globalThis:e||self,t(e["engineering-unit-converter"]={}))})(this,function(e){"use strict";var O=Object.defineProperty;var H=(e,t,o)=>t in e?O(e,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[t]=o;var c=(e,t,o)=>(H(e,typeof t!="symbol"?t+"":t,o),o);class t{constructor(n,r){c(this,"_definitions");c(this,"_val");c(this,"_fromUnit",null);this._definitions=r,this._val=n}from(n){return this._checkUnit(n),this._fromUnit=n,this}to(n){if(!this._fromUnit)throw new Error('Please specify the "from" unit using the from() method before calling to().');this._checkUnit(n);const r=this._getUnit(n),J=this._getUnit(this._fromUnit);return this._val*J/r}_getUnit(n){return this._definitions.units[n].convertValue}_checkUnit(n){const r=Object.keys(this._definitions.units);if(!r.includes(n))throw new Error(`Invalid unit "${n}". Available units: ${r.join(", ")}`)}}class o{constructor(n,r){c(this,"_internalConverter");this._internalConverter=new t(n,r)}from(n){return this._internalConverter.from(n),new u(this._internalConverter)}}class u{constructor(n){this._internalConverter=n}to(n){return this._internalConverter.to(n)}}const a=l=>n=>new o(n,l),m={baseUnit:"m/s2",units:{"m/s2":{name:"Meter per Second Squared",convertValue:1},"km/s2":{name:"Kilometer per Second Squared",convertValue:1e3},"cm/s2":{name:"Centimeter per Second Squared",convertValue:1/100},"ft/s2":{name:"Foot per Second Squared",convertValue:1/3.28084}}},i=a(m),s={baseUnit:"m2",units:{m2:{name:"Square Meter",convertValue:1},km2:{name:"Square Kilometer",convertValue:1/1e-6},cm2:{name:"Square Centimeter",convertValue:1/1e4},mm2:{name:"Square Millimeter",convertValue:1/1e6},sqin:{name:"Square Inch",convertValue:1/1550.0031},sqft:{name:"Square Foot",convertValue:1/10.763888889},sqyd:{name:"Square Yard",convertValue:1/1.1959876543333339},acre:{name:"Acre",convertValue:1/247105e-9},hectare:{name:"Hectare",convertValue:1/1e-4}}},v=a(s),V={baseUnit:"kg/m3",units:{"kg/m3":{name:"Kilogram per cubic meter",convertValue:1},"lb/ft3":{name:"Pound per cubic foot",convertValue:1/.062427962},"g/cm3":{name:"Gram per cubic centimeter",convertValue:.001},"kg/ft3":{name:"Kilogram per cubic foot",convertValue:1/.0283168},"lb/m3":{name:"Pound per cubic meter",convertValue:1/2.20462}}},d=a(V),h=a({baseUnit:"C",units:{C:{name:"Coulomb",convertValue:1},mC:{name:"MilliCoulomb",convertValue:.001},μC:{name:"MicroCoulomb",convertValue:1e-6},nC:{name:"NanoCoulomb",convertValue:1e-9},pC:{name:"PicoCoulomb",convertValue:1e-12}}}),p=a({baseUnit:"A",units:{A:{name:"Ampere",convertValue:1},mA:{name:"Milliampere",convertValue:.001},μA:{name:"Microampere",convertValue:1e-6},nA:{name:"Nanoampere",convertValue:1e-9},pA:{name:"Picoampere",convertValue:1e-12}}}),b={baseUnit:"J",units:{J:{name:"Joule",convertValue:1},kJ:{name:"Kilojoule",convertValue:1/.001},cal:{name:"Calorie",convertValue:1/.239006},kcal:{name:"Kilocalorie",convertValue:1/239006e-9},Wh:{name:"Watt-hour",convertValue:1/277778e-9},kWh:{name:"Kilowatt-hour",convertValue:1/277778e-12},BTU:{name:"British Thermal Unit",convertValue:1/947817e-9}}},g=a(b),C={baseUnit:"N",units:{N:{name:"Newton",convertValue:1},dyn:{name:"Dyne",convertValue:1e-5},lbf:{name:"Pound-force",convertValue:1/.224809},kgf:{name:"Kilogram-force",convertValue:9.80665}}},f=a(C),M=a({baseUnit:"m",units:{m:{name:"Meter",convertValue:1},mm:{name:"Millimeter",convertValue:.001},cm:{name:"Centimeter",convertValue:.01},in:{name:"Inch",convertValue:.0254},ft:{name:"Foot",convertValue:.3048}}}),y={baseUnit:"kg/s",units:{"kg/s":{name:"Kilogram per second",convertValue:1},"kg/h":{name:"Kilogram per hour",convertValue:1/3600},"lb/day":{name:"Pound per day",convertValue:1/190479},"g/s":{name:"Gram per second",convertValue:.001},"lb/h":{name:"Pound per hour",convertValue:1/(190479/24)},"ton/day":{name:"Ton per day",convertValue:1/(34762.5/365)},"oz/min":{name:"Ounce per minute",convertValue:1/2116.4394433764},"ton/year":{name:"Ton per year",convertValue:1/34762.5},"lb/s":{name:"Pound per second",convertValue:1/(190479/86400)},"kg/day":{name:"Kilogram per day",convertValue:1/86400}}},S=a(y),U=a({baseUnit:"kg",units:{kg:{name:"Kilogram",convertValue:1},g:{name:"Gram",convertValue:.001},lb:{name:"Pound",convertValue:.453592},oz:{name:"Ounce",convertValue:.0283495},ton:{name:"Ton",convertValue:1e3}}}),P={baseUnit:"W",units:{W:{name:"Watt",convertValue:1},kW:{name:"Kilowatt",convertValue:1e3},hp:{name:"Horsepower",convertValue:745.7},"BTU/h":{name:"British Thermal Unit per hour",convertValue:1/3.41214},"cal/s":{name:"Calorie per second",convertValue:1/.23884589662749595}}},k=a(P),w=a({baseUnit:"Pa",units:{Pag:{name:"Pascal",convertValue:1},kPag:{name:"Kilopascal",convertValue:1e3},MPag:{name:"Megapascal",convertValue:1e6},barg:{name:"Bar",convertValue:1e5},atmg:{name:"Atmosphere",convertValue:101325},psig:{name:"Pound per Square Inch",convertValue:6894.76},"kg/cm2g":{name:"Kilogram per Square Centimeter",convertValue:98066.5}}}),q=a({baseUnit:"Pa",units:{Pa:{name:"Pascal",convertValue:1},kPa:{name:"Kilopascal",convertValue:1e3},MPa:{name:"Megapascal",convertValue:1e6},bar:{name:"Bar",convertValue:1e5},atm:{name:"Atmosphere",convertValue:101325},psi:{name:"Pound per Square Inch",convertValue:6894.76},"kg/cm2":{name:"Kilogram per Square Centimeter",convertValue:98066.5}}}),_={baseUnit:"m/s",units:{"m/s":{name:"Meter per second",convertValue:1},"km/h":{name:"Kilometer per hour",convertValue:.277778},"ft/s":{name:"Foot per second",convertValue:.3048},"mi/h":{name:"Mile per hour",convertValue:.44704},knot:{name:"Knot",convertValue:.514444},"m/h":{name:"Meter per hour",convertValue:1/3600},"ft/h":{name:"Foot per hour",convertValue:1/11811}}},$=a(_),K={baseUnit:"SCMD",units:{SCMD:{name:"Standard Cubic Meters per Day",convertValue:1},SCFD:{name:"Standard Cubic Feet per Day",convertValue:1/35.3147},MSCMD:{name:"Million Standard Cubic Meters per Day",convertValue:1e3},MMSCMD:{name:"Million Million Standard Cubic Meters per Day",convertValue:1e6},MSCFD:{name:"Million Standard Cubic Feet per Day",convertValue:1/35.3147*1e3},MMSCFD:{name:"Million Million Standard Cubic Feet per Day",convertValue:1/35.3147*1e6}}},F=a(K),D=a({baseUnit:"N/m",units:{"N/m":{name:"Newton per Meter",convertValue:1},"dyn/cm":{name:"Dyne per Centimeter",convertValue:.001},"lbf/ft":{name:"Pound-force per Foot",convertValue:1.35582},"mN/m":{name:"Millinewton per Meter",convertValue:.001}}}),A=a({baseUnit:"s",units:{s:{name:"Second",convertValue:1},min:{name:"Minute",convertValue:60},hr:{name:"Hour",convertValue:3600},day:{name:"Day",convertValue:86400}}}),T={baseUnit:"cP",units:{cP:{name:"Centipoise",convertValue:1},Pas:{name:"Pascal second",convertValue:1/.001},"lb/fts":{name:"Pound per second-foot",convertValue:1/.000671968994813},"kg/ms":{name:"Kilogram per meter-second-hour",convertValue:1/.001},"lb/fth":{name:"Pound per hour-foot",convertValue:1/2.4190883105},"kg/mh":{name:"Kilogram per meter-second-meter",convertValue:1/3.6}}},N=a(T),G=a({baseUnit:"V",units:{V:{name:"Volt",convertValue:1},mV:{name:"Millivolt",convertValue:.001},kV:{name:"Kilovolt",convertValue:1e3}}}),I={baseUnit:"m3",units:{m3:{name:"Cubic Meter",convertValue:1},liter:{name:"Liter",convertValue:.001},cm3:{name:"Cubic Centimeter",convertValue:1e-6},mm3:{name:"Cubic Millimeter",convertValue:1e-9},gallon:{name:"Gallon",convertValue:.00454609},quart:{name:"Quart",convertValue:1/879.877}}},W=a(I),B={baseUnit:"m3/h",units:{"m3/h":{name:"Cubic meter per hour",convertValue:1},"m3/day":{name:"Cubic meter per day",convertValue:1/24},"ft3/h":{name:"Cubic foot per hour",convertValue:.0283168},"ft3/day":{name:"Cubic foot per day",convertValue:.0283168/24},"gal/h":{name:"Gallon per hour",convertValue:.00378541},"gal/day":{name:"Gallon per day",convertValue:.00378541/24},"m3/s":{name:"Cubic meter per second",convertValue:3600},"ft3/s":{name:"Cubic foot per second",convertValue:1/.00980963},"gal/s":{name:"Gallon per second",convertValue:.00378541*3600}}},j=a(B);e.acceleration=i,e.area=v,e.density=d,e.electricCharge=h,e.electricCurrent=p,e.energy=g,e.force=f,e.length=M,e.mass=U,e.massFlow=S,e.power=k,e.pressure=q,e.pressureManometric=w,e.speed=$,e.standardVolumetricFlow=F,e.time=A,e.torque=D,e.viscosity=N,e.voltage=G,e.volume=W,e.volumetricFlow=j,Object.defineProperty(e,Symbol.toStringTag,{value:"Module"})});
1
+ (function(e,t){typeof exports=="object"&&typeof module<"u"?t(exports):typeof define=="function"&&define.amd?define(["exports"],t):(e=typeof globalThis<"u"?globalThis:e||self,t(e["engineering-unit-converter"]={}))})(this,function(e){"use strict";var E=Object.defineProperty;var L=(e,t,o)=>t in e?E(e,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[t]=o;var u=(e,t,o)=>(L(e,typeof t!="symbol"?t+"":t,o),o);class t{constructor(a,r){u(this,"_definitions");u(this,"_val");u(this,"_fromUnit",null);this._definitions=r,this._val=a}from(a){return this._checkUnit(a),this._fromUnit=a,this}to(a){if(!this._fromUnit)throw new Error('Please specify the "from" unit using the from() method before calling to().');this._checkUnit(a);const r=this._getUnit(this._fromUnit),c=this._getUnit(a);let l=this._val;return r.offset!==0&&(l-=r.offset),l=l*r.convertValue/c.convertValue,c.offset!==0&&(l+=c.offset),l}_getUnit(a){const r=this._definitions.units[a],c=r.offset??0;return{convertValue:r.convertValue,offset:c}}_checkUnit(a){const r=Object.keys(this._definitions.units);if(!r.includes(a))throw new Error(`Invalid unit "${a}". Available units: ${r.join(", ")}`)}}class o{constructor(a,r){u(this,"_internalConverter");this._internalConverter=new t(a,r)}from(a){return this._internalConverter.from(a),new i(this._internalConverter)}}class i{constructor(a){this._internalConverter=a}to(a){return this._internalConverter.to(a)}}const n=m=>a=>new o(a,m),s={baseUnit:"m/s2",units:{"m/s2":{name:"Meter per Second Squared",convertValue:1},"km/s2":{name:"Kilometer per Second Squared",convertValue:1e3},"cm/s2":{name:"Centimeter per Second Squared",convertValue:1/100},"ft/s2":{name:"Foot per Second Squared",convertValue:1/3.28084}}},v=n(s),V={baseUnit:"m2",units:{m2:{name:"Square Meter",convertValue:1},km2:{name:"Square Kilometer",convertValue:1/1e-6},cm2:{name:"Square Centimeter",convertValue:1/1e4},mm2:{name:"Square Millimeter",convertValue:1/1e6},sqin:{name:"Square Inch",convertValue:1/1550.0031},sqft:{name:"Square Foot",convertValue:1/10.763888889},sqyd:{name:"Square Yard",convertValue:1/1.1959876543333339},acre:{name:"Acre",convertValue:1/247105e-9},hectare:{name:"Hectare",convertValue:1/1e-4}}},d=n(V),f={baseUnit:"kg/m3",units:{"kg/m3":{name:"Kilogram per cubic meter",convertValue:1},"lb/ft3":{name:"Pound per cubic foot",convertValue:1/.062427962},"g/cm3":{name:"Gram per cubic centimeter",convertValue:.001},"kg/ft3":{name:"Kilogram per cubic foot",convertValue:1/.0283168},"lb/m3":{name:"Pound per cubic meter",convertValue:1/2.20462}}},h=n(f),p=n({baseUnit:"C",units:{C:{name:"Coulomb",convertValue:1},mC:{name:"MilliCoulomb",convertValue:.001},μC:{name:"MicroCoulomb",convertValue:1e-6},nC:{name:"NanoCoulomb",convertValue:1e-9},pC:{name:"PicoCoulomb",convertValue:1e-12}}}),g=n({baseUnit:"A",units:{A:{name:"Ampere",convertValue:1},mA:{name:"Milliampere",convertValue:.001},μA:{name:"Microampere",convertValue:1e-6},nA:{name:"Nanoampere",convertValue:1e-9},pA:{name:"Picoampere",convertValue:1e-12}}}),b={baseUnit:"J",units:{J:{name:"Joule",convertValue:1},kJ:{name:"Kilojoule",convertValue:1/.001},cal:{name:"Calorie",convertValue:1/.239006},kcal:{name:"Kilocalorie",convertValue:1/239006e-9},Wh:{name:"Watt-hour",convertValue:1/277778e-9},kWh:{name:"Kilowatt-hour",convertValue:1/277778e-12},BTU:{name:"British Thermal Unit",convertValue:1/947817e-9}}},C=n(b),M={baseUnit:"N",units:{N:{name:"Newton",convertValue:1},dyn:{name:"Dyne",convertValue:1e-5},lbf:{name:"Pound-force",convertValue:1/.224809},kgf:{name:"Kilogram-force",convertValue:9.80665}}},y=n(M),S=n({baseUnit:"m",units:{m:{name:"Meter",convertValue:1},km:{name:"Kilometer",convertValue:1e3},mm:{name:"Millimeter",convertValue:.001},cm:{name:"Centimeter",convertValue:.01},in:{name:"Inch",convertValue:.0254},ft:{name:"Foot",convertValue:.3048},um:{name:"Micrometer",convertValue:1e-6},nm:{name:"Nanometer",convertValue:1e-9}}}),P={baseUnit:"kg/s",units:{"kg/s":{name:"Kilogram per second",convertValue:1},"kg/h":{name:"Kilogram per hour",convertValue:1/3600},"lb/day":{name:"Pound per day",convertValue:1/190479},"g/s":{name:"Gram per second",convertValue:.001},"lb/h":{name:"Pound per hour",convertValue:1/(190479/24)},"ton/day":{name:"Ton per day",convertValue:1/(34762.5/365)},"oz/min":{name:"Ounce per minute",convertValue:1/2116.4394433764},"ton/year":{name:"Ton per year",convertValue:1/34762.5},"lb/s":{name:"Pound per second",convertValue:1/(190479/86400)},"kg/day":{name:"Kilogram per day",convertValue:1/86400}}},U=n(P),k=n({baseUnit:"kg",units:{kg:{name:"Kilogram",convertValue:1},g:{name:"Gram",convertValue:.001},lb:{name:"Pound",convertValue:.453592},oz:{name:"Ounce",convertValue:.0283495},ton:{name:"Ton",convertValue:1e3}}}),K={baseUnit:"W",units:{W:{name:"Watt",convertValue:1},kW:{name:"Kilowatt",convertValue:1e3},hp:{name:"Horsepower",convertValue:745.7},"BTU/h":{name:"British Thermal Unit per hour",convertValue:1/3.41214},"cal/s":{name:"Calorie per second",convertValue:1/.23884589662749595}}},q=n(K),w=n({baseUnit:"Pag",units:{Pag:{name:"Pascal",convertValue:1},kPag:{name:"Kilopascal",convertValue:1e3},MPag:{name:"Megapascal",convertValue:1e6},barg:{name:"Bar",convertValue:1e5},atmg:{name:"Atmosphere",convertValue:101325},psig:{name:"Pound per Square Inch",convertValue:6894.76},"kg/cm2g":{name:"Kilogram per Square Centimeter",convertValue:98066.5}}}),F=n({baseUnit:"Pa",units:{Pa:{name:"Pascal",convertValue:1},kPa:{name:"Kilopascal",convertValue:1e3},MPa:{name:"Megapascal",convertValue:1e6},bar:{name:"Bar",convertValue:1e5},atm:{name:"Atmosphere",convertValue:101325},psi:{name:"Pound per Square Inch",convertValue:6894.76},"kg/cm2":{name:"Kilogram per Square Centimeter",convertValue:98066.5},Pag:{name:"Pascal",convertValue:1,offset:-1},kPag:{name:"Kilopascal",convertValue:1e3,offset:-1},MPag:{name:"Megapascal",convertValue:1e6,offset:-1},barg:{name:"Bar",convertValue:1e5,offset:-1},atmg:{name:"Atmosphere",convertValue:101325,offset:-1},psig:{name:"Pound per Square Inch",convertValue:6894.76,offset:-1},"kg/cm2g":{name:"Kilogram per Square Centimeter",convertValue:98066.5,offset:-1}}}),$={baseUnit:"m/s",units:{"m/s":{name:"Meter per second",convertValue:1},"km/h":{name:"Kilometer per hour",convertValue:.277778},"ft/s":{name:"Foot per second",convertValue:.3048},"mi/h":{name:"Mile per hour",convertValue:.44704},knot:{name:"Knot",convertValue:.514444},"m/h":{name:"Meter per hour",convertValue:1/3600},"ft/h":{name:"Foot per hour",convertValue:1/11811},mph:{name:"Miles per hour",convertValue:2.23694}}},_=n($),D={baseUnit:"SCMD",units:{SCMD:{name:"Standard Cubic Meters per Day",convertValue:1},SCFD:{name:"Standard Cubic Feet per Day",convertValue:1/35.3147},MSCMD:{name:"Million Standard Cubic Meters per Day",convertValue:1e3},MMSCMD:{name:"Million Million Standard Cubic Meters per Day",convertValue:1e6},MSCFD:{name:"Million Standard Cubic Feet per Day",convertValue:1/35.3147*1e3},MMSCFD:{name:"Million Million Standard Cubic Feet per Day",convertValue:1/35.3147*1e6},"Sm3/h":{name:"Standard Cubic Meter per Hour",convertValue:24},"Sft3/h":{name:"Standard Cubic Feet per Hour",convertValue:1/35.3147*24}}},A=n(D),I=n({baseUnit:"N/m",units:{"N/m":{name:"Newton per Meter",convertValue:1},"dyn/cm":{name:"Dyne per Centimeter",convertValue:.001},"lbf/ft":{name:"Pound-force per Foot",convertValue:14.5939},"mN/m":{name:"Millinewton per Meter",convertValue:.001},"lbf/in":{name:"Pound-force per Inch",convertValue:175.126836},"ozf/in":{name:"Ounce-force per Inch",convertValue:10.945427}}}),N=n({baseUnit:"s",units:{s:{name:"Second",convertValue:1},min:{name:"Minute",convertValue:60},hr:{name:"Hour",convertValue:3600},day:{name:"Day",convertValue:86400}}}),T={baseUnit:"cP",units:{cP:{name:"Centipoise",convertValue:1},Pas:{name:"Pascal second",convertValue:1/.001},"lb/fts":{name:"Pound per second-foot",convertValue:1/.000671968994813},"kg/ms":{name:"Kilogram per meter-second-hour",convertValue:1/.001},"lb/fth":{name:"Pound per hour-foot",convertValue:1/2.4190883105},"kg/mh":{name:"Kilogram per meter-second-meter",convertValue:1/3.6}}},B=n(T),G=n({baseUnit:"V",units:{V:{name:"Volt",convertValue:1},mV:{name:"Millivolt",convertValue:.001},kV:{name:"Kilovolt",convertValue:1e3}}}),W={baseUnit:"m3",units:{m3:{name:"Cubic Meter",convertValue:1},liter:{name:"Liter",convertValue:.001},cm3:{name:"Cubic Centimeter",convertValue:1e-6},mm3:{name:"Cubic Millimeter",convertValue:1e-9},gallon:{name:"Gallon",convertValue:.00454609},quart:{name:"Quart",convertValue:1/879.877}}},j=n(W),H={baseUnit:"m3/h",units:{"m3/h":{name:"Cubic meter per hour",convertValue:1},"m3/day":{name:"Cubic meter per day",convertValue:1/24},"ft3/h":{name:"Cubic foot per hour",convertValue:.0283168},"ft3/day":{name:"Cubic foot per day",convertValue:.0283168/24},"gal/h":{name:"Gallon per hour",convertValue:.00378541},"gal/day":{name:"Gallon per day",convertValue:.00378541/24},"m3/s":{name:"Cubic meter per second",convertValue:3600},"ft3/s":{name:"Cubic foot per second",convertValue:1/.00980963},"gal/s":{name:"Gallon per second",convertValue:.00378541*3600}}},O=n(H),J={baseUnit:"C",units:{C:{name:"Celsius",convertValue:1,offset:0},F:{name:"Fahrenheit",convertValue:5/9,offset:32},K:{name:"Kelvin",convertValue:1,offset:273.15}}},z=n(J);e.acceleration=v,e.area=d,e.density=h,e.electricCharge=p,e.electricCurrent=g,e.energy=C,e.force=y,e.length=S,e.mass=k,e.massFlow=U,e.power=q,e.pressure=F,e.pressureManometric=w,e.speed=_,e.standardVolumetricFlow=A,e.temperature=z,e.time=N,e.torque=I,e.viscosity=B,e.voltage=G,e.volume=j,e.volumetricFlow=O,Object.defineProperty(e,Symbol.toStringTag,{value:"Module"})});
package/dist/index.d.ts CHANGED
@@ -19,3 +19,4 @@ export { default as viscosity } from './units/viscosity';
19
19
  export { default as voltage } from './units/voltage';
20
20
  export { default as volume } from './units/volume';
21
21
  export { default as volumetricFlow } from './units/volumetric-flow';
22
+ export { default as temperature } from './units/temperature';
package/dist/types.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  export type UnitsValues = {
2
2
  name: string;
3
3
  convertValue: number;
4
+ offset?: number;
4
5
  };
5
6
  export type VoltageUnits = {
6
7
  V: UnitsValues;
@@ -67,10 +68,13 @@ export type Viscosity = {
67
68
  };
68
69
  export type LengthUnits = {
69
70
  mm: UnitsValues;
71
+ km: UnitsValues;
70
72
  cm: UnitsValues;
71
73
  m: UnitsValues;
72
74
  in: UnitsValues;
73
75
  ft: UnitsValues;
76
+ um: UnitsValues;
77
+ nm: UnitsValues;
74
78
  };
75
79
  export type Length = {
76
80
  baseUnit: 'm';
@@ -95,6 +99,7 @@ export type SpeedUnits = {
95
99
  'knot': UnitsValues;
96
100
  'm/h': UnitsValues;
97
101
  'ft/h': UnitsValues;
102
+ 'mph': UnitsValues;
98
103
  };
99
104
  export type Speed = {
100
105
  baseUnit: 'm/s';
@@ -166,6 +171,8 @@ export type TorqueUnits = {
166
171
  'dyn/cm': UnitsValues;
167
172
  'lbf/ft': UnitsValues;
168
173
  'mN/m': UnitsValues;
174
+ 'lbf/in': UnitsValues;
175
+ 'ozf/in': UnitsValues;
169
176
  };
170
177
  export type Torque = {
171
178
  baseUnit: 'N/m';
@@ -221,6 +228,13 @@ export type PressureUnits = {
221
228
  'atm': UnitsValues;
222
229
  'psi': UnitsValues;
223
230
  'kg/cm2': UnitsValues;
231
+ 'Pag': UnitsValues;
232
+ 'kPag': UnitsValues;
233
+ 'MPag': UnitsValues;
234
+ 'barg': UnitsValues;
235
+ 'atmg': UnitsValues;
236
+ 'psig': UnitsValues;
237
+ 'kg/cm2g': UnitsValues;
224
238
  };
225
239
  export type Pressure = {
226
240
  baseUnit: 'Pa';
@@ -236,7 +250,7 @@ export type PressureManometricUnits = {
236
250
  'kg/cm2g': UnitsValues;
237
251
  };
238
252
  export type PressureManometric = {
239
- baseUnit: 'Pa';
253
+ baseUnit: 'Pag';
240
254
  units: PressureManometricUnits;
241
255
  };
242
256
  export type StandardVolumetricFlowUnits = {
@@ -246,12 +260,23 @@ export type StandardVolumetricFlowUnits = {
246
260
  'MMSCMD': UnitsValues;
247
261
  'MSCFD': UnitsValues;
248
262
  'MMSCFD': UnitsValues;
263
+ 'Sm3/h': UnitsValues;
264
+ 'Sft3/h': UnitsValues;
249
265
  };
250
266
  export type StandardVolumetricFlow = {
251
267
  baseUnit: 'SCMD';
252
268
  units: StandardVolumetricFlowUnits;
253
269
  };
254
- export type Measurement = Voltage | MassFlow | VolumetricFlow | Density | Viscosity | Length | Mass | Speed | Power | Energy | Area | Volume | Force | Torque | Time | ElectricCharge | ElectricCurrent | Acceleration | Pressure | PressureManometric | StandardVolumetricFlow;
270
+ export type TemperatureUnits = {
271
+ 'C': UnitsValues;
272
+ 'F': UnitsValues;
273
+ 'K': UnitsValues;
274
+ };
275
+ export type Temperature = {
276
+ baseUnit: 'C';
277
+ units: TemperatureUnits;
278
+ };
279
+ export type Measurement = Voltage | MassFlow | VolumetricFlow | Density | Viscosity | Length | Mass | Speed | Power | Energy | Area | Volume | Force | Torque | Time | ElectricCharge | ElectricCurrent | Acceleration | Pressure | PressureManometric | StandardVolumetricFlow | Temperature;
255
280
  export type MeasurementUnits<T extends Measurement> = T extends {
256
281
  units: infer U;
257
282
  } ? keyof U : never;
@@ -0,0 +1,9 @@
1
+ import { Temperature } from "../types";
2
+ declare const _default: (val: number) => {
3
+ readonly _internalConverter: import("../internalConverter").default<Temperature>;
4
+ from<U extends keyof import("../types").TemperatureUnits>(fromUnit: U): {
5
+ readonly _internalConverter: import("../internalConverter").default<Temperature>;
6
+ to<U_1 extends keyof import("../types").TemperatureUnits>(toUnit: U_1): number;
7
+ };
8
+ };
9
+ export default _default;
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "type": "git",
5
5
  "url": "git+https://github.com/alanhaertel/engineering-unit-converter.git"
6
6
  },
7
- "version": "0.0.9",
7
+ "version": "0.0.11",
8
8
  "keywords": [
9
9
  "units",
10
10
  "engineering",