formulab 0.5.1 → 0.9.0

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 (258) hide show
  1. package/CHANGELOG.md +84 -0
  2. package/README.md +90 -26
  3. package/dist/automotive/chargingLoss.d.ts +15 -0
  4. package/dist/automotive/chargingLoss.d.ts.map +1 -0
  5. package/dist/automotive/chargingLoss.js +62 -0
  6. package/dist/automotive/chargingLoss.js.map +1 -0
  7. package/dist/automotive/index.d.ts +2 -1
  8. package/dist/automotive/index.d.ts.map +1 -1
  9. package/dist/automotive/index.js +1 -0
  10. package/dist/automotive/index.js.map +1 -1
  11. package/dist/automotive/types.d.ts +23 -0
  12. package/dist/automotive/types.d.ts.map +1 -1
  13. package/dist/battery/guards.d.ts +7 -0
  14. package/dist/battery/guards.d.ts.map +1 -0
  15. package/dist/battery/guards.js +17 -0
  16. package/dist/battery/guards.js.map +1 -0
  17. package/dist/battery/index.d.ts +1 -0
  18. package/dist/battery/index.d.ts.map +1 -1
  19. package/dist/battery/index.js +2 -0
  20. package/dist/battery/index.js.map +1 -1
  21. package/dist/chemical/flowControl.d.ts +14 -0
  22. package/dist/chemical/flowControl.d.ts.map +1 -0
  23. package/dist/chemical/flowControl.js +69 -0
  24. package/dist/chemical/flowControl.js.map +1 -0
  25. package/dist/chemical/guards.d.ts +17 -0
  26. package/dist/chemical/guards.d.ts.map +1 -0
  27. package/dist/chemical/guards.js +54 -0
  28. package/dist/chemical/guards.js.map +1 -0
  29. package/dist/chemical/index.d.ts +5 -1
  30. package/dist/chemical/index.d.ts.map +1 -1
  31. package/dist/chemical/index.js +5 -0
  32. package/dist/chemical/index.js.map +1 -1
  33. package/dist/chemical/pid.d.ts +14 -0
  34. package/dist/chemical/pid.d.ts.map +1 -0
  35. package/dist/chemical/pid.js +103 -0
  36. package/dist/chemical/pid.js.map +1 -0
  37. package/dist/chemical/reliefValve.d.ts +14 -0
  38. package/dist/chemical/reliefValve.d.ts.map +1 -0
  39. package/dist/chemical/reliefValve.js +98 -0
  40. package/dist/chemical/reliefValve.js.map +1 -0
  41. package/dist/chemical/types.d.ts +63 -0
  42. package/dist/chemical/types.d.ts.map +1 -1
  43. package/dist/construction/guards.d.ts +7 -0
  44. package/dist/construction/guards.d.ts.map +1 -0
  45. package/dist/construction/guards.js +31 -0
  46. package/dist/construction/guards.js.map +1 -0
  47. package/dist/construction/index.d.ts +1 -0
  48. package/dist/construction/index.d.ts.map +1 -1
  49. package/dist/construction/index.js +2 -0
  50. package/dist/construction/index.js.map +1 -1
  51. package/dist/electronics/guards.d.ts +7 -0
  52. package/dist/electronics/guards.d.ts.map +1 -0
  53. package/dist/electronics/guards.js +17 -0
  54. package/dist/electronics/guards.js.map +1 -0
  55. package/dist/electronics/index.d.ts +1 -0
  56. package/dist/electronics/index.d.ts.map +1 -1
  57. package/dist/electronics/index.js +2 -0
  58. package/dist/electronics/index.js.map +1 -1
  59. package/dist/energy/boilerEfficiency.d.ts +13 -0
  60. package/dist/energy/boilerEfficiency.d.ts.map +1 -0
  61. package/dist/energy/boilerEfficiency.js +46 -0
  62. package/dist/energy/boilerEfficiency.js.map +1 -0
  63. package/dist/energy/cusum.d.ts +15 -0
  64. package/dist/energy/cusum.d.ts.map +1 -0
  65. package/dist/energy/cusum.js +71 -0
  66. package/dist/energy/cusum.js.map +1 -0
  67. package/dist/energy/degreeDay.d.ts +13 -0
  68. package/dist/energy/degreeDay.d.ts.map +1 -0
  69. package/dist/energy/degreeDay.js +46 -0
  70. package/dist/energy/degreeDay.js.map +1 -0
  71. package/dist/energy/heatPump.d.ts +13 -0
  72. package/dist/energy/heatPump.d.ts.map +1 -0
  73. package/dist/energy/heatPump.js +48 -0
  74. package/dist/energy/heatPump.js.map +1 -0
  75. package/dist/energy/index.d.ts +9 -1
  76. package/dist/energy/index.d.ts.map +1 -1
  77. package/dist/energy/index.js +8 -0
  78. package/dist/energy/index.js.map +1 -1
  79. package/dist/energy/insulationRoi.d.ts +14 -0
  80. package/dist/energy/insulationRoi.d.ts.map +1 -0
  81. package/dist/energy/insulationRoi.js +52 -0
  82. package/dist/energy/insulationRoi.js.map +1 -0
  83. package/dist/energy/ledRoi.d.ts +14 -0
  84. package/dist/energy/ledRoi.d.ts.map +1 -0
  85. package/dist/energy/ledRoi.js +49 -0
  86. package/dist/energy/ledRoi.js.map +1 -0
  87. package/dist/energy/transformerLoss.d.ts +13 -0
  88. package/dist/energy/transformerLoss.d.ts.map +1 -0
  89. package/dist/energy/transformerLoss.js +63 -0
  90. package/dist/energy/transformerLoss.js.map +1 -0
  91. package/dist/energy/types.d.ts +168 -0
  92. package/dist/energy/types.d.ts.map +1 -1
  93. package/dist/energy/windOutput.d.ts +14 -0
  94. package/dist/energy/windOutput.d.ts.map +1 -0
  95. package/dist/energy/windOutput.js +77 -0
  96. package/dist/energy/windOutput.js.map +1 -0
  97. package/dist/food/index.d.ts +3 -1
  98. package/dist/food/index.d.ts.map +1 -1
  99. package/dist/food/index.js +2 -0
  100. package/dist/food/index.js.map +1 -1
  101. package/dist/food/stabilityStudy.d.ts +15 -0
  102. package/dist/food/stabilityStudy.d.ts.map +1 -0
  103. package/dist/food/stabilityStudy.js +92 -0
  104. package/dist/food/stabilityStudy.js.map +1 -0
  105. package/dist/food/types.d.ts +43 -0
  106. package/dist/food/types.d.ts.map +1 -1
  107. package/dist/food/waterActivity.d.ts +17 -0
  108. package/dist/food/waterActivity.d.ts.map +1 -0
  109. package/dist/food/waterActivity.js +63 -0
  110. package/dist/food/waterActivity.js.map +1 -0
  111. package/dist/logistics/abcAnalysis.d.ts +15 -0
  112. package/dist/logistics/abcAnalysis.d.ts.map +1 -0
  113. package/dist/logistics/abcAnalysis.js +101 -0
  114. package/dist/logistics/abcAnalysis.js.map +1 -0
  115. package/dist/logistics/index.d.ts +4 -1
  116. package/dist/logistics/index.d.ts.map +1 -1
  117. package/dist/logistics/index.js +3 -0
  118. package/dist/logistics/index.js.map +1 -1
  119. package/dist/logistics/inventoryTurnover.d.ts +13 -0
  120. package/dist/logistics/inventoryTurnover.d.ts.map +1 -0
  121. package/dist/logistics/inventoryTurnover.js +36 -0
  122. package/dist/logistics/inventoryTurnover.js.map +1 -0
  123. package/dist/logistics/loadCapacity.d.ts +13 -0
  124. package/dist/logistics/loadCapacity.d.ts.map +1 -0
  125. package/dist/logistics/loadCapacity.js +46 -0
  126. package/dist/logistics/loadCapacity.js.map +1 -0
  127. package/dist/logistics/types.d.ts +78 -0
  128. package/dist/logistics/types.d.ts.map +1 -1
  129. package/dist/metal/guards.d.ts +12 -0
  130. package/dist/metal/guards.d.ts.map +1 -0
  131. package/dist/metal/guards.js +36 -0
  132. package/dist/metal/guards.js.map +1 -0
  133. package/dist/metal/index.d.ts +1 -0
  134. package/dist/metal/index.d.ts.map +1 -1
  135. package/dist/metal/index.js +2 -0
  136. package/dist/metal/index.js.map +1 -1
  137. package/dist/quality/cmk.d.ts +17 -0
  138. package/dist/quality/cmk.d.ts.map +1 -0
  139. package/dist/quality/cmk.js +43 -0
  140. package/dist/quality/cmk.js.map +1 -0
  141. package/dist/quality/gageRR.d.ts +18 -0
  142. package/dist/quality/gageRR.d.ts.map +1 -0
  143. package/dist/quality/gageRR.js +110 -0
  144. package/dist/quality/gageRR.js.map +1 -0
  145. package/dist/quality/index.d.ts +5 -1
  146. package/dist/quality/index.d.ts.map +1 -1
  147. package/dist/quality/index.js +4 -0
  148. package/dist/quality/index.js.map +1 -1
  149. package/dist/quality/paretoAnalysis.d.ts +15 -0
  150. package/dist/quality/paretoAnalysis.d.ts.map +1 -0
  151. package/dist/quality/paretoAnalysis.js +92 -0
  152. package/dist/quality/paretoAnalysis.js.map +1 -0
  153. package/dist/quality/types.d.ts +91 -0
  154. package/dist/quality/types.d.ts.map +1 -1
  155. package/dist/quality/weibull.d.ts +17 -0
  156. package/dist/quality/weibull.d.ts.map +1 -0
  157. package/dist/quality/weibull.js +106 -0
  158. package/dist/quality/weibull.js.map +1 -0
  159. package/dist/safety/arcFlash.d.ts +14 -0
  160. package/dist/safety/arcFlash.d.ts.map +1 -0
  161. package/dist/safety/arcFlash.js +90 -0
  162. package/dist/safety/arcFlash.js.map +1 -0
  163. package/dist/safety/confinedSpace.d.ts +15 -0
  164. package/dist/safety/confinedSpace.d.ts.map +1 -0
  165. package/dist/safety/confinedSpace.js +116 -0
  166. package/dist/safety/confinedSpace.js.map +1 -0
  167. package/dist/safety/ergonomicRisk.d.ts +9 -0
  168. package/dist/safety/ergonomicRisk.d.ts.map +1 -0
  169. package/dist/safety/ergonomicRisk.js +208 -0
  170. package/dist/safety/ergonomicRisk.js.map +1 -0
  171. package/dist/safety/illuminance.d.ts +13 -0
  172. package/dist/safety/illuminance.d.ts.map +1 -0
  173. package/dist/safety/illuminance.js +91 -0
  174. package/dist/safety/illuminance.js.map +1 -0
  175. package/dist/safety/index.d.ts +8 -1
  176. package/dist/safety/index.d.ts.map +1 -1
  177. package/dist/safety/index.js +7 -0
  178. package/dist/safety/index.js.map +1 -1
  179. package/dist/safety/ladderAngle.d.ts +16 -0
  180. package/dist/safety/ladderAngle.d.ts.map +1 -0
  181. package/dist/safety/ladderAngle.js +87 -0
  182. package/dist/safety/ladderAngle.js.map +1 -0
  183. package/dist/safety/lel.d.ts +14 -0
  184. package/dist/safety/lel.d.ts.map +1 -0
  185. package/dist/safety/lel.js +66 -0
  186. package/dist/safety/lel.js.map +1 -0
  187. package/dist/safety/thermalComfort.d.ts +14 -0
  188. package/dist/safety/thermalComfort.d.ts.map +1 -0
  189. package/dist/safety/thermalComfort.js +96 -0
  190. package/dist/safety/thermalComfort.js.map +1 -0
  191. package/dist/safety/types.d.ts +164 -0
  192. package/dist/safety/types.d.ts.map +1 -1
  193. package/dist/utility/bilinearInterpolation.d.ts +3 -0
  194. package/dist/utility/bilinearInterpolation.d.ts.map +1 -0
  195. package/dist/utility/bilinearInterpolation.js +47 -0
  196. package/dist/utility/bilinearInterpolation.js.map +1 -0
  197. package/dist/utility/correlation.d.ts +3 -0
  198. package/dist/utility/correlation.d.ts.map +1 -0
  199. package/dist/utility/correlation.js +29 -0
  200. package/dist/utility/correlation.js.map +1 -0
  201. package/dist/utility/depreciation.d.ts +3 -0
  202. package/dist/utility/depreciation.d.ts.map +1 -0
  203. package/dist/utility/depreciation.js +57 -0
  204. package/dist/utility/depreciation.js.map +1 -0
  205. package/dist/utility/histogram.d.ts +3 -0
  206. package/dist/utility/histogram.d.ts.map +1 -0
  207. package/dist/utility/histogram.js +42 -0
  208. package/dist/utility/histogram.js.map +1 -0
  209. package/dist/utility/index.d.ts +15 -1
  210. package/dist/utility/index.d.ts.map +1 -1
  211. package/dist/utility/index.js +14 -0
  212. package/dist/utility/index.js.map +1 -1
  213. package/dist/utility/lcc.d.ts +3 -0
  214. package/dist/utility/lcc.d.ts.map +1 -0
  215. package/dist/utility/lcc.js +26 -0
  216. package/dist/utility/lcc.js.map +1 -0
  217. package/dist/utility/linearInterpolation.d.ts +3 -0
  218. package/dist/utility/linearInterpolation.d.ts.map +1 -0
  219. package/dist/utility/linearInterpolation.js +42 -0
  220. package/dist/utility/linearInterpolation.js.map +1 -0
  221. package/dist/utility/movingAverage.d.ts +3 -0
  222. package/dist/utility/movingAverage.d.ts.map +1 -0
  223. package/dist/utility/movingAverage.js +41 -0
  224. package/dist/utility/movingAverage.js.map +1 -0
  225. package/dist/utility/normalize.d.ts +3 -0
  226. package/dist/utility/normalize.d.ts.map +1 -0
  227. package/dist/utility/normalize.js +35 -0
  228. package/dist/utility/normalize.js.map +1 -0
  229. package/dist/utility/npv.d.ts +3 -0
  230. package/dist/utility/npv.d.ts.map +1 -0
  231. package/dist/utility/npv.js +45 -0
  232. package/dist/utility/npv.js.map +1 -0
  233. package/dist/utility/percentile.d.ts +3 -0
  234. package/dist/utility/percentile.d.ts.map +1 -0
  235. package/dist/utility/percentile.js +24 -0
  236. package/dist/utility/percentile.js.map +1 -0
  237. package/dist/utility/regression.d.ts +3 -0
  238. package/dist/utility/regression.d.ts.map +1 -0
  239. package/dist/utility/regression.js +40 -0
  240. package/dist/utility/regression.js.map +1 -0
  241. package/dist/utility/roi.d.ts +3 -0
  242. package/dist/utility/roi.d.ts.map +1 -0
  243. package/dist/utility/roi.js +19 -0
  244. package/dist/utility/roi.js.map +1 -0
  245. package/dist/utility/statistics.d.ts +3 -0
  246. package/dist/utility/statistics.d.ts.map +1 -0
  247. package/dist/utility/statistics.js +34 -0
  248. package/dist/utility/statistics.js.map +1 -0
  249. package/dist/utility/types.d.ts +213 -1
  250. package/dist/utility/types.d.ts.map +1 -1
  251. package/dist/utility/unit.d.ts.map +1 -1
  252. package/dist/utility/unit.js +51 -0
  253. package/dist/utility/unit.js.map +1 -1
  254. package/dist/utility/weightedScore.d.ts +3 -0
  255. package/dist/utility/weightedScore.d.ts.map +1 -0
  256. package/dist/utility/weightedScore.js +35 -0
  257. package/dist/utility/weightedScore.js.map +1 -0
  258. package/package.json +3 -2
