siderust-js 0.1.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 (272) hide show
  1. package/.github/workflows/ci.yml +166 -0
  2. package/.gitmodules +9 -0
  3. package/CHANGELOG.md +26 -0
  4. package/LICENSE +661 -0
  5. package/README.md +138 -0
  6. package/package.json +12 -0
  7. package/qtty-js/.github/workflows/ci.yml +151 -0
  8. package/qtty-js/.gitmodules +3 -0
  9. package/qtty-js/CHANGELOG.md +31 -0
  10. package/qtty-js/LICENSE +661 -0
  11. package/qtty-js/README.md +132 -0
  12. package/qtty-js/package.json +20 -0
  13. package/qtty-js/qtty/.github/workflows/ci.yml +155 -0
  14. package/qtty-js/qtty/CHANGELOG.md +120 -0
  15. package/qtty-js/qtty/Cargo.lock +1462 -0
  16. package/qtty-js/qtty/Cargo.toml +12 -0
  17. package/qtty-js/qtty/LICENSE +661 -0
  18. package/qtty-js/qtty/README.md +9 -0
  19. package/qtty-js/qtty/qtty/Cargo.toml +41 -0
  20. package/qtty-js/qtty/qtty/README.md +8 -0
  21. package/qtty-js/qtty/qtty/examples/angles.rs +14 -0
  22. package/qtty-js/qtty/qtty/examples/astronomy.rs +17 -0
  23. package/qtty-js/qtty/qtty/examples/dimensional_arithmetic.rs +83 -0
  24. package/qtty-js/qtty/qtty/examples/python_integration.rs +61 -0
  25. package/qtty-js/qtty/qtty/examples/quickstart.rs +15 -0
  26. package/qtty-js/qtty/qtty/examples/ratios.rs +12 -0
  27. package/qtty-js/qtty/qtty/examples/serde_with_unit.rs +234 -0
  28. package/qtty-js/qtty/qtty/examples/serialization.rs +141 -0
  29. package/qtty-js/qtty/qtty/examples/serialization_advanced.rs +155 -0
  30. package/qtty-js/qtty/qtty/src/f32.rs +108 -0
  31. package/qtty-js/qtty/qtty/src/f64.rs +30 -0
  32. package/qtty-js/qtty/qtty/src/i128.rs +111 -0
  33. package/qtty-js/qtty/qtty/src/i16.rs +111 -0
  34. package/qtty-js/qtty/qtty/src/i32.rs +111 -0
  35. package/qtty-js/qtty/qtty/src/i64.rs +111 -0
  36. package/qtty-js/qtty/qtty/src/i8.rs +111 -0
  37. package/qtty-js/qtty/qtty/src/lib.rs +238 -0
  38. package/qtty-js/qtty/qtty/tests/fixtures/qtty-vec-no-std/Cargo.lock +83 -0
  39. package/qtty-js/qtty/qtty/tests/fixtures/qtty-vec-no-std/Cargo.toml +10 -0
  40. package/qtty-js/qtty/qtty/tests/fixtures/qtty-vec-no-std/src/lib.rs +7 -0
  41. package/qtty-js/qtty/qtty/tests/fixtures/qtty-vec-no-std-alloc/Cargo.lock +83 -0
  42. package/qtty-js/qtty/qtty/tests/fixtures/qtty-vec-no-std-alloc/Cargo.toml +10 -0
  43. package/qtty-js/qtty/qtty/tests/fixtures/qtty-vec-no-std-alloc/src/lib.rs +7 -0
  44. package/qtty-js/qtty/qtty/tests/fixtures/qtty-vec-std/Cargo.lock +83 -0
  45. package/qtty-js/qtty/qtty/tests/fixtures/qtty-vec-std/Cargo.toml +10 -0
  46. package/qtty-js/qtty/qtty/tests/fixtures/qtty-vec-std/src/lib.rs +5 -0
  47. package/qtty-js/qtty/qtty/tests/integration_tests.rs +529 -0
  48. package/qtty-js/qtty/qtty/tests/qtty_vec_feature_matrix.rs +58 -0
  49. package/qtty-js/qtty/qtty-core/Cargo.toml +41 -0
  50. package/qtty-js/qtty/qtty-core/README.md +8 -0
  51. package/qtty-js/qtty/qtty-core/examples/diesel_integration.rs +145 -0
  52. package/qtty-js/qtty/qtty-core/examples/quantity_db_serde.rs +215 -0
  53. package/qtty-js/qtty/qtty-core/src/dimension.rs +249 -0
  54. package/qtty-js/qtty/qtty-core/src/feature_diesel.rs +318 -0
  55. package/qtty-js/qtty/qtty-core/src/feature_pyo3.rs +27 -0
  56. package/qtty-js/qtty/qtty-core/src/feature_serde.rs +203 -0
  57. package/qtty-js/qtty/qtty-core/src/feature_tiberius.rs +28 -0
  58. package/qtty-js/qtty/qtty-core/src/lib.rs +744 -0
  59. package/qtty-js/qtty/qtty-core/src/macros.rs +93 -0
  60. package/qtty-js/qtty/qtty-core/src/quantity.rs +810 -0
  61. package/qtty-js/qtty/qtty-core/src/scalar.rs +1742 -0
  62. package/qtty-js/qtty/qtty-core/src/unit.rs +332 -0
  63. package/qtty-js/qtty/qtty-core/src/units/angular.rs +1228 -0
  64. package/qtty-js/qtty/qtty-core/src/units/area.rs +243 -0
  65. package/qtty-js/qtty/qtty-core/src/units/frequency.rs +179 -0
  66. package/qtty-js/qtty/qtty-core/src/units/length.rs +1270 -0
  67. package/qtty-js/qtty/qtty-core/src/units/mass.rs +488 -0
  68. package/qtty-js/qtty/qtty-core/src/units/mod.rs +26 -0
  69. package/qtty-js/qtty/qtty-core/src/units/power.rs +324 -0
  70. package/qtty-js/qtty/qtty-core/src/units/time.rs +667 -0
  71. package/qtty-js/qtty/qtty-core/src/units/unitless.rs +212 -0
  72. package/qtty-js/qtty/qtty-core/src/units/velocity.rs +210 -0
  73. package/qtty-js/qtty/qtty-core/src/units/volume.rs +269 -0
  74. package/qtty-js/qtty/qtty-core/tests/core.rs +628 -0
  75. package/qtty-js/qtty/qtty-core/tests/diesel.rs +461 -0
  76. package/qtty-js/qtty/qtty-core/tests/integers.rs +632 -0
  77. package/qtty-js/qtty/qtty-core/tests/no_cross_unit_ops.rs +35 -0
  78. package/qtty-js/qtty/qtty-core/tests/pyo3.rs +334 -0
  79. package/qtty-js/qtty/qtty-core/tests/quantity_f32.rs +276 -0
  80. package/qtty-js/qtty/qtty-core/tests/scalar_decimal.rs +258 -0
  81. package/qtty-js/qtty/qtty-core/tests/scalar_f32.rs +286 -0
  82. package/qtty-js/qtty/qtty-core/tests/scalar_f64_real.rs +287 -0
  83. package/qtty-js/qtty/qtty-core/tests/scalar_rational.rs +260 -0
  84. package/qtty-js/qtty/qtty-core/tests/serde.rs +256 -0
  85. package/qtty-js/qtty/qtty-core/tests/tiberius.rs +208 -0
  86. package/qtty-js/qtty/qtty-derive/Cargo.toml +23 -0
  87. package/qtty-js/qtty/qtty-derive/README.md +8 -0
  88. package/qtty-js/qtty/qtty-derive/src/lib.rs +340 -0
  89. package/qtty-js/qtty/qtty-ffi/ARCHITECTURE.md +3 -0
  90. package/qtty-js/qtty/qtty-ffi/Cargo.toml +31 -0
  91. package/qtty-js/qtty/qtty-ffi/README.md +9 -0
  92. package/qtty-js/qtty/qtty-ffi/build.rs +326 -0
  93. package/qtty-js/qtty/qtty-ffi/cbindgen.toml +105 -0
  94. package/qtty-js/qtty/qtty-ffi/include/qtty_ffi.h +1126 -0
  95. package/qtty-js/qtty/qtty-ffi/src/ffi.rs +1251 -0
  96. package/qtty-js/qtty/qtty-ffi/src/ffi_serde.rs +294 -0
  97. package/qtty-js/qtty/qtty-ffi/src/helpers.rs +310 -0
  98. package/qtty-js/qtty/qtty-ffi/src/lib.rs +229 -0
  99. package/qtty-js/qtty/qtty-ffi/src/macros.rs +121 -0
  100. package/qtty-js/qtty/qtty-ffi/src/registry.rs +274 -0
  101. package/qtty-js/qtty/qtty-ffi/src/types.rs +620 -0
  102. package/qtty-js/qtty/qtty-ffi/tests/integration_tests.rs +842 -0
  103. package/qtty-js/qtty/qtty-ffi/units.csv +156 -0
  104. package/qtty-js/qtty/qtty-ffi/units.csv.md +3 -0
  105. package/qtty-js/qtty-node/.prettierignore +6 -0
  106. package/qtty-js/qtty-node/.prettierrc.json +6 -0
  107. package/qtty-js/qtty-node/README.md +250 -0
  108. package/qtty-js/qtty-node/c8.config.json +11 -0
  109. package/qtty-js/qtty-node/eslint.config.js +31 -0
  110. package/qtty-js/qtty-node/examples/arithmetic.mjs +64 -0
  111. package/qtty-js/qtty-node/examples/astronomy.mjs +90 -0
  112. package/qtty-js/qtty-node/examples/quickstart.mjs +36 -0
  113. package/qtty-js/qtty-node/examples/serialization.mjs +125 -0
  114. package/qtty-js/qtty-node/examples/unit_factories.mjs +74 -0
  115. package/qtty-js/qtty-node/index.d.ts +219 -0
  116. package/qtty-js/qtty-node/index.js +323 -0
  117. package/qtty-js/qtty-node/lib/DerivedQuantity.js +122 -0
  118. package/qtty-js/qtty-node/lib/Quantity.js +151 -0
  119. package/qtty-js/qtty-node/lib/backend.js +25 -0
  120. package/qtty-js/qtty-node/native.cjs +306 -0
  121. package/qtty-js/qtty-node/package-lock.json +3223 -0
  122. package/qtty-js/qtty-node/package.json +70 -0
  123. package/qtty-js/qtty-node/units.d.ts +299 -0
  124. package/qtty-js/qtty-node/units.js +210 -0
  125. package/qtty-js/qtty-web/Cargo.lock +767 -0
  126. package/qtty-js/qtty-web/Cargo.toml +21 -0
  127. package/qtty-js/qtty-web/index.d.ts +140 -0
  128. package/qtty-js/qtty-web/index.js +20 -0
  129. package/qtty-js/qtty-web/lib/DerivedQuantity.js +58 -0
  130. package/qtty-js/qtty-web/lib/Quantity.js +75 -0
  131. package/qtty-js/qtty-web/lib/backend.js +80 -0
  132. package/qtty-js/qtty-web/package.json +45 -0
  133. package/qtty-js/qtty-web/src/lib.rs +111 -0
  134. package/qtty-js/scripts/ci.sh +73 -0
  135. package/scripts/ci.sh +123 -0
  136. package/siderust-core/Cargo.lock +787 -0
  137. package/siderust-core/Cargo.toml +18 -0
  138. package/siderust-core/DEDUPLICATION.md +124 -0
  139. package/siderust-core/src/body.rs +120 -0
  140. package/siderust-core/src/events.rs +184 -0
  141. package/siderust-core/src/lib.rs +20 -0
  142. package/siderust-core/src/observer.rs +55 -0
  143. package/siderust-core/src/position.rs +213 -0
  144. package/siderust-node/.prettierignore +7 -0
  145. package/siderust-node/.prettierrc.json +6 -0
  146. package/siderust-node/Cargo.lock +906 -0
  147. package/siderust-node/Cargo.toml +29 -0
  148. package/siderust-node/README.md +109 -0
  149. package/siderust-node/__test__/index.test.mjs +248 -0
  150. package/siderust-node/build.rs +5 -0
  151. package/siderust-node/c8.config.json +3 -0
  152. package/siderust-node/eslint.config.js +31 -0
  153. package/siderust-node/examples/01_basic_coordinates.mjs +24 -0
  154. package/siderust-node/examples/02_coordinate_transformations.mjs +25 -0
  155. package/siderust-node/examples/03_all_frames_conversions.mjs +26 -0
  156. package/siderust-node/examples/04_all_center_conversions.mjs +24 -0
  157. package/siderust-node/examples/05_target_tracking.mjs +22 -0
  158. package/siderust-node/examples/06_night_events.mjs +18 -0
  159. package/siderust-node/examples/07_moon_properties.mjs +21 -0
  160. package/siderust-node/examples/08_solar_system.mjs +19 -0
  161. package/siderust-node/examples/09_star_observability.mjs +22 -0
  162. package/siderust-node/examples/10_time_periods.mjs +9 -0
  163. package/siderust-node/examples/11_serialization.mjs +31 -0
  164. package/siderust-node/examples/12_runtime_ephemeris.mjs +27 -0
  165. package/siderust-node/examples/13_coordinate_operations.mjs +20 -0
  166. package/siderust-node/index.d.ts +623 -0
  167. package/siderust-node/index.js +79 -0
  168. package/siderust-node/lib/Observer.js +112 -0
  169. package/siderust-node/lib/Star.js +118 -0
  170. package/siderust-node/lib/backend.js +63 -0
  171. package/siderust-node/lib/wrappers.js +566 -0
  172. package/siderust-node/main.js +20 -0
  173. package/siderust-node/native.cjs +360 -0
  174. package/siderust-node/package-lock.json +3261 -0
  175. package/siderust-node/package.json +71 -0
  176. package/siderust-node/src/body.rs +74 -0
  177. package/siderust-node/src/coordinates.rs +372 -0
  178. package/siderust-node/src/ephemeris.rs +462 -0
  179. package/siderust-node/src/events.rs +577 -0
  180. package/siderust-node/src/lib.rs +43 -0
  181. package/siderust-node/src/observer.rs +132 -0
  182. package/siderust-node/src/phase.rs +218 -0
  183. package/siderust-node/src/position.rs +292 -0
  184. package/siderust-node/src/star.rs +200 -0
  185. package/siderust-web/Cargo.lock +855 -0
  186. package/siderust-web/Cargo.toml +34 -0
  187. package/siderust-web/README.md +100 -0
  188. package/siderust-web/__test__/index.test.mjs +118 -0
  189. package/siderust-web/examples/github-pages/README.md +31 -0
  190. package/siderust-web/examples/github-pages/index.html +135 -0
  191. package/siderust-web/index.d.ts +311 -0
  192. package/siderust-web/index.js +66 -0
  193. package/siderust-web/lib/Observer.js +103 -0
  194. package/siderust-web/lib/Star.js +116 -0
  195. package/siderust-web/lib/backend.js +400 -0
  196. package/siderust-web/lib/wrappers.js +512 -0
  197. package/siderust-web/package.json +55 -0
  198. package/siderust-web/src/body.rs +69 -0
  199. package/siderust-web/src/coordinates.rs +302 -0
  200. package/siderust-web/src/ephemeris.rs +456 -0
  201. package/siderust-web/src/events.rs +520 -0
  202. package/siderust-web/src/lib.rs +51 -0
  203. package/siderust-web/src/observer.rs +117 -0
  204. package/siderust-web/src/phase.rs +190 -0
  205. package/siderust-web/src/position.rs +291 -0
  206. package/siderust-web/src/star.rs +178 -0
  207. package/tempoch-js/.github/workflows/ci.yml +142 -0
  208. package/tempoch-js/.gitmodules +3 -0
  209. package/tempoch-js/CHANGELOG.md +25 -0
  210. package/tempoch-js/LICENSE +661 -0
  211. package/tempoch-js/README.md +126 -0
  212. package/tempoch-js/package.json +20 -0
  213. package/tempoch-js/scripts/ci.sh +73 -0
  214. package/tempoch-js/tempoch/.github/workflows/ci.yml +113 -0
  215. package/tempoch-js/tempoch/CHANGELOG.md +82 -0
  216. package/tempoch-js/tempoch/Cargo.lock +947 -0
  217. package/tempoch-js/tempoch/Cargo.toml +3 -0
  218. package/tempoch-js/tempoch/LICENSE +661 -0
  219. package/tempoch-js/tempoch/README.md +76 -0
  220. package/tempoch-js/tempoch/tempoch/Cargo.toml +27 -0
  221. package/tempoch-js/tempoch/tempoch/examples/periods.rs +45 -0
  222. package/tempoch-js/tempoch/tempoch/examples/quickstart.rs +13 -0
  223. package/tempoch-js/tempoch/tempoch/src/lib.rs +49 -0
  224. package/tempoch-js/tempoch/tempoch/tests/integration.rs +57 -0
  225. package/tempoch-js/tempoch/tempoch-core/Cargo.toml +24 -0
  226. package/tempoch-js/tempoch/tempoch-core/src/delta_t.rs +345 -0
  227. package/tempoch-js/tempoch/tempoch-core/src/instant.rs +811 -0
  228. package/tempoch-js/tempoch/tempoch-core/src/julian_date_ext.rs +142 -0
  229. package/tempoch-js/tempoch/tempoch-core/src/lib.rs +81 -0
  230. package/tempoch-js/tempoch/tempoch-core/src/period.rs +1168 -0
  231. package/tempoch-js/tempoch/tempoch-core/src/scales.rs +779 -0
  232. package/tempoch-js/tempoch/tempoch-ffi/Cargo.lock +889 -0
  233. package/tempoch-js/tempoch/tempoch-ffi/Cargo.toml +26 -0
  234. package/tempoch-js/tempoch/tempoch-ffi/build.rs +24 -0
  235. package/tempoch-js/tempoch/tempoch-ffi/cbindgen.toml +30 -0
  236. package/tempoch-js/tempoch/tempoch-ffi/src/error.rs +19 -0
  237. package/tempoch-js/tempoch/tempoch-ffi/src/lib.rs +82 -0
  238. package/tempoch-js/tempoch/tempoch-ffi/src/period.rs +101 -0
  239. package/tempoch-js/tempoch/tempoch-ffi/src/time.rs +711 -0
  240. package/tempoch-js/tempoch/tempoch-ffi/tests/ffi.rs +265 -0
  241. package/tempoch-js/tempoch-node/.prettierignore +6 -0
  242. package/tempoch-js/tempoch-node/.prettierrc.json +6 -0
  243. package/tempoch-js/tempoch-node/Cargo.lock +496 -0
  244. package/tempoch-js/tempoch-node/Cargo.toml +29 -0
  245. package/tempoch-js/tempoch-node/README.md +265 -0
  246. package/tempoch-js/tempoch-node/__test__/index.test.mjs +598 -0
  247. package/tempoch-js/tempoch-node/build.rs +5 -0
  248. package/tempoch-js/tempoch-node/c8.config.json +3 -0
  249. package/tempoch-js/tempoch-node/eslint.config.js +31 -0
  250. package/tempoch-js/tempoch-node/examples/periods.mjs +79 -0
  251. package/tempoch-js/tempoch-node/examples/quickstart.mjs +71 -0
  252. package/tempoch-js/tempoch-node/examples/timescales.mjs +92 -0
  253. package/tempoch-js/tempoch-node/index.d.ts +280 -0
  254. package/tempoch-js/tempoch-node/index.js +32 -0
  255. package/tempoch-js/tempoch-node/lib/JulianDate.js +176 -0
  256. package/tempoch-js/tempoch-node/lib/ModifiedJulianDate.js +156 -0
  257. package/tempoch-js/tempoch-node/lib/Period.js +133 -0
  258. package/tempoch-js/tempoch-node/lib/backend.js +38 -0
  259. package/tempoch-js/tempoch-node/lib/qttyCompat.js +92 -0
  260. package/tempoch-js/tempoch-node/native.cjs +317 -0
  261. package/tempoch-js/tempoch-node/package-lock.json +3223 -0
  262. package/tempoch-js/tempoch-node/package.json +56 -0
  263. package/tempoch-js/tempoch-node/src/lib.rs +573 -0
  264. package/tempoch-js/tempoch-web/Cargo.toml +23 -0
  265. package/tempoch-js/tempoch-web/index.d.ts +95 -0
  266. package/tempoch-js/tempoch-web/index.js +27 -0
  267. package/tempoch-js/tempoch-web/lib/JulianDate.js +170 -0
  268. package/tempoch-js/tempoch-web/lib/ModifiedJulianDate.js +145 -0
  269. package/tempoch-js/tempoch-web/lib/Period.js +121 -0
  270. package/tempoch-js/tempoch-web/lib/backend.js +118 -0
  271. package/tempoch-js/tempoch-web/package.json +46 -0
  272. package/tempoch-js/tempoch-web/src/lib.rs +184 -0
@@ -0,0 +1,323 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ /* prettier-ignore */
4
+
5
+ /* auto-generated by NAPI-RS */
6
+
7
+ const { existsSync, readFileSync } = require('fs')
8
+ const { join } = require('path')
9
+
10
+ const { platform, arch } = process
11
+
12
+ let nativeBinding = null
13
+ let localFileExisted = false
14
+ let loadError = null
15
+
16
+ function isMusl() {
17
+ // For Node 10
18
+ if (!process.report || typeof process.report.getReport !== 'function') {
19
+ try {
20
+ const lddPath = require('child_process').execSync('which ldd').toString().trim()
21
+ return readFileSync(lddPath, 'utf8').includes('musl')
22
+ } catch (e) {
23
+ return true
24
+ }
25
+ } else {
26
+ const { glibcVersionRuntime } = process.report.getReport().header
27
+ return !glibcVersionRuntime
28
+ }
29
+ }
30
+
31
+ switch (platform) {
32
+ case 'android':
33
+ switch (arch) {
34
+ case 'arm64':
35
+ localFileExisted = existsSync(join(__dirname, 'qtty.android-arm64.node'))
36
+ try {
37
+ if (localFileExisted) {
38
+ nativeBinding = require('./qtty.android-arm64.node')
39
+ } else {
40
+ nativeBinding = require('@siderust/qtty-android-arm64')
41
+ }
42
+ } catch (e) {
43
+ loadError = e
44
+ }
45
+ break
46
+ case 'arm':
47
+ localFileExisted = existsSync(join(__dirname, 'qtty.android-arm-eabi.node'))
48
+ try {
49
+ if (localFileExisted) {
50
+ nativeBinding = require('./qtty.android-arm-eabi.node')
51
+ } else {
52
+ nativeBinding = require('@siderust/qtty-android-arm-eabi')
53
+ }
54
+ } catch (e) {
55
+ loadError = e
56
+ }
57
+ break
58
+ default:
59
+ throw new Error(`Unsupported architecture on Android ${arch}`)
60
+ }
61
+ break
62
+ case 'win32':
63
+ switch (arch) {
64
+ case 'x64':
65
+ localFileExisted = existsSync(
66
+ join(__dirname, 'qtty.win32-x64-msvc.node')
67
+ )
68
+ try {
69
+ if (localFileExisted) {
70
+ nativeBinding = require('./qtty.win32-x64-msvc.node')
71
+ } else {
72
+ nativeBinding = require('@siderust/qtty-win32-x64-msvc')
73
+ }
74
+ } catch (e) {
75
+ loadError = e
76
+ }
77
+ break
78
+ case 'ia32':
79
+ localFileExisted = existsSync(
80
+ join(__dirname, 'qtty.win32-ia32-msvc.node')
81
+ )
82
+ try {
83
+ if (localFileExisted) {
84
+ nativeBinding = require('./qtty.win32-ia32-msvc.node')
85
+ } else {
86
+ nativeBinding = require('@siderust/qtty-win32-ia32-msvc')
87
+ }
88
+ } catch (e) {
89
+ loadError = e
90
+ }
91
+ break
92
+ case 'arm64':
93
+ localFileExisted = existsSync(
94
+ join(__dirname, 'qtty.win32-arm64-msvc.node')
95
+ )
96
+ try {
97
+ if (localFileExisted) {
98
+ nativeBinding = require('./qtty.win32-arm64-msvc.node')
99
+ } else {
100
+ nativeBinding = require('@siderust/qtty-win32-arm64-msvc')
101
+ }
102
+ } catch (e) {
103
+ loadError = e
104
+ }
105
+ break
106
+ default:
107
+ throw new Error(`Unsupported architecture on Windows: ${arch}`)
108
+ }
109
+ break
110
+ case 'darwin':
111
+ localFileExisted = existsSync(join(__dirname, 'qtty.darwin-universal.node'))
112
+ try {
113
+ if (localFileExisted) {
114
+ nativeBinding = require('./qtty.darwin-universal.node')
115
+ } else {
116
+ nativeBinding = require('@siderust/qtty-darwin-universal')
117
+ }
118
+ break
119
+ } catch {}
120
+ switch (arch) {
121
+ case 'x64':
122
+ localFileExisted = existsSync(join(__dirname, 'qtty.darwin-x64.node'))
123
+ try {
124
+ if (localFileExisted) {
125
+ nativeBinding = require('./qtty.darwin-x64.node')
126
+ } else {
127
+ nativeBinding = require('@siderust/qtty-darwin-x64')
128
+ }
129
+ } catch (e) {
130
+ loadError = e
131
+ }
132
+ break
133
+ case 'arm64':
134
+ localFileExisted = existsSync(
135
+ join(__dirname, 'qtty.darwin-arm64.node')
136
+ )
137
+ try {
138
+ if (localFileExisted) {
139
+ nativeBinding = require('./qtty.darwin-arm64.node')
140
+ } else {
141
+ nativeBinding = require('@siderust/qtty-darwin-arm64')
142
+ }
143
+ } catch (e) {
144
+ loadError = e
145
+ }
146
+ break
147
+ default:
148
+ throw new Error(`Unsupported architecture on macOS: ${arch}`)
149
+ }
150
+ break
151
+ case 'freebsd':
152
+ if (arch !== 'x64') {
153
+ throw new Error(`Unsupported architecture on FreeBSD: ${arch}`)
154
+ }
155
+ localFileExisted = existsSync(join(__dirname, 'qtty.freebsd-x64.node'))
156
+ try {
157
+ if (localFileExisted) {
158
+ nativeBinding = require('./qtty.freebsd-x64.node')
159
+ } else {
160
+ nativeBinding = require('@siderust/qtty-freebsd-x64')
161
+ }
162
+ } catch (e) {
163
+ loadError = e
164
+ }
165
+ break
166
+ case 'linux':
167
+ switch (arch) {
168
+ case 'x64':
169
+ if (isMusl()) {
170
+ localFileExisted = existsSync(
171
+ join(__dirname, 'qtty.linux-x64-musl.node')
172
+ )
173
+ try {
174
+ if (localFileExisted) {
175
+ nativeBinding = require('./qtty.linux-x64-musl.node')
176
+ } else {
177
+ nativeBinding = require('@siderust/qtty-linux-x64-musl')
178
+ }
179
+ } catch (e) {
180
+ loadError = e
181
+ }
182
+ } else {
183
+ localFileExisted = existsSync(
184
+ join(__dirname, 'qtty.linux-x64-gnu.node')
185
+ )
186
+ try {
187
+ if (localFileExisted) {
188
+ nativeBinding = require('./qtty.linux-x64-gnu.node')
189
+ } else {
190
+ nativeBinding = require('@siderust/qtty-linux-x64-gnu')
191
+ }
192
+ } catch (e) {
193
+ loadError = e
194
+ }
195
+ }
196
+ break
197
+ case 'arm64':
198
+ if (isMusl()) {
199
+ localFileExisted = existsSync(
200
+ join(__dirname, 'qtty.linux-arm64-musl.node')
201
+ )
202
+ try {
203
+ if (localFileExisted) {
204
+ nativeBinding = require('./qtty.linux-arm64-musl.node')
205
+ } else {
206
+ nativeBinding = require('@siderust/qtty-linux-arm64-musl')
207
+ }
208
+ } catch (e) {
209
+ loadError = e
210
+ }
211
+ } else {
212
+ localFileExisted = existsSync(
213
+ join(__dirname, 'qtty.linux-arm64-gnu.node')
214
+ )
215
+ try {
216
+ if (localFileExisted) {
217
+ nativeBinding = require('./qtty.linux-arm64-gnu.node')
218
+ } else {
219
+ nativeBinding = require('@siderust/qtty-linux-arm64-gnu')
220
+ }
221
+ } catch (e) {
222
+ loadError = e
223
+ }
224
+ }
225
+ break
226
+ case 'arm':
227
+ if (isMusl()) {
228
+ localFileExisted = existsSync(
229
+ join(__dirname, 'qtty.linux-arm-musleabihf.node')
230
+ )
231
+ try {
232
+ if (localFileExisted) {
233
+ nativeBinding = require('./qtty.linux-arm-musleabihf.node')
234
+ } else {
235
+ nativeBinding = require('@siderust/qtty-linux-arm-musleabihf')
236
+ }
237
+ } catch (e) {
238
+ loadError = e
239
+ }
240
+ } else {
241
+ localFileExisted = existsSync(
242
+ join(__dirname, 'qtty.linux-arm-gnueabihf.node')
243
+ )
244
+ try {
245
+ if (localFileExisted) {
246
+ nativeBinding = require('./qtty.linux-arm-gnueabihf.node')
247
+ } else {
248
+ nativeBinding = require('@siderust/qtty-linux-arm-gnueabihf')
249
+ }
250
+ } catch (e) {
251
+ loadError = e
252
+ }
253
+ }
254
+ break
255
+ case 'riscv64':
256
+ if (isMusl()) {
257
+ localFileExisted = existsSync(
258
+ join(__dirname, 'qtty.linux-riscv64-musl.node')
259
+ )
260
+ try {
261
+ if (localFileExisted) {
262
+ nativeBinding = require('./qtty.linux-riscv64-musl.node')
263
+ } else {
264
+ nativeBinding = require('@siderust/qtty-linux-riscv64-musl')
265
+ }
266
+ } catch (e) {
267
+ loadError = e
268
+ }
269
+ } else {
270
+ localFileExisted = existsSync(
271
+ join(__dirname, 'qtty.linux-riscv64-gnu.node')
272
+ )
273
+ try {
274
+ if (localFileExisted) {
275
+ nativeBinding = require('./qtty.linux-riscv64-gnu.node')
276
+ } else {
277
+ nativeBinding = require('@siderust/qtty-linux-riscv64-gnu')
278
+ }
279
+ } catch (e) {
280
+ loadError = e
281
+ }
282
+ }
283
+ break
284
+ case 's390x':
285
+ localFileExisted = existsSync(
286
+ join(__dirname, 'qtty.linux-s390x-gnu.node')
287
+ )
288
+ try {
289
+ if (localFileExisted) {
290
+ nativeBinding = require('./qtty.linux-s390x-gnu.node')
291
+ } else {
292
+ nativeBinding = require('@siderust/qtty-linux-s390x-gnu')
293
+ }
294
+ } catch (e) {
295
+ loadError = e
296
+ }
297
+ break
298
+ default:
299
+ throw new Error(`Unsupported architecture on Linux: ${arch}`)
300
+ }
301
+ break
302
+ default:
303
+ throw new Error(`Unsupported OS: ${platform}, architecture: ${arch}`)
304
+ }
305
+
306
+ if (!nativeBinding) {
307
+ if (loadError) {
308
+ throw loadError
309
+ }
310
+ throw new Error(`Failed to load native binding`)
311
+ }
312
+
313
+ const { Quantity, DerivedQuantity, convert, isCompatible, unitDimension, unitSymbol, isValidUnit, ffiVersion, listUnits } = nativeBinding
314
+
315
+ module.exports.Quantity = Quantity
316
+ module.exports.DerivedQuantity = DerivedQuantity
317
+ module.exports.convert = convert
318
+ module.exports.isCompatible = isCompatible
319
+ module.exports.unitDimension = unitDimension
320
+ module.exports.unitSymbol = unitSymbol
321
+ module.exports.isValidUnit = isValidUnit
322
+ module.exports.ffiVersion = ffiVersion
323
+ module.exports.listUnits = listUnits
@@ -0,0 +1,122 @@
1
+ /**
2
+ * @siderust/qtty — DerivedQuantity façade class.
3
+ *
4
+ * A compound quantity like velocity (m/s) or angular velocity (rad/s).
5
+ * This is a plain JS class, mirroring the Quantity façade design.
6
+ *
7
+ * @module @siderust/qtty/lib/DerivedQuantity
8
+ */
9
+
10
+ 'use strict';
11
+
12
+ const backend = require('./backend.js');
13
+
14
+ class DerivedQuantity {
15
+ /**
16
+ * @param {number} value Numeric value.
17
+ * @param {string} numerator Numerator unit name, e.g. `"Meter"`.
18
+ * @param {string} denominator Denominator unit name, e.g. `"Second"`.
19
+ */
20
+ constructor(value, numerator, denominator) {
21
+ if (typeof value !== 'number' || !Number.isFinite(value)) {
22
+ throw new Error('DerivedQuantity value must be a finite number');
23
+ }
24
+ if (!backend.isValidUnit(numerator)) {
25
+ throw new Error(`Unknown numerator unit: "${numerator}"`);
26
+ }
27
+ if (!backend.isValidUnit(denominator)) {
28
+ throw new Error(`Unknown denominator unit: "${denominator}"`);
29
+ }
30
+ this._value = value;
31
+ this._numerator = numerator;
32
+ this._denominator = denominator;
33
+ this._numSymbol = backend.unitSymbol(numerator);
34
+ this._denSymbol = backend.unitSymbol(denominator);
35
+ }
36
+
37
+ /** The numeric value. */
38
+ get value() {
39
+ return this._value;
40
+ }
41
+
42
+ /** The numerator unit name. */
43
+ get numerator() {
44
+ return this._numerator;
45
+ }
46
+
47
+ /** The denominator unit name. */
48
+ get denominator() {
49
+ return this._denominator;
50
+ }
51
+
52
+ /** The compound symbol, e.g. `"m/s"`. */
53
+ get symbol() {
54
+ return `${this._numSymbol}/${this._denSymbol}`;
55
+ }
56
+
57
+ /**
58
+ * Convert to different units.
59
+ * @param {string} numerator Target numerator unit.
60
+ * @param {string} denominator Target denominator unit.
61
+ * @returns {DerivedQuantity}
62
+ */
63
+ to(numerator, denominator) {
64
+ // Convert numerator and denominator independently.
65
+ // v_new = v_old × (numFactor / denFactor)
66
+ const numFactor = backend.convert(1, this._numerator, numerator);
67
+ const denFactor = backend.convert(1, this._denominator, denominator);
68
+ return new DerivedQuantity((this._value * numFactor) / denFactor, numerator, denominator);
69
+ }
70
+
71
+ /**
72
+ * Multiply by a scalar.
73
+ * @param {number} scalar
74
+ * @returns {DerivedQuantity}
75
+ */
76
+ mul(scalar) {
77
+ return new DerivedQuantity(this._value * scalar, this._numerator, this._denominator);
78
+ }
79
+
80
+ /**
81
+ * Divide by a scalar.
82
+ * @param {number} scalar
83
+ * @returns {DerivedQuantity}
84
+ */
85
+ div(scalar) {
86
+ return new DerivedQuantity(this._value / scalar, this._numerator, this._denominator);
87
+ }
88
+
89
+ /** Negate the value. */
90
+ neg() {
91
+ return new DerivedQuantity(-this._value, this._numerator, this._denominator);
92
+ }
93
+
94
+ /**
95
+ * Format as a human-readable string.
96
+ * @param {number} [precision]
97
+ * @returns {string}
98
+ */
99
+ format(precision) {
100
+ const v =
101
+ precision != null && precision >= 0 ? this._value.toFixed(precision) : String(this._value);
102
+ return `${v} ${this.symbol}`;
103
+ }
104
+
105
+ /**
106
+ * Serialize to a plain JSON object.
107
+ * @returns {{ value: number, numerator: string, denominator: string }}
108
+ */
109
+ toJson() {
110
+ return {
111
+ value: this._value,
112
+ numerator: this._numerator,
113
+ denominator: this._denominator,
114
+ };
115
+ }
116
+
117
+ toString() {
118
+ return this.format();
119
+ }
120
+ }
121
+
122
+ module.exports = { DerivedQuantity };
@@ -0,0 +1,151 @@
1
+ /**
2
+ * @siderust/qtty — Quantity façade class.
3
+ *
4
+ * This is the public runtime class for a physical quantity. It is a plain
5
+ * JS object (not a native addon class) so that the same `Quantity` identity
6
+ * works in both Node (NAPI-RS) and Web (WASM) environments, and instances
7
+ * produced by `@siderust/qtty` can flow through `@siderust/tempoch` and
8
+ * `@siderust/siderust` without cross-addon identity mismatches.
9
+ *
10
+ * @module @siderust/qtty/lib/Quantity
11
+ */
12
+
13
+ 'use strict';
14
+
15
+ const backend = require('./backend.js');
16
+
17
+ class Quantity {
18
+ /**
19
+ * @param {number} value Numeric value.
20
+ * @param {string} unit Unit name, e.g. `"Meter"`, `"Kilometer"`.
21
+ */
22
+ constructor(value, unit) {
23
+ if (typeof value !== 'number' || !Number.isFinite(value)) {
24
+ throw new Error('Quantity value must be a finite number');
25
+ }
26
+ if (!backend.isValidUnit(unit)) {
27
+ throw new Error(`Unknown unit: "${unit}". Use listUnits() to list valid units.`);
28
+ }
29
+ this._value = value;
30
+ this._unit = unit;
31
+ this._symbol = backend.unitSymbol(unit);
32
+ this._dimension = backend.unitDimension(unit);
33
+ }
34
+
35
+ /** The numeric value of this quantity. */
36
+ get value() {
37
+ return this._value;
38
+ }
39
+
40
+ /** The unit name, e.g. `"Meter"`. */
41
+ get unit() {
42
+ return this._unit;
43
+ }
44
+
45
+ /** The unit symbol, e.g. `"m"`. */
46
+ get symbol() {
47
+ return this._symbol;
48
+ }
49
+
50
+ /** The dimension name, e.g. `"Length"`. */
51
+ get dimension() {
52
+ return this._dimension;
53
+ }
54
+
55
+ /**
56
+ * Convert to a different unit.
57
+ * @param {string} targetUnit
58
+ * @returns {Quantity}
59
+ */
60
+ to(targetUnit) {
61
+ const converted = backend.convert(this._value, this._unit, targetUnit);
62
+ return new Quantity(converted, targetUnit);
63
+ }
64
+
65
+ /**
66
+ * Check dimensional compatibility with another Quantity.
67
+ * @param {Quantity} other
68
+ * @returns {boolean}
69
+ */
70
+ compatible(other) {
71
+ return backend.isCompatible(this._unit, other._unit);
72
+ }
73
+
74
+ /**
75
+ * Add another quantity (same dimension). Result uses this quantity's unit.
76
+ * @param {Quantity} other
77
+ * @returns {Quantity}
78
+ */
79
+ add(other) {
80
+ if (!this.compatible(other)) {
81
+ throw new Error(
82
+ `Cannot add quantities with different dimensions: ${this._dimension} vs ${other._dimension}`,
83
+ );
84
+ }
85
+ const otherInMyUnit = backend.convert(other._value, other._unit, this._unit);
86
+ return new Quantity(this._value + otherInMyUnit, this._unit);
87
+ }
88
+
89
+ /**
90
+ * Subtract another quantity (same dimension). Result uses this quantity's unit.
91
+ * @param {Quantity} other
92
+ * @returns {Quantity}
93
+ */
94
+ sub(other) {
95
+ if (!this.compatible(other)) {
96
+ throw new Error(
97
+ `Cannot subtract quantities with different dimensions: ${this._dimension} vs ${other._dimension}`,
98
+ );
99
+ }
100
+ const otherInMyUnit = backend.convert(other._value, other._unit, this._unit);
101
+ return new Quantity(this._value - otherInMyUnit, this._unit);
102
+ }
103
+
104
+ /**
105
+ * Multiply by a scalar.
106
+ * @param {number} scalar
107
+ * @returns {Quantity}
108
+ */
109
+ mul(scalar) {
110
+ return new Quantity(this._value * scalar, this._unit);
111
+ }
112
+
113
+ /**
114
+ * Divide by a scalar.
115
+ * @param {number} scalar
116
+ * @returns {Quantity}
117
+ */
118
+ div(scalar) {
119
+ return new Quantity(this._value / scalar, this._unit);
120
+ }
121
+
122
+ /** Negate the value. */
123
+ neg() {
124
+ return new Quantity(-this._value, this._unit);
125
+ }
126
+
127
+ /**
128
+ * Format as a human-readable string.
129
+ * @param {number} [precision]
130
+ * @returns {string}
131
+ */
132
+ format(precision) {
133
+ const v =
134
+ precision != null && precision >= 0 ? this._value.toFixed(precision) : String(this._value);
135
+ return `${v} ${this._symbol}`;
136
+ }
137
+
138
+ /**
139
+ * Serialize to a plain JSON object.
140
+ * @returns {{ value: number, unit: string }}
141
+ */
142
+ toJson() {
143
+ return { value: this._value, unit: this._unit };
144
+ }
145
+
146
+ toString() {
147
+ return this.format();
148
+ }
149
+ }
150
+
151
+ module.exports = { Quantity };
@@ -0,0 +1,25 @@
1
+ /**
2
+ * @siderust/qtty — Internal backend abstraction.
3
+ *
4
+ * This module loads the native NAPI-RS addon and re-exports only the
5
+ * primitive-level helpers that the JS façade classes need. Consumer code
6
+ * should never import this module directly.
7
+ *
8
+ * @module @siderust/qtty/lib/backend
9
+ * @private
10
+ */
11
+
12
+ 'use strict';
13
+
14
+ const native = require('../native.cjs');
15
+
16
+ // Re-export the primitive operations the façade needs.
17
+ module.exports = {
18
+ convert: native.convert,
19
+ isCompatible: native.isCompatible,
20
+ unitDimension: native.unitDimension,
21
+ unitSymbol: native.unitSymbol,
22
+ isValidUnit: native.isValidUnit,
23
+ listUnits: native.listUnits,
24
+ ffiVersion: native.ffiVersion,
25
+ };