package/CHANGELOG.md CHANGED
@@ -5,6 +5,90 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [0.9.0] - 2026-02-09
9
+
10
+ ### Added
11
+
12
+ - **Type Guards** — 8 runtime type guard functions for discriminated union inputs ([#2](https://github.com/iyulab/formulab/issues/2)):
13
+ - `isCRateInput()` — battery domain (mode: currentToRate | rateToCurrent)
14
+ - `isDilutionInput()` — chemical domain (solveFor: c1 | v1 | c2 | v2)
15
+ - `isReactorInput()` — chemical domain (shape: cylindrical | spherical)
16
+ - `isHeatTransferInput()` — chemical domain (mode: conduction | convection | radiation)
17
+ - `isMomentOfInertiaInput()` — construction domain (shape: 7 variants)
18
+ - `isOhmsLawInput()` — electronics domain (solveFor: voltage | current | resistance | power)
19
+ - `isMetalWeightInput()` — metal domain (shape: plate | round | pipe | angle)
20
+ - `isBoltInput()` — metal domain (mode: torqueToPreload | preloadToTorque)
21
+
22
+ - **Error Behavior Specification** — `ERRORS.md` documenting error policy and per-function error behavior ([#1](https://github.com/iyulab/formulab/issues/1)):
23
+ - Defined error policy: validation failures → throw RangeError
24
+ - Documented all 174 functions' error behavior (throw / NaN / Infinity / null / safe)
25
+ - Identified 6 legacy NaN/Infinity patterns with migration roadmap to v0.10.0
26
+
27
+ ### Changed
28
+
29
+ - Total function count: 174 → 182 (+8 type guards)
30
+
31
+ ## [0.7.0] - 2026-02-07
32
+
33
+ ### Added
34
+
35
+ - **Quality** (+4 functions, 14 → 18):
36
+ - `gageRR()` — Gage R&R repeatability/reproducibility analysis (AIAG MSA 4th Edition)
37
+ - `cmk()` — Machine capability index Cm/Cmk (threshold ≥ 1.67)
38
+ - `weibull()` — Weibull reliability analysis with median rank regression
39
+ - `paretoAnalysis()` — Pareto 80/20 ABC classification
40
+
41
+ - **Safety** (+5 functions, 9 → 14):
42
+ - `thermalComfort()` — PMV/PPD thermal comfort (ISO 7730 Fanger model)
43
+ - `ergonomicRisk()` — REBA ergonomic risk assessment scoring
44
+ - `arcFlash()` — Arc flash incident energy & PPE category (IEEE 1584/NFPA 70E)
45
+ - `confinedSpace()` — Confined space atmospheric assessment (OSHA 29 CFR 1910.146)
46
+ - `lel()` — Lower explosive limit for mixed gases (Le Chatelier's rule)
47
+
48
+ - **Energy** (+4 functions, 11 → 15):
49
+ - `heatPump()` — Heat pump COP & Carnot efficiency with annual savings
50
+ - `degreeDay()` — Heating/Cooling degree day calculation (HDD/CDD)
51
+ - `windOutput()` — Wind turbine output with Rayleigh capacity factor
52
+ - `cusum()` — CUSUM energy anomaly detection (Page's algorithm)
53
+
54
+ - **Chemical** (+3 functions, 9 → 12):
55
+ - `flowControl()` — Control valve Cv/Kv sizing (ISA/IEC 60534)
56
+ - `reliefValve()` — Safety relief valve sizing (API 520/526)
57
+ - `pid()` — PID controller tuning (Ziegler-Nichols / Cohen-Coon)
58
+
59
+ - **Logistics** (+1 function, 16 → 17):
60
+ - `abcAnalysis()` — ABC inventory classification by annual value
61
+
62
+ - **Food** (+2 functions, 4 → 6):
63
+ - `waterActivity()` — Water activity microbial growth risk (HACCP)
64
+ - `stabilityStudy()` — Accelerated stability study with Arrhenius regression (ICH Q1A)
65
+
66
+ - **Automotive** (+1 function, 8 → 9):
67
+ - `chargingLoss()` — EV charging loss/efficiency with temperature derating
68
+
69
+ ### Changed
70
+
71
+ - Total function count: 154 → 174 (+20)
72
+ - Total domains: 14 (unchanged)
73
+
74
+ ## [0.6.0] - 2026-02-07
75
+
76
+ ### Added
77
+
78
+ - **Energy** (+4 functions, 7 → 11):
79
+ - `boilerEfficiency()` — Boiler thermal efficiency (direct input-output method)
80
+ - `transformerLoss()` — Transformer loss calculation with optimal load point
81
+ - `insulationRoi()` — Insulation ROI with payback period
82
+ - `ledRoi()` — LED lighting retrofit ROI with CO2 savings
83
+
84
+ - **Safety** (+2 functions, 7 → 9):
85
+ - `ladderAngle()` — Ladder safety angle calculation (OSHA 4:1 rule, 70°–80° compliance)
86
+ - `illuminance()` — Workplace illuminance calculation (Lumen Method with CU lookup)
87
+
88
+ - **Logistics** (+2 functions, 14 → 16):
89
+ - `inventoryTurnover()` — Inventory turnover ratio, days/weeks of supply, GMROII
90
+ - `loadCapacity()` — Forklift load capacity derating with attachment loss
91
+
8
92
  ## [0.5.0] - 2026-02-07
9
93
 
10
94
  ### Added
package/README.md CHANGED
@@ -11,7 +11,7 @@ A comprehensive collection of engineering formulas and calculations for manufact
11
11
 
12
12
  ## Features
13
13
 
14
- - **146 industrial calculations** — OEE, Cpk, SPC control charts, metal weight, CNC machining, GD&T, pipe flow, CBM, NIOSH lifting, battery SOH, GHG emissions, and more
14
+ - **174 industrial calculations** — OEE, Cpk, SPC control charts, Gage R&R, Weibull, metal weight, CNC machining, GD&T, pipe flow, CBM, NIOSH lifting, PMV/PPD, arc flash, battery SOH, GHG emissions, PID tuning, and more
15
15
  - **14 specialized domains** — Quality, Metal, Chemical, Electronics, Construction, Automotive, Logistics, Energy, Safety, Food, Utility, Battery, Environmental, Machining
16
16
  - **Zero dependencies** — Lightweight and fast
17
17
  - **TypeScript first** — Full type definitions included
@@ -23,16 +23,16 @@ A comprehensive collection of engineering formulas and calculations for manufact
23
23
 
24
24
  | Domain | Functions | Golden Tests | Key References |
25
25
  |--------|-----------|-------------|----------------|
26
- | Quality | 14 | oee, cpk, controlChart | ISO 22400-2, AIAG/ASTM E2587, JIPM |
26
+ | Quality | 18 | oee, cpk, controlChart, gageRR | ISO 22400-2, AIAG/ASTM E2587, JIPM, AIAG MSA |
27
27
  | Metal | 25 | metalWeight | Machinery's Handbook, ASME B36.10/B16.5 |
28
- | Logistics | 14 | cbm | Physical formula |
29
- | Safety | 7 | nioshLifting | NIOSH 94-110 |
30
- | Chemical | 9 | — | Darcy-Weisbach, Fourier |
28
+ | Logistics | 17 | cbm | Physical formula |
29
+ | Safety | 14 | nioshLifting | NIOSH 94-110, ISO 7730, IEEE 1584, OSHA |
30
+ | Chemical | 12 | — | Darcy-Weisbach, Fourier, API 520, ISA |
31
31
  | Electronics | 11 | — | IPC-2221 |
32
32
  | Construction | 12 | — | AISC, Timoshenko |
33
- | Automotive | 8 | — | AASHTO |
34
- | Energy | 7 | — | NREL PVWatts |
35
- | Food | 4 | — | HACCP |
33
+ | Automotive | 9 | — | AASHTO, SAE J1772 |
34
+ | Energy | 15 | — | NREL PVWatts, ISO 50001 |
35
+ | Food | 6 | — | HACCP, ICH Q1A |
36
36
  | Utility | 3 | — | — |
37
37
  | Battery | 10 | — | IEEE 1188, IEC 62620, Battery University |
38
38
  | Environmental | 10 | — | GHG Protocol, IPCC AR6, IEA 2023 |
@@ -157,10 +157,10 @@ console.log(volume.totalCbm); // 0.96 m³
157
157
 
158
158
  ## Domains
159
159
 
160
- ### Quality & Production (14 functions)
160
+ ### Quality & Production (18 functions)
161
161
 
162
162
  ```typescript
163
- import { oee, cpk, taktTime, dpmo, controlChart } from 'formulab/quality';
163
+ import { oee, cpk, taktTime, dpmo, controlChart, gageRR, weibull } from 'formulab/quality';
164
164
  ```
165
165
 
166
166
  | Function | Description |
@@ -179,6 +179,10 @@ import { oee, cpk, taktTime, dpmo, controlChart } from 'formulab/quality';
179
179
  | `ppm()` | Parts Per Million conversion |
180
180
  | `rpn()` | Risk Priority Number (FMEA) |
181
181
  | `yieldCalc()` | First Pass Yield / RTY |
182
+ | `gageRR()` | Gage R&R (AIAG MSA Average & Range) |
183
+ | `cmk()` | Machine capability index Cm/Cmk |
184
+ | `weibull()` | Weibull reliability analysis |
185
+ | `paretoAnalysis()` | Pareto 80/20 ABC classification |
182
186
 
183
187
  ### Metal & Machining (25 functions)
184
188
 
@@ -214,10 +218,10 @@ import { metalWeight, bendAllowance, cutting, bearing } from 'formulab/metal';
214
218
  | `pipeSpec()` | ANSI/ASME pipe dimensions lookup |
215
219
  | `flangeSpec()` | ASME B16.5 flange dimensions lookup |
216
220
 
217
- ### Chemical & Process (9 functions)
221
+ ### Chemical & Process (12 functions)
218
222
 
219
223
  ```typescript
220
- import { dilution, concentration, ph, reactor, pipeFlow, heatTransfer } from 'formulab/chemical';
224
+ import { dilution, concentration, ph, reactor, pipeFlow, heatTransfer, flowControl, pid } from 'formulab/chemical';
221
225
  ```
222
226
 
223
227
  | Function | Description |
@@ -231,6 +235,9 @@ import { dilution, concentration, ph, reactor, pipeFlow, heatTransfer } from 'fo
231
235
  | `reactor()` | Reactor sizing |
232
236
  | `shelfLife()` | Shelf life prediction (Arrhenius) |
233
237
  | `injectionCycle()` | Injection molding cycle time |
238
+ | `flowControl()` | Control valve Cv/Kv sizing (ISA/IEC 60534) |
239
+ | `reliefValve()` | Safety relief valve sizing (API 520/526) |
240
+ | `pid()` | PID controller tuning (Z-N / Cohen-Coon) |
234
241
 
235
242
  ### Electronics & SMT (11 functions)
236
243
 
@@ -273,10 +280,10 @@ import { concreteMix, rebarWeight, slope, stair, momentOfInertia } from 'formula
273
280
  | `roof()` | Roof calculation |
274
281
  | `stair()` | Stair dimension calculation |
275
282
 
276
- ### Automotive (8 functions)
283
+ ### Automotive (9 functions)
277
284
 
278
285
  ```typescript
279
- import { batteryRuntime, evCharging, torque, brakingDistance } from 'formulab/automotive';
286
+ import { batteryRuntime, evCharging, torque, brakingDistance, chargingLoss } from 'formulab/automotive';
280
287
  ```
281
288
 
282
289
  | Function | Description |
@@ -289,22 +296,26 @@ import { batteryRuntime, evCharging, torque, brakingDistance } from 'formulab/au
289
296
  | `tireCompare()` | Tire size comparison |
290
297
  | `torque()` | Torque conversion |
291
298
  | `power()` | Power conversion (HP, kW) |
299
+ | `chargingLoss()` | EV charging loss/efficiency |
292
300
 
293
- ### Logistics & Inventory (14 functions)
301
+ ### Logistics & Inventory (17 functions)
294
302
 
295
303
  ```typescript
296
- import { cbm, eoq, safetyStock, kanban } from 'formulab/logistics';
304
+ import { cbm, eoq, safetyStock, kanban, inventoryTurnover, abcAnalysis } from 'formulab/logistics';
297
305
  ```
298
306
 
299
307
  | Function | Description |
300
308
  |----------|-------------|
309
+ | `abcAnalysis()` | ABC inventory classification by annual value |
301
310
  | `cbm()` | Cubic meter calculation |
302
311
  | `containerFit()` | Container capacity estimation |
303
312
  | `dimWeight()` | Dimensional weight |
304
313
  | `eoq()` | Economic Order Quantity |
305
314
  | `fillRate()` | Fill rate calculation |
306
315
  | `freightClass()` | NMFC freight class |
316
+ | `inventoryTurnover()` | Inventory turnover ratio & days of supply |
307
317
  | `kanban()` | Kanban quantity |
318
+ | `loadCapacity()` | Forklift load capacity derating |
308
319
  | `pallet3d()` | 3D pallet loading heuristic (BLF + FFD) |
309
320
  | `palletStack()` | Pallet stacking calculation |
310
321
  | `pickTime()` | Picking time estimation |
@@ -313,42 +324,57 @@ import { cbm, eoq, safetyStock, kanban } from 'formulab/logistics';
313
324
  | `shipping()` | Shipping cost estimation |
314
325
  | `tsp()` | TSP heuristic (NN + 2-Opt; exact for n ≤ 10) |
315
326
 
316
- ### Energy & Utilities (7 functions)
327
+ ### Energy & Utilities (15 functions)
317
328
 
318
329
  ```typescript
319
- import { powerCost, motorEfficiency, carbonFootprint, solarOutput } from 'formulab/energy';
330
+ import { powerCost, motorEfficiency, carbonFootprint, solarOutput, boilerEfficiency, heatPump, cusum } from 'formulab/energy';
320
331
  ```
321
332
 
322
333
  | Function | Description |
323
334
  |----------|-------------|
324
- | `solarOutput()` | Solar panel output estimation (PVWatts-based) |
335
+ | `boilerEfficiency()` | Boiler thermal efficiency (direct method) |
325
336
  | `carbonFootprint()` | Scope 2 emissions |
326
337
  | `compressedAirCost()` | Compressed air cost |
338
+ | `cusum()` | CUSUM energy anomaly detection |
339
+ | `degreeDay()` | Heating/Cooling degree days (HDD/CDD) |
340
+ | `heatPump()` | Heat pump COP & Carnot efficiency |
341
+ | `insulationRoi()` | Insulation ROI & payback |
342
+ | `ledRoi()` | LED lighting retrofit ROI |
327
343
  | `motorEfficiency()` | Motor upgrade ROI |
328
344
  | `pfCorrection()` | Power factor correction |
329
345
  | `powerCost()` | Electricity cost with demand |
346
+ | `solarOutput()` | Solar panel output estimation (PVWatts-based) |
347
+ | `transformerLoss()` | Transformer loss & efficiency |
330
348
  | `vfdSavings()` | VFD energy savings |
349
+ | `windOutput()` | Wind turbine output with Rayleigh CF |
331
350
 
332
- ### Safety & Ergonomics (7 functions)
351
+ ### Safety & Ergonomics (14 functions)
333
352
 
334
353
  ```typescript
335
- import { nioshLifting, noiseExposure, wbgtCalculate, ventilationRate } from 'formulab/safety';
354
+ import { nioshLifting, noiseExposure, wbgtCalculate, ventilationRate, thermalComfort, arcFlash, lel } from 'formulab/safety';
336
355
  ```
337
356
 
338
357
  | Function | Description |
339
358
  |----------|-------------|
340
- | `ventilationRate()` | Required ventilation ACH/CFM (ASHRAE/OSHA) |
359
+ | `arcFlash()` | Arc flash incident energy & PPE (IEEE 1584) |
360
+ | `confinedSpace()` | Confined space atmospheric assessment (OSHA) |
361
+ | `ergonomicRisk()` | REBA ergonomic risk scoring |
341
362
  | `fallClearance()` | Fall protection clearance |
363
+ | `havsCalculate()` | Hand-arm vibration exposure |
364
+ | `illuminance()` | Workplace illuminance (Lumen Method) |
365
+ | `ladderAngle()` | Ladder safety angle (OSHA 4:1) |
366
+ | `lel()` | Mixed gas LEL (Le Chatelier's rule) |
342
367
  | `nioshLifting()` | NIOSH lifting equation |
343
368
  | `noiseExposure()` | TWA/Dose calculation |
344
- | `wbgtCalculate()` | WBGT heat stress index |
345
- | `havsCalculate()` | Hand-arm vibration exposure |
346
369
  | `respiratorCalculate()` | Respirator MUC calculation |
370
+ | `thermalComfort()` | PMV/PPD thermal comfort (ISO 7730) |
371
+ | `ventilationRate()` | Required ventilation ACH/CFM (ASHRAE/OSHA) |
372
+ | `wbgtCalculate()` | WBGT heat stress index |
347
373
 
348
- ### Food & HACCP (4 functions)
374
+ ### Food & HACCP (6 functions)
349
375
 
350
376
  ```typescript
351
- import { calorie, nutrition, haccp } from 'formulab/food';
377
+ import { calorie, nutrition, haccp, waterActivity, stabilityStudy } from 'formulab/food';
352
378
  ```
353
379
 
354
380
  | Function | Description |
@@ -357,6 +383,8 @@ import { calorie, nutrition, haccp } from 'formulab/food';
357
383
  | `expiry()` | Expiry date calculation |
358
384
  | `nutrition()` | Nutrition facts calculation |
359
385
  | `haccp()` | HACCP checklist generation |
386
+ | `waterActivity()` | Water activity microbial risk (HACCP) |
387
+ | `stabilityStudy()` | Accelerated stability (Arrhenius, ICH Q1A) |
360
388
 
361
389
  ### Utility (3 functions)
362
390
 
@@ -499,6 +527,42 @@ console.log(result);
499
527
  // }
500
528
  ```
501
529
 
530
+ ## Type Guards for Discriminated Unions
531
+
532
+ formulab provides runtime type guard functions for all [discriminated union](https://www.typescriptlang.org/docs/handbook/2/narrowing.html#discriminated-unions) input types. These enable type-safe integration when working with dynamic data (e.g., form inputs, API responses):
533
+
534
+ ```typescript
535
+ import { isCRateInput, cRate } from 'formulab/battery';
536
+
537
+ // Form data from user input (Record<string, unknown>)
538
+ const formData: unknown = { mode: 'currentToRate', capacityAh: 100, currentA: 50 };
539
+
540
+ if (isCRateInput(formData)) {
541
+ const result = cRate(formData); // Type-safe, no 'as any' needed
542
+ }
543
+ ```
544
+
545
+ ### Available Type Guards
546
+
547
+ | Guard | Domain | Discriminant | Variants |
548
+ |-------|--------|-------------|----------|
549
+ | `isCRateInput()` | battery | `mode` | currentToRate, rateToCurrent |
550
+ | `isDilutionInput()` | chemical | `solveFor` | c1, v1, c2, v2 |
551
+ | `isReactorInput()` | chemical | `shape` | cylindrical, spherical |
552
+ | `isHeatTransferInput()` | chemical | `mode` | conduction, convection, radiation |
553
+ | `isMomentOfInertiaInput()` | construction | `shape` | rectangle, circle, hollowRectangle, hollowCircle, iBeam, tSection, cChannel |
554
+ | `isOhmsLawInput()` | electronics | `solveFor` | voltage, current, resistance, power |
555
+ | `isMetalWeightInput()` | metal | `shape` | plate, round, pipe, angle |
556
+ | `isBoltInput()` | metal | `mode` | torqueToPreload, preloadToTorque |
557
+
558
+ ## Error Handling
559
+
560
+ See [ERRORS.md](./ERRORS.md) for the complete error behavior specification. Key points:
561
+
562
+ - **Validation failures** throw `RangeError` with descriptive messages
563
+ - **Legacy NaN/Infinity patterns** are documented and scheduled for migration
564
+ - Each function's error behavior is documented in the specification
565
+
502
566
  ## Tree Shaking
503
567
 
504
568
  Import only what you need to minimize bundle size:
@@ -0,0 +1,15 @@
1
+ import type { ChargingLossInput, ChargingLossResult } from './types.js';
2
+ /**
3
+ * EV Charging Loss Calculator
4
+ *
5
+ * @formula
6
+ * - energyDelivered = batteryCapacity × (targetSoc − soc) / 100
7
+ * - energyConsumed = energyDelivered / (chargerEff × batteryEff)
8
+ * - totalLoss = energyConsumed − energyDelivered
9
+ * - chargingTime = energyConsumed / effectivePower
10
+ *
11
+ * @reference SAE J1772 — Electric Vehicle Charging
12
+ * @reference IEC 61851 — Electric vehicle conductive charging system
13
+ */
14
+ export declare function chargingLoss(input: ChargingLossInput): ChargingLossResult;
15
+ //# sourceMappingURL=chargingLoss.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chargingLoss.d.ts","sourceRoot":"","sources":["../../src/automotive/chargingLoss.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AASxE;;;;;;;;;;;GAWG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,iBAAiB,GAAG,kBAAkB,CAiDzE"}
@@ -0,0 +1,62 @@
1
+ import { roundTo } from '../utils.js';
2
+ // Default charger efficiencies by type
3
+ const DEFAULT_CHARGER_EFFICIENCY = {
4
+ ac_l1: 0.85,
5
+ ac_l2: 0.90,
6
+ dc_fast: 0.93,
7
+ };
8
+ /**
9
+ * EV Charging Loss Calculator
10
+ *
11
+ * @formula
12
+ * - energyDelivered = batteryCapacity × (targetSoc − soc) / 100
13
+ * - energyConsumed = energyDelivered / (chargerEff × batteryEff)
14
+ * - totalLoss = energyConsumed − energyDelivered
15
+ * - chargingTime = energyConsumed / effectivePower
16
+ *
17
+ * @reference SAE J1772 — Electric Vehicle Charging
18
+ * @reference IEC 61851 — Electric vehicle conductive charging system
19
+ */
20
+ export function chargingLoss(input) {
21
+ const { batteryCapacity, chargerPower, chargerType, batteryEfficiency = 0.95, soc, ambientTemp, } = input;
22
+ const chargerEfficiency = input.chargerEfficiency ?? DEFAULT_CHARGER_EFFICIENCY[chargerType] ?? 0.90;
23
+ const targetSoc = input.targetSoc ?? (chargerType === 'dc_fast' ? 80 : 100);
24
+ // Temperature derating
25
+ let derating = 1.0;
26
+ if (ambientTemp != null) {
27
+ if (ambientTemp < 0) {
28
+ derating = 0.70; // Cold weather significant derating
29
+ }
30
+ else if (ambientTemp < 10) {
31
+ derating = 0.85;
32
+ }
33
+ else if (ambientTemp > 40) {
34
+ derating = 0.90;
35
+ }
36
+ else if (ambientTemp > 35) {
37
+ derating = 0.95;
38
+ }
39
+ }
40
+ const effectivePower = chargerPower * derating;
41
+ // Energy calculations
42
+ const energyDelivered = batteryCapacity * (targetSoc - soc) / 100;
43
+ const overallEff = chargerEfficiency * batteryEfficiency;
44
+ const energyConsumed = overallEff > 0 ? energyDelivered / overallEff : 0;
45
+ const totalLoss = energyConsumed - energyDelivered;
46
+ // Loss breakdown
47
+ const chargerLoss = energyConsumed * (1 - chargerEfficiency);
48
+ const batteryLoss = (energyConsumed - chargerLoss) * (1 - batteryEfficiency);
49
+ // Charging time
50
+ const chargingTime = effectivePower > 0 ? energyConsumed / effectivePower : 0;
51
+ return {
52
+ energyDelivered: roundTo(energyDelivered, 2),
53
+ energyConsumed: roundTo(energyConsumed, 2),
54
+ totalLoss: roundTo(totalLoss, 2),
55
+ overallEfficiency: roundTo(overallEff * 100, 2),
56
+ chargerLoss: roundTo(chargerLoss, 2),
57
+ batteryLoss: roundTo(batteryLoss, 2),
58
+ chargingTime: roundTo(chargingTime, 2),
59
+ effectivePower: roundTo(effectivePower, 2),
60
+ };
61
+ }
62
+ //# sourceMappingURL=chargingLoss.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chargingLoss.js","sourceRoot":"","sources":["../../src/automotive/chargingLoss.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAGtC,uCAAuC;AACvC,MAAM,0BAA0B,GAA2B;IACzD,KAAK,EAAE,IAAI;IACX,KAAK,EAAE,IAAI;IACX,OAAO,EAAE,IAAI;CACd,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,YAAY,CAAC,KAAwB;IACnD,MAAM,EACJ,eAAe,EAAE,YAAY,EAAE,WAAW,EAC1C,iBAAiB,GAAG,IAAI,EACxB,GAAG,EAAE,WAAW,GACjB,GAAG,KAAK,CAAC;IAEV,MAAM,iBAAiB,GAAG,KAAK,CAAC,iBAAiB,IAAI,0BAA0B,CAAC,WAAW,CAAC,IAAI,IAAI,CAAC;IACrG,MAAM,SAAS,GAAG,KAAK,CAAC,SAAS,IAAI,CAAC,WAAW,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG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AE,OAAO,CAAC,cAAc,EAAE,CAAC,CAAC;QAC1C,SAAS,EAAE,OAAO,CAAC,SAAS,EAAE,CAAC,CAAC;QAChC,iBAAiB,EAAE,OAAO,CAAC,UAAU,GAAG,GAAG,EAAE,CAAC,CAAC;QAC/C,WAAW,EAAE,OAAO,CAAC,WAAW,EAAE,CAAC,CAAC;QACpC,WAAW,EAAE,OAAO,CAAC,WAAW,EAAE,CAAC,CAAC;QACpC,YAAY,EAAE,OAAO,CAAC,YAAY,EAAE,CAAC,CAAC;QACtC,cAAc,EAAE,OAAO,CAAC,cAAc,EAAE,CAAC,CAAC;KAC3C,CAAC;AACJ,CAAC"}
@@ -6,5 +6,6 @@ export { gearRatio } from './gearRatio.js';
6
6
  export { tireCompare } from './tireCompare.js';
7
7
  export { torque } from './torque.js';
8
8
  export { power } from './power.js';
9
- export type { BrakingDistanceInput, BrakingDistanceResult, BatteryInput, BatteryResult, ChargingInput, ChargingResult, FuelUnit, FuelInput, FuelResult, GearRatioInput, GearRatioResult, TireSpec, TireInput, TireData, TireResult, TorqueUnit, TorqueInput, TorqueResult, PowerUnit, PowerInput, PowerResult, } from './types.js';
9
+ export { chargingLoss } from './chargingLoss.js';
10
+ export type { BrakingDistanceInput, BrakingDistanceResult, BatteryInput, BatteryResult, ChargingInput, ChargingResult, FuelUnit, FuelInput, FuelResult, GearRatioInput, GearRatioResult, TireSpec, TireInput, TireData, TireResult, TorqueUnit, TorqueInput, TorqueResult, PowerUnit, PowerInput, PowerResult, ChargingLossInput, ChargingLossResult, } from './types.js';
10
11
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/automotive/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,O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,QAAQ,EACR,UAAU,EAEV,UAAU,EACV,WAAW,EACX,YAAY,EAEZ,SAAS,EACT,UAAU,EACV,WAAW,EAEX,iBAAiB,EACjB,kBAAkB,GACnB,MAAM,YAAY,CAAC"}
@@ -7,4 +7,5 @@ export { gearRatio } from './gearRatio.js';
7
7
  export { tireCompare } from './tireCompare.js';
8
8
  export { torque } from './torque.js';
9
9
  export { power } from './power.js';
10
+ export { chargingLoss } from './chargingLoss.js';
10
11
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/automotive/index.ts"],"names":[],"mappings":"AAAA,6BAA6B;AAC7B,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/automotive/index.ts"],"names":[],"mappings":"AAAA,6BAA6B;AAC7B,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC"}
@@ -127,4 +127,27 @@ export interface PowerResult {
127
127
  HP: number;
128
128
  PS: number;
129
129
  }
130
+ /**
131
+ * EV Charging Loss Calculator Types
132
+ */
133
+ export interface ChargingLossInput {
134
+ batteryCapacity: number;
135
+ chargerPower: number;
136
+ chargerType: 'ac_l1' | 'ac_l2' | 'dc_fast';
137
+ chargerEfficiency?: number;
138
+ batteryEfficiency?: number;
139
+ soc: number;
140
+ targetSoc?: number;
141
+ ambientTemp?: number;
142
+ }
143
+ export interface ChargingLossResult {
144
+ energyDelivered: number;
145
+ energyConsumed: number;
146
+ totalLoss: number;
147
+ overallEfficiency: number;
148
+ chargerLoss: number;
149
+ batteryLoss: number;
150
+ chargingTime: number;
151
+ effectivePower: number;
152
+ }
130
153
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/automotive/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,aAAa;IAC5B,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,EAAE,MAAM,CAAC;IACrB,cAAc,EAAE,MAAM,CAAC;IACvB,WAAW,EAAE,MAAM,CAAC;CACrB;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,kBAAkB,EAAE,MAAM,CAAC;IAC3B,cAAc,EAAE,MAAM,CAAC;IACvB,eAAe,EAAE,MAAM,CAAC;IACxB,aAAa,EAAE,MAAM,CAAC;IACtB,UAAU,EAAE,MAAM,CAAC;C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AC;IACjB,YAAY,EAAE,MAAM,CAAC;CACtB;AAED;;GAEG;AACH,MAAM,MAAM,SAAS,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC;AAE3C,MAAM,WAAW,UAAU;IACzB,QAAQ,EAAE,SAAS,CAAC;IACpB,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,WAAW;IAC1B,EAAE,EAAE,MAAM,CAAC;IACX,EAAE,EAAE,MAAM,CAAC;IACX,EAAE,EAAE,MAAM,CAAC;CACZ;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,eAAe,EAAE,MAAM,CAAC;IACxB,YAAY,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE,OAAO,GAAG,OAAO,GAAG,SAAS,CAAC;IAC3C,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,GAAG,EAAE,MAAM,CAAC;IACZ,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,kBAAkB;IACjC,eAAe,EAAE,MAAM,CAAC;IACxB,cAAc,EAAE,MAAM,CAAC;IACvB,SAAS,EAAE,MAAM,CAAC;IAClB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB,cAAc,EAAE,MAAM,CAAC;CACxB"}
@@ -0,0 +1,7 @@
1
+ import type { CRateInput } from './types.js';
2
+ /**
3
+ * Runtime type guard for {@link CRateInput} discriminated union.
4
+ * Validates the `mode` discriminant and required fields for each variant.
5
+ */
6
+ export declare function isCRateInput(input: unknown): input is CRateInput;
7
+ //# sourceMappingURL=guards.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"guards.d.ts","sourceRoot":"","sources":["../../src/battery/guards.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE7C;;;GAGG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,UAAU,CAShE"}
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Runtime type guard for {@link CRateInput} discriminated union.
3
+ * Validates the `mode` discriminant and required fields for each variant.
4
+ */
5
+ export function isCRateInput(input) {
6
+ if (typeof input !== 'object' || input === null)
7
+ return false;
8
+ const o = input;
9
+ if (typeof o.capacityAh !== 'number')
10
+ return false;
11
+ switch (o.mode) {
12
+ case 'currentToRate': return typeof o.currentA === 'number';
13
+ case 'rateToCurrent': return typeof o.cRate === 'number';
14
+ default: return false;
15
+ }
16
+ }
17
+ //# sourceMappingURL=guards.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"guards.js","sourceRoot":"","sources":["../../src/battery/guards.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,MAAM,UAAU,YAAY,CAAC,KAAc;IACzC,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,KAAK,CAAC;IAC9D,MAAM,CAAC,GAAG,KAAgC,CAAC;IAC3C,IAAI,OAAO,CAAC,CAAC,UAAU,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC;IACnD,QAAQ,CAAC,CAAC,IAAI,EAAE,CAAC;QACf,KAAK,eAAe,CAAC,CAAC,OAAO,OAAO,CAAC,CAAC,QAAQ,KAAK,QAAQ,CAAC;QAC5D,KAAK,eAAe,CAAC,CAAC,OAAO,OAAO,CAAC,CAAC,KAAK,KAAK,QAAQ,CAAC;QACzD,OAAO,CAAC,CAAC,OAAO,KAAK,CAAC;IACxB,CAAC;AACH,CAAC"}
@@ -1,4 +1,5 @@
1
1
  export type { BatteryChemistry, EnergyDensityInput, EnergyDensityResult, CRateMode, CRateInput, CRateResult, StateOfHealthInput, SohStatus, StateOfHealthResult, BatteryPackConfigInput, BatteryPackConfigResult, CycleLifeInput, CycleLifeResult, InternalResistanceInput, InternalResistanceResult, SelfDischargeInput, SelfDischargeResult, ThermalRunawayInput, ThermalRunawayResult, BmsBalancingInput, BmsBalancingResult, ChargingProfileInput, ChargingProfileResult, } from './types.js';
2
+ export { isCRateInput } from './guards.js';
2
3
  export { energyDensity } from './energyDensity.js';
3
4
  export { cRate } from './cRate.js';
4
5
  export { stateOfHealth } from './stateOfHealth.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/battery/index.ts"],"names":[],"mappings":"AACA,YAAY,EACV,gBAAgB,EAChB,kBAAkB,EAClB,mBAAmB,EACnB,SAAS,EACT,UAAU,EACV,WAAW,EACX,kBAAkB,EAClB,SAAS,EACT,mBAAmB,EACnB,sBAAsB,EACtB,uBAAuB,EACvB,cAAc,EACd,eAAe,EACf,uBAAuB,EACvB,wBAAwB,EACxB,kBAAkB,EAClB,mBAAmB,EACnB,mBAAmB,EACnB,oBAAoB,EACpB,iBAAiB,EACjB,kBAAkB,EAClB,oBAAoB,EACpB,qBAAqB,GACtB,MAAM,YAAY,CAAC;AAGpB,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/battery/index.ts"],"names":[],"mappings":"AACA,YAAY,EACV,gBAAgB,EAChB,kBAAkB,EAClB,mBAAmB,EACnB,SAAS,EACT,UAAU,EACV,WAAW,EACX,kBAAkB,EAClB,SAAS,EACT,mBAAmB,EACnB,sBAAsB,EACtB,uBAAuB,EACvB,cAAc,EACd,eAAe,EACf,uBAAuB,EACvB,wBAAwB,EACxB,kBAAkB,EAClB,mBAAmB,EACnB,mBAAmB,EACnB,oBAAoB,EACpB,iBAAiB,EACjB,kBAAkB,EAClB,oBAAoB,EACpB,qBAAqB,GACtB,MAAM,YAAY,CAAC;AAGpB,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAG3C,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC"}
@@ -1,3 +1,5 @@
1
+ // Guards
2
+ export { isCRateInput } from './guards.js';
1
3
  // Functions
2
4
  export { energyDensity } from './energyDensity.js';
3
5
  export { cRate } from './cRate.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/battery/index.ts"],"names":[],"mappings":"AA2BA,YAAY;AACZ,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/battery/index.ts"],"names":[],"mappings":"AA2BA,SAAS;AACT,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C,YAAY;AACZ,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC"}
@@ -0,0 +1,14 @@
1
+ import type { FlowControlInput, FlowControlResult } from './types.js';
2
+ /**
3
+ * Control Valve Cv Calculator
4
+ *
5
+ * @formula
6
+ * - Liquid: Cv = Q × √(SG / ΔP) (Q in GPM, ΔP in psi)
7
+ * - Gas: Cv = Q / (N × P1) × √(SG × T / ΔP)
8
+ * - Kv = 0.865 × Cv
9
+ *
10
+ * @reference ISA-75.01.01-2012 — Flow equations for sizing control valves
11
+ * @reference IEC 60534-2-1 — Industrial-process control valves
12
+ */
13
+ export declare function flowControl(input: FlowControlInput): FlowControlResult;
14
+ //# sourceMappingURL=flowControl.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"flowControl.d.ts","sourceRoot":"","sources":["../../src/chemical/flowControl.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAEtE;;;;;;;;;;GAUG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,gBAAgB,GAAG,iBAAiB,CAkEtE"}
@@ -0,0 +1,69 @@
1
+ import { roundTo } from '../utils.js';
2
+ /**
3
+ * Control Valve Cv Calculator
4
+ *
5
+ * @formula
6
+ * - Liquid: Cv = Q × √(SG / ΔP) (Q in GPM, ΔP in psi)
7
+ * - Gas: Cv = Q / (N × P1) × √(SG × T / ΔP)
8
+ * - Kv = 0.865 × Cv
9
+ *
10
+ * @reference ISA-75.01.01-2012 — Flow equations for sizing control valves
11
+ * @reference IEC 60534-2-1 — Industrial-process control valves
12
+ */
13
+ export function flowControl(input) {
14
+ const { flowRate, inletPressure, outletPressure, fluidDensity, fluidType, temperature = 20, molecularWeight, specificHeatRatio = 1.4, } = input;
15
+ const pressureDrop = inletPressure - outletPressure; // kPa
16
+ // Reference density: water = 999 kg/m³
17
+ const sg = fluidDensity / 999;
18
+ const pressureRatio = pressureDrop / inletPressure;
19
+ let cv;
20
+ let isChoked = false;
21
+ if (fluidType === 'liquid') {
22
+ // ISA liquid sizing: Cv = Q(m³/h) × √(SG / ΔP(bar))
23
+ // Convert kPa to bar: 1 bar = 100 kPa
24
+ const dpBar = pressureDrop / 100;
25
+ if (dpBar <= 0) {
26
+ cv = 0;
27
+ }
28
+ else {
29
+ cv = flowRate * Math.sqrt(sg / dpBar);
30
+ }
31
+ }
32
+ else {
33
+ // Gas/Steam sizing
34
+ // Critical pressure ratio for choked flow
35
+ const xT = 0.7; // typical for globe valve
36
+ const Fk = specificHeatRatio / 1.4;
37
+ const xCritical = Fk * xT;
38
+ const x = pressureDrop / inletPressure;
39
+ if (x >= xCritical) {
40
+ isChoked = true;
41
+ }
42
+ const xEffective = Math.min(x, xCritical);
43
+ const p1Bar = inletPressure / 100;
44
+ const T = temperature + 273.15;
45
+ const MW = molecularWeight ?? 29; // default air
46
+ // N8 = 94.8 for metric (m³/h, bar, K)
47
+ const N8 = 94.8;
48
+ const Y = 1 - xEffective / (3 * xCritical); // Expansion factor
49
+ if (p1Bar <= 0 || xEffective <= 0) {
50
+ cv = 0;
51
+ }
52
+ else {
53
+ cv = flowRate / (N8 * p1Bar * Y) * Math.sqrt(MW * T / xEffective);
54
+ }
55
+ }
56
+ const kv = cv * 0.865;
57
+ // Estimate pipe velocity (assuming DN50 pipe)
58
+ const pipeArea = Math.PI * (0.05 / 2) ** 2; // m²
59
+ const velocity = (flowRate / 3600) / pipeArea; // m/s
60
+ return {
61
+ cv: roundTo(cv, 2),
62
+ kv: roundTo(kv, 2),
63
+ pressureDrop: roundTo(pressureDrop, 2),
64
+ pressureRatio: roundTo(pressureRatio, 4),
65
+ isChoked,
66
+ velocity: roundTo(velocity, 2),
67
+ };
68
+ }
69
+ //# sourceMappingURL=flowControl.js.map