@depup/stripe 21.0.0-depup.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 (654) hide show
  1. package/CHANGELOG.md +4529 -0
  2. package/LICENSE +20 -0
  3. package/OPENAPI_VERSION +1 -0
  4. package/README.md +25 -0
  5. package/VERSION +1 -0
  6. package/changes.json +5 -0
  7. package/cjs/Decimal.js +854 -0
  8. package/cjs/Error.js +284 -0
  9. package/cjs/RequestSender.js +469 -0
  10. package/cjs/ResourceNamespace.js +21 -0
  11. package/cjs/StripeContext.js +56 -0
  12. package/cjs/StripeEmitter.js +46 -0
  13. package/cjs/StripeMethod.js +36 -0
  14. package/cjs/StripeResource.js +188 -0
  15. package/cjs/V2Coercion.js +109 -0
  16. package/cjs/Webhooks.js +225 -0
  17. package/cjs/apiVersion.js +6 -0
  18. package/cjs/autoPagination.js +294 -0
  19. package/cjs/crypto/CryptoProvider.js +51 -0
  20. package/cjs/crypto/NodeCryptoProvider.js +30 -0
  21. package/cjs/crypto/SubtleCryptoProvider.js +51 -0
  22. package/cjs/multipart.js +61 -0
  23. package/cjs/net/FetchHttpClient.js +145 -0
  24. package/cjs/net/HttpClient.js +53 -0
  25. package/cjs/net/NodeHttpClient.js +108 -0
  26. package/cjs/package.json +1 -0
  27. package/cjs/platform/NodePlatformFunctions.js +98 -0
  28. package/cjs/platform/PlatformFunctions.js +98 -0
  29. package/cjs/platform/WebPlatformFunctions.js +38 -0
  30. package/cjs/resources/AccountLinks.js +9 -0
  31. package/cjs/resources/AccountSessions.js +9 -0
  32. package/cjs/resources/Accounts.js +101 -0
  33. package/cjs/resources/ApplePayDomains.js +22 -0
  34. package/cjs/resources/ApplicationFees.js +34 -0
  35. package/cjs/resources/Apps/Secrets.js +19 -0
  36. package/cjs/resources/Balance.js +9 -0
  37. package/cjs/resources/BalanceSettings.js +10 -0
  38. package/cjs/resources/BalanceTransactions.js +17 -0
  39. package/cjs/resources/Billing/Alerts.js +27 -0
  40. package/cjs/resources/Billing/CreditBalanceSummary.js +12 -0
  41. package/cjs/resources/Billing/CreditBalanceTransactions.js +17 -0
  42. package/cjs/resources/Billing/CreditGrants.js +30 -0
  43. package/cjs/resources/Billing/MeterEventAdjustments.js +12 -0
  44. package/cjs/resources/Billing/MeterEvents.js +9 -0
  45. package/cjs/resources/Billing/Meters.js +29 -0
  46. package/cjs/resources/BillingPortal/Configurations.js +25 -0
  47. package/cjs/resources/BillingPortal/Sessions.js +12 -0
  48. package/cjs/resources/Charges.js +25 -0
  49. package/cjs/resources/Checkout/Sessions.js +538 -0
  50. package/cjs/resources/Climate/Orders.js +61 -0
  51. package/cjs/resources/Climate/Products.js +33 -0
  52. package/cjs/resources/Climate/Suppliers.js +17 -0
  53. package/cjs/resources/ConfirmationTokens.js +12 -0
  54. package/cjs/resources/CountrySpecs.js +17 -0
  55. package/cjs/resources/Coupons.js +17 -0
  56. package/cjs/resources/CreditNotes.js +253 -0
  57. package/cjs/resources/CustomerSessions.js +9 -0
  58. package/cjs/resources/Customers.js +581 -0
  59. package/cjs/resources/Disputes.js +19 -0
  60. package/cjs/resources/Entitlements/ActiveEntitlements.js +17 -0
  61. package/cjs/resources/Entitlements/Features.js +22 -0
  62. package/cjs/resources/EphemeralKeys.js +18 -0
  63. package/cjs/resources/Events.js +14 -0
  64. package/cjs/resources/ExchangeRates.js +17 -0
  65. package/cjs/resources/FileLinks.js +16 -0
  66. package/cjs/resources/Files.js +24 -0
  67. package/cjs/resources/FinancialConnections/Accounts.js +38 -0
  68. package/cjs/resources/FinancialConnections/Sessions.js +16 -0
  69. package/cjs/resources/FinancialConnections/Transactions.js +17 -0
  70. package/cjs/resources/Forwarding/Requests.js +18 -0
  71. package/cjs/resources/Identity/VerificationReports.js +17 -0
  72. package/cjs/resources/Identity/VerificationSessions.js +33 -0
  73. package/cjs/resources/InvoiceItems.js +131 -0
  74. package/cjs/resources/InvoicePayments.js +17 -0
  75. package/cjs/resources/InvoiceRenderingTemplates.js +25 -0
  76. package/cjs/resources/Invoices.js +776 -0
  77. package/cjs/resources/Issuing/Authorizations.js +847 -0
  78. package/cjs/resources/Issuing/Cardholders.js +22 -0
  79. package/cjs/resources/Issuing/Cards.js +16 -0
  80. package/cjs/resources/Issuing/Disputes.js +26 -0
  81. package/cjs/resources/Issuing/PersonalizationDesigns.js +25 -0
  82. package/cjs/resources/Issuing/PhysicalBundles.js +17 -0
  83. package/cjs/resources/Issuing/Tokens.js +21 -0
  84. package/cjs/resources/Issuing/Transactions.js +275 -0
  85. package/cjs/resources/Mandates.js +9 -0
  86. package/cjs/resources/OAuth.js +44 -0
  87. package/cjs/resources/PaymentAttemptRecords.js +17 -0
  88. package/cjs/resources/PaymentIntents.js +56 -0
  89. package/cjs/resources/PaymentLinks.js +420 -0
  90. package/cjs/resources/PaymentMethodConfigurations.js +25 -0
  91. package/cjs/resources/PaymentMethodDomains.js +29 -0
  92. package/cjs/resources/PaymentMethods.js +30 -0
  93. package/cjs/resources/PaymentRecords.js +37 -0
  94. package/cjs/resources/Payouts.js +24 -0
  95. package/cjs/resources/Plans.js +141 -0
  96. package/cjs/resources/Prices.js +346 -0
  97. package/cjs/resources/Products.js +72 -0
  98. package/cjs/resources/PromotionCodes.js +22 -0
  99. package/cjs/resources/Quotes.js +825 -0
  100. package/cjs/resources/Radar/EarlyFraudWarnings.js +17 -0
  101. package/cjs/resources/Radar/PaymentEvaluations.js +12 -0
  102. package/cjs/resources/Radar/ValueListItems.js +25 -0
  103. package/cjs/resources/Radar/ValueLists.js +26 -0
  104. package/cjs/resources/Refunds.js +20 -0
  105. package/cjs/resources/Reporting/ReportRuns.js +18 -0
  106. package/cjs/resources/Reporting/ReportTypes.js +17 -0
  107. package/cjs/resources/Reviews.js +18 -0
  108. package/cjs/resources/SetupAttempts.js +13 -0
  109. package/cjs/resources/SetupIntents.js +34 -0
  110. package/cjs/resources/ShippingRates.js +22 -0
  111. package/cjs/resources/Sigma/ScheduledQueryRuns.js +17 -0
  112. package/cjs/resources/Sources.js +20 -0
  113. package/cjs/resources/SubscriptionItems.js +378 -0
  114. package/cjs/resources/SubscriptionSchedules.js +107 -0
  115. package/cjs/resources/Subscriptions.js +888 -0
  116. package/cjs/resources/Tax/Associations.js +9 -0
  117. package/cjs/resources/Tax/Calculations.js +18 -0
  118. package/cjs/resources/Tax/Registrations.js +22 -0
  119. package/cjs/resources/Tax/Settings.js +10 -0
  120. package/cjs/resources/Tax/Transactions.js +25 -0
  121. package/cjs/resources/TaxCodes.js +14 -0
  122. package/cjs/resources/TaxIds.js +16 -0
  123. package/cjs/resources/TaxRates.js +16 -0
  124. package/cjs/resources/Terminal/Configurations.js +29 -0
  125. package/cjs/resources/Terminal/ConnectionTokens.js +12 -0
  126. package/cjs/resources/Terminal/Locations.js +26 -0
  127. package/cjs/resources/Terminal/OnboardingLinks.js +12 -0
  128. package/cjs/resources/Terminal/Readers.js +58 -0
  129. package/cjs/resources/TestHelpers/ConfirmationTokens.js +12 -0
  130. package/cjs/resources/TestHelpers/Customers.js +12 -0
  131. package/cjs/resources/TestHelpers/Issuing/Authorizations.js +1293 -0
  132. package/cjs/resources/TestHelpers/Issuing/Cards.js +28 -0
  133. package/cjs/resources/TestHelpers/Issuing/PersonalizationDesigns.js +20 -0
  134. package/cjs/resources/TestHelpers/Issuing/Transactions.js +364 -0
  135. package/cjs/resources/TestHelpers/Refunds.js +12 -0
  136. package/cjs/resources/TestHelpers/Terminal/Readers.js +20 -0
  137. package/cjs/resources/TestHelpers/TestClocks.js +29 -0
  138. package/cjs/resources/TestHelpers/Treasury/InboundTransfers.js +20 -0
  139. package/cjs/resources/TestHelpers/Treasury/OutboundPayments.js +24 -0
  140. package/cjs/resources/TestHelpers/Treasury/OutboundTransfers.js +24 -0
  141. package/cjs/resources/TestHelpers/Treasury/ReceivedCredits.js +12 -0
  142. package/cjs/resources/TestHelpers/Treasury/ReceivedDebits.js +12 -0
  143. package/cjs/resources/Tokens.js +10 -0
  144. package/cjs/resources/Topups.js +17 -0
  145. package/cjs/resources/Transfers.js +33 -0
  146. package/cjs/resources/Treasury/CreditReversals.js +21 -0
  147. package/cjs/resources/Treasury/DebitReversals.js +21 -0
  148. package/cjs/resources/Treasury/FinancialAccounts.js +37 -0
  149. package/cjs/resources/Treasury/InboundTransfers.js +25 -0
  150. package/cjs/resources/Treasury/OutboundPayments.js +25 -0
  151. package/cjs/resources/Treasury/OutboundTransfers.js +25 -0
  152. package/cjs/resources/Treasury/ReceivedCredits.js +17 -0
  153. package/cjs/resources/Treasury/ReceivedDebits.js +17 -0
  154. package/cjs/resources/Treasury/TransactionEntries.js +393 -0
  155. package/cjs/resources/Treasury/Transactions.js +447 -0
  156. package/cjs/resources/V2/Billing/MeterEventAdjustments.js +12 -0
  157. package/cjs/resources/V2/Billing/MeterEventSession.js +12 -0
  158. package/cjs/resources/V2/Billing/MeterEventStream.js +13 -0
  159. package/cjs/resources/V2/Billing/MeterEvents.js +9 -0
  160. package/cjs/resources/V2/Core/AccountLinks.js +9 -0
  161. package/cjs/resources/V2/Core/AccountTokens.js +35 -0
  162. package/cjs/resources/V2/Core/Accounts/PersonTokens.js +25 -0
  163. package/cjs/resources/V2/Core/Accounts/Persons.js +91 -0
  164. package/cjs/resources/V2/Core/Accounts.js +177 -0
  165. package/cjs/resources/V2/Core/EventDestinations.js +41 -0
  166. package/cjs/resources/V2/Core/Events.js +66 -0
  167. package/cjs/resources/WebhookEndpoints.js +26 -0
  168. package/cjs/resources.js +324 -0
  169. package/cjs/stripe.cjs.node.js +13 -0
  170. package/cjs/stripe.cjs.worker.js +13 -0
  171. package/cjs/stripe.core.js +412 -0
  172. package/cjs/utils.js +477 -0
  173. package/esm/Decimal.js +850 -0
  174. package/esm/Error.js +259 -0
  175. package/esm/RequestSender.js +465 -0
  176. package/esm/ResourceNamespace.js +17 -0
  177. package/esm/StripeContext.js +52 -0
  178. package/esm/StripeEmitter.js +42 -0
  179. package/esm/StripeMethod.js +32 -0
  180. package/esm/StripeResource.js +185 -0
  181. package/esm/V2Coercion.js +104 -0
  182. package/esm/Webhooks.js +221 -0
  183. package/esm/apiVersion.js +3 -0
  184. package/esm/autoPagination.js +290 -0
  185. package/esm/crypto/CryptoProvider.js +46 -0
  186. package/esm/crypto/NodeCryptoProvider.js +26 -0
  187. package/esm/crypto/SubtleCryptoProvider.js +47 -0
  188. package/esm/multipart.js +57 -0
  189. package/esm/net/FetchHttpClient.js +140 -0
  190. package/esm/net/HttpClient.js +48 -0
  191. package/esm/net/NodeHttpClient.js +103 -0
  192. package/esm/package.json +1 -0
  193. package/esm/platform/NodePlatformFunctions.js +94 -0
  194. package/esm/platform/PlatformFunctions.js +94 -0
  195. package/esm/platform/WebPlatformFunctions.js +34 -0
  196. package/esm/resources/AccountLinks.js +6 -0
  197. package/esm/resources/AccountSessions.js +6 -0
  198. package/esm/resources/Accounts.js +98 -0
  199. package/esm/resources/ApplePayDomains.js +19 -0
  200. package/esm/resources/ApplicationFees.js +31 -0
  201. package/esm/resources/Apps/Secrets.js +16 -0
  202. package/esm/resources/Balance.js +6 -0
  203. package/esm/resources/BalanceSettings.js +7 -0
  204. package/esm/resources/BalanceTransactions.js +14 -0
  205. package/esm/resources/Billing/Alerts.js +24 -0
  206. package/esm/resources/Billing/CreditBalanceSummary.js +9 -0
  207. package/esm/resources/Billing/CreditBalanceTransactions.js +14 -0
  208. package/esm/resources/Billing/CreditGrants.js +27 -0
  209. package/esm/resources/Billing/MeterEventAdjustments.js +9 -0
  210. package/esm/resources/Billing/MeterEvents.js +6 -0
  211. package/esm/resources/Billing/Meters.js +26 -0
  212. package/esm/resources/BillingPortal/Configurations.js +22 -0
  213. package/esm/resources/BillingPortal/Sessions.js +9 -0
  214. package/esm/resources/Charges.js +22 -0
  215. package/esm/resources/Checkout/Sessions.js +535 -0
  216. package/esm/resources/Climate/Orders.js +58 -0
  217. package/esm/resources/Climate/Products.js +30 -0
  218. package/esm/resources/Climate/Suppliers.js +14 -0
  219. package/esm/resources/ConfirmationTokens.js +9 -0
  220. package/esm/resources/CountrySpecs.js +14 -0
  221. package/esm/resources/Coupons.js +14 -0
  222. package/esm/resources/CreditNotes.js +250 -0
  223. package/esm/resources/CustomerSessions.js +6 -0
  224. package/esm/resources/Customers.js +578 -0
  225. package/esm/resources/Disputes.js +16 -0
  226. package/esm/resources/Entitlements/ActiveEntitlements.js +14 -0
  227. package/esm/resources/Entitlements/Features.js +19 -0
  228. package/esm/resources/EphemeralKeys.js +15 -0
  229. package/esm/resources/Events.js +11 -0
  230. package/esm/resources/ExchangeRates.js +14 -0
  231. package/esm/resources/FileLinks.js +13 -0
  232. package/esm/resources/Files.js +21 -0
  233. package/esm/resources/FinancialConnections/Accounts.js +35 -0
  234. package/esm/resources/FinancialConnections/Sessions.js +13 -0
  235. package/esm/resources/FinancialConnections/Transactions.js +14 -0
  236. package/esm/resources/Forwarding/Requests.js +15 -0
  237. package/esm/resources/Identity/VerificationReports.js +14 -0
  238. package/esm/resources/Identity/VerificationSessions.js +30 -0
  239. package/esm/resources/InvoiceItems.js +128 -0
  240. package/esm/resources/InvoicePayments.js +14 -0
  241. package/esm/resources/InvoiceRenderingTemplates.js +22 -0
  242. package/esm/resources/Invoices.js +773 -0
  243. package/esm/resources/Issuing/Authorizations.js +844 -0
  244. package/esm/resources/Issuing/Cardholders.js +19 -0
  245. package/esm/resources/Issuing/Cards.js +13 -0
  246. package/esm/resources/Issuing/Disputes.js +23 -0
  247. package/esm/resources/Issuing/PersonalizationDesigns.js +22 -0
  248. package/esm/resources/Issuing/PhysicalBundles.js +14 -0
  249. package/esm/resources/Issuing/Tokens.js +18 -0
  250. package/esm/resources/Issuing/Transactions.js +272 -0
  251. package/esm/resources/Mandates.js +6 -0
  252. package/esm/resources/OAuth.js +42 -0
  253. package/esm/resources/PaymentAttemptRecords.js +14 -0
  254. package/esm/resources/PaymentIntents.js +53 -0
  255. package/esm/resources/PaymentLinks.js +417 -0
  256. package/esm/resources/PaymentMethodConfigurations.js +22 -0
  257. package/esm/resources/PaymentMethodDomains.js +26 -0
  258. package/esm/resources/PaymentMethods.js +27 -0
  259. package/esm/resources/PaymentRecords.js +34 -0
  260. package/esm/resources/Payouts.js +21 -0
  261. package/esm/resources/Plans.js +138 -0
  262. package/esm/resources/Prices.js +343 -0
  263. package/esm/resources/Products.js +69 -0
  264. package/esm/resources/PromotionCodes.js +19 -0
  265. package/esm/resources/Quotes.js +822 -0
  266. package/esm/resources/Radar/EarlyFraudWarnings.js +14 -0
  267. package/esm/resources/Radar/PaymentEvaluations.js +9 -0
  268. package/esm/resources/Radar/ValueListItems.js +22 -0
  269. package/esm/resources/Radar/ValueLists.js +23 -0
  270. package/esm/resources/Refunds.js +17 -0
  271. package/esm/resources/Reporting/ReportRuns.js +15 -0
  272. package/esm/resources/Reporting/ReportTypes.js +14 -0
  273. package/esm/resources/Reviews.js +15 -0
  274. package/esm/resources/SetupAttempts.js +10 -0
  275. package/esm/resources/SetupIntents.js +31 -0
  276. package/esm/resources/ShippingRates.js +19 -0
  277. package/esm/resources/Sigma/ScheduledQueryRuns.js +14 -0
  278. package/esm/resources/Sources.js +17 -0
  279. package/esm/resources/SubscriptionItems.js +375 -0
  280. package/esm/resources/SubscriptionSchedules.js +104 -0
  281. package/esm/resources/Subscriptions.js +885 -0
  282. package/esm/resources/Tax/Associations.js +6 -0
  283. package/esm/resources/Tax/Calculations.js +15 -0
  284. package/esm/resources/Tax/Registrations.js +19 -0
  285. package/esm/resources/Tax/Settings.js +7 -0
  286. package/esm/resources/Tax/Transactions.js +22 -0
  287. package/esm/resources/TaxCodes.js +11 -0
  288. package/esm/resources/TaxIds.js +13 -0
  289. package/esm/resources/TaxRates.js +13 -0
  290. package/esm/resources/Terminal/Configurations.js +26 -0
  291. package/esm/resources/Terminal/ConnectionTokens.js +9 -0
  292. package/esm/resources/Terminal/Locations.js +23 -0
  293. package/esm/resources/Terminal/OnboardingLinks.js +9 -0
  294. package/esm/resources/Terminal/Readers.js +55 -0
  295. package/esm/resources/TestHelpers/ConfirmationTokens.js +9 -0
  296. package/esm/resources/TestHelpers/Customers.js +9 -0
  297. package/esm/resources/TestHelpers/Issuing/Authorizations.js +1290 -0
  298. package/esm/resources/TestHelpers/Issuing/Cards.js +25 -0
  299. package/esm/resources/TestHelpers/Issuing/PersonalizationDesigns.js +17 -0
  300. package/esm/resources/TestHelpers/Issuing/Transactions.js +361 -0
  301. package/esm/resources/TestHelpers/Refunds.js +9 -0
  302. package/esm/resources/TestHelpers/Terminal/Readers.js +17 -0
  303. package/esm/resources/TestHelpers/TestClocks.js +26 -0
  304. package/esm/resources/TestHelpers/Treasury/InboundTransfers.js +17 -0
  305. package/esm/resources/TestHelpers/Treasury/OutboundPayments.js +21 -0
  306. package/esm/resources/TestHelpers/Treasury/OutboundTransfers.js +21 -0
  307. package/esm/resources/TestHelpers/Treasury/ReceivedCredits.js +9 -0
  308. package/esm/resources/TestHelpers/Treasury/ReceivedDebits.js +9 -0
  309. package/esm/resources/Tokens.js +7 -0
  310. package/esm/resources/Topups.js +14 -0
  311. package/esm/resources/Transfers.js +30 -0
  312. package/esm/resources/Treasury/CreditReversals.js +18 -0
  313. package/esm/resources/Treasury/DebitReversals.js +18 -0
  314. package/esm/resources/Treasury/FinancialAccounts.js +34 -0
  315. package/esm/resources/Treasury/InboundTransfers.js +22 -0
  316. package/esm/resources/Treasury/OutboundPayments.js +22 -0
  317. package/esm/resources/Treasury/OutboundTransfers.js +22 -0
  318. package/esm/resources/Treasury/ReceivedCredits.js +14 -0
  319. package/esm/resources/Treasury/ReceivedDebits.js +14 -0
  320. package/esm/resources/Treasury/TransactionEntries.js +390 -0
  321. package/esm/resources/Treasury/Transactions.js +444 -0
  322. package/esm/resources/V2/Billing/MeterEventAdjustments.js +9 -0
  323. package/esm/resources/V2/Billing/MeterEventSession.js +9 -0
  324. package/esm/resources/V2/Billing/MeterEventStream.js +10 -0
  325. package/esm/resources/V2/Billing/MeterEvents.js +6 -0
  326. package/esm/resources/V2/Core/AccountLinks.js +6 -0
  327. package/esm/resources/V2/Core/AccountTokens.js +32 -0
  328. package/esm/resources/V2/Core/Accounts/PersonTokens.js +22 -0
  329. package/esm/resources/V2/Core/Accounts/Persons.js +88 -0
  330. package/esm/resources/V2/Core/Accounts.js +174 -0
  331. package/esm/resources/V2/Core/EventDestinations.js +38 -0
  332. package/esm/resources/V2/Core/Events.js +63 -0
  333. package/esm/resources/WebhookEndpoints.js +23 -0
  334. package/esm/resources.js +263 -0
  335. package/esm/stripe.core.js +408 -0
  336. package/esm/stripe.esm.node.js +5 -0
  337. package/esm/stripe.esm.worker.js +5 -0
  338. package/esm/utils.js +450 -0
  339. package/package.json +110 -0
  340. package/types/.eslintrc.js +22 -0
  341. package/types/AccountLinks.d.ts +33 -0
  342. package/types/AccountLinksResource.d.ts +78 -0
  343. package/types/AccountSessions.d.ts +578 -0
  344. package/types/AccountSessionsResource.d.ts +677 -0
  345. package/types/Accounts.d.ts +1736 -0
  346. package/types/AccountsResource.d.ts +5312 -0
  347. package/types/ApplePayDomains.d.ts +57 -0
  348. package/types/ApplePayDomainsResource.d.ts +77 -0
  349. package/types/ApplicationFees.d.ts +108 -0
  350. package/types/ApplicationFeesResource.d.ts +162 -0
  351. package/types/Applications.d.ts +55 -0
  352. package/types/Apps/Secrets.d.ts +80 -0
  353. package/types/Apps/SecretsResource.d.ts +186 -0
  354. package/types/Balance.d.ts +343 -0
  355. package/types/BalanceResource.d.ts +26 -0
  356. package/types/BalanceSettings.d.ts +103 -0
  357. package/types/BalanceSettingsResource.d.ts +124 -0
  358. package/types/BalanceTransactionSources.d.ts +23 -0
  359. package/types/BalanceTransactions.d.ts +176 -0
  360. package/types/BalanceTransactionsResource.d.ts +72 -0
  361. package/types/BankAccounts.d.ts +433 -0
  362. package/types/Billing/AlertTriggereds.d.ts +42 -0
  363. package/types/Billing/Alerts.d.ts +84 -0
  364. package/types/Billing/AlertsResource.d.ts +183 -0
  365. package/types/Billing/CreditBalanceSummary.d.ts +99 -0
  366. package/types/Billing/CreditBalanceSummaryResource.d.ts +83 -0
  367. package/types/Billing/CreditBalanceTransactions.d.ts +178 -0
  368. package/types/Billing/CreditBalanceTransactionsResource.d.ts +62 -0
  369. package/types/Billing/CreditGrants.d.ts +150 -0
  370. package/types/Billing/CreditGrantsResource.d.ts +248 -0
  371. package/types/Billing/MeterEventAdjustments.d.ts +53 -0
  372. package/types/Billing/MeterEventAdjustmentsResource.d.ts +48 -0
  373. package/types/Billing/MeterEventSummaries.d.ts +50 -0
  374. package/types/Billing/MeterEvents.d.ts +49 -0
  375. package/types/Billing/MeterEventsResource.d.ts +46 -0
  376. package/types/Billing/Meters.d.ts +110 -0
  377. package/types/Billing/MetersResource.d.ts +234 -0
  378. package/types/BillingPortal/Configurations.d.ts +319 -0
  379. package/types/BillingPortal/ConfigurationsResource.d.ts +679 -0
  380. package/types/BillingPortal/Sessions.d.ts +293 -0
  381. package/types/BillingPortal/SessionsResource.d.ts +273 -0
  382. package/types/Capabilities.d.ts +422 -0
  383. package/types/Cards.d.ts +225 -0
  384. package/types/CashBalances.d.ts +57 -0
  385. package/types/Charges.d.ts +2646 -0
  386. package/types/ChargesResource.d.ts +426 -0
  387. package/types/Checkout/Sessions.d.ts +2878 -0
  388. package/types/Checkout/SessionsResource.d.ts +4027 -0
  389. package/types/Climate/Orders.d.ts +197 -0
  390. package/types/Climate/OrdersResource.d.ts +159 -0
  391. package/types/Climate/Products.d.ts +81 -0
  392. package/types/Climate/ProductsResource.d.ts +45 -0
  393. package/types/Climate/Suppliers.d.ts +82 -0
  394. package/types/Climate/SuppliersResource.d.ts +45 -0
  395. package/types/ConfirmationTokens.d.ts +1755 -0
  396. package/types/ConfirmationTokensResource.d.ts +27 -0
  397. package/types/ConnectCollectionTransfers.d.ts +40 -0
  398. package/types/CountrySpecs.d.ts +88 -0
  399. package/types/CountrySpecsResource.d.ts +43 -0
  400. package/types/Coupons.d.ts +139 -0
  401. package/types/CouponsResource.d.ts +203 -0
  402. package/types/CreditNoteLineItems.d.ts +195 -0
  403. package/types/CreditNotes.d.ts +408 -0
  404. package/types/CreditNotesResource.d.ts +765 -0
  405. package/types/CustomerBalanceTransactions.d.ts +106 -0
  406. package/types/CustomerCashBalanceTransactions.d.ts +230 -0
  407. package/types/CustomerSessions.d.ts +283 -0
  408. package/types/CustomerSessionsResource.d.ts +263 -0
  409. package/types/CustomerSources.d.ts +9 -0
  410. package/types/Customers.d.ts +326 -0
  411. package/types/CustomersResource.d.ts +1554 -0
  412. package/types/Discounts.d.ts +175 -0
  413. package/types/Disputes.d.ts +519 -0
  414. package/types/DisputesResource.d.ts +384 -0
  415. package/types/Entitlements/ActiveEntitlementSummaries.d.ts +32 -0
  416. package/types/Entitlements/ActiveEntitlements.d.ts +37 -0
  417. package/types/Entitlements/ActiveEntitlementsResource.d.ts +49 -0
  418. package/types/Entitlements/Features.d.ts +48 -0
  419. package/types/Entitlements/FeaturesResource.d.ts +118 -0
  420. package/types/EphemeralKeys.d.ts +40 -0
  421. package/types/EphemeralKeysResource.d.ts +65 -0
  422. package/types/Errors.d.ts +356 -0
  423. package/types/EventTypes.d.ts +4443 -0
  424. package/types/Events.d.ts +373 -0
  425. package/types/EventsResource.d.ts +63 -0
  426. package/types/ExchangeRates.d.ts +54 -0
  427. package/types/ExchangeRatesResource.d.ts +49 -0
  428. package/types/ExternalAccounts.d.ts +9 -0
  429. package/types/FeeRefunds.d.ts +54 -0
  430. package/types/FileLinks.d.ts +57 -0
  431. package/types/FileLinksResource.d.ts +114 -0
  432. package/types/Files.d.ts +96 -0
  433. package/types/FilesResource.d.ts +146 -0
  434. package/types/FinancialConnections/AccountOwners.d.ts +52 -0
  435. package/types/FinancialConnections/AccountOwnerships.d.ts +32 -0
  436. package/types/FinancialConnections/Accounts.d.ts +325 -0
  437. package/types/FinancialConnections/AccountsResource.d.ts +184 -0
  438. package/types/FinancialConnections/Sessions.d.ts +113 -0
  439. package/types/FinancialConnections/SessionsResource.d.ts +128 -0
  440. package/types/FinancialConnections/Transactions.d.ts +85 -0
  441. package/types/FinancialConnections/TransactionsResource.d.ts +68 -0
  442. package/types/Forwarding/Requests.d.ts +165 -0
  443. package/types/Forwarding/RequestsResource.d.ts +127 -0
  444. package/types/FundingInstructions.d.ts +297 -0
  445. package/types/Identity/VerificationReports.d.ts +487 -0
  446. package/types/Identity/VerificationReportsResource.d.ts +71 -0
  447. package/types/Identity/VerificationSessions.d.ts +352 -0
  448. package/types/Identity/VerificationSessionsResource.d.ts +366 -0
  449. package/types/InvoiceItems.d.ts +240 -0
  450. package/types/InvoiceItemsResource.d.ts +424 -0
  451. package/types/InvoiceLineItems.d.ts +366 -0
  452. package/types/InvoicePayments.d.ts +111 -0
  453. package/types/InvoicePaymentsResource.d.ts +88 -0
  454. package/types/InvoiceRenderingTemplates.d.ts +55 -0
  455. package/types/InvoiceRenderingTemplatesResource.d.ts +93 -0
  456. package/types/Invoices.d.ts +1650 -0
  457. package/types/InvoicesResource.d.ts +4196 -0
  458. package/types/Issuing/Authorizations.d.ts +689 -0
  459. package/types/Issuing/AuthorizationsResource.d.ts +151 -0
  460. package/types/Issuing/Cardholders.d.ts +1184 -0
  461. package/types/Issuing/CardholdersResource.d.ts +2411 -0
  462. package/types/Issuing/Cards.d.ts +1312 -0
  463. package/types/Issuing/CardsResource.d.ts +2371 -0
  464. package/types/Issuing/Disputes.d.ts +383 -0
  465. package/types/Issuing/DisputesResource.d.ts +776 -0
  466. package/types/Issuing/PersonalizationDesigns.d.ts +142 -0
  467. package/types/Issuing/PersonalizationDesignsResource.d.ts +253 -0
  468. package/types/Issuing/PhysicalBundles.d.ts +75 -0
  469. package/types/Issuing/PhysicalBundlesResource.d.ts +63 -0
  470. package/types/Issuing/Tokens.d.ts +273 -0
  471. package/types/Issuing/TokensResource.d.ts +88 -0
  472. package/types/Issuing/Transactions.d.ts +479 -0
  473. package/types/Issuing/TransactionsResource.d.ts +92 -0
  474. package/types/LineItems.d.ts +145 -0
  475. package/types/LoginLinks.d.ts +26 -0
  476. package/types/Mandates.d.ts +373 -0
  477. package/types/MandatesResource.d.ts +27 -0
  478. package/types/OAuth.d.ts +355 -0
  479. package/types/PaymentAttemptRecords.d.ts +2438 -0
  480. package/types/PaymentAttemptRecordsResource.d.ts +57 -0
  481. package/types/PaymentIntentAmountDetailsLineItems.d.ts +126 -0
  482. package/types/PaymentIntents.d.ts +3162 -0
  483. package/types/PaymentIntentsResource.d.ts +11473 -0
  484. package/types/PaymentLinks.d.ts +1051 -0
  485. package/types/PaymentLinksResource.d.ts +2334 -0
  486. package/types/PaymentMethodConfigurations.d.ts +2045 -0
  487. package/types/PaymentMethodConfigurationsResource.d.ts +2958 -0
  488. package/types/PaymentMethodDomains.d.ts +213 -0
  489. package/types/PaymentMethodDomainsResource.d.ts +126 -0
  490. package/types/PaymentMethods.d.ts +1645 -0
  491. package/types/PaymentMethodsResource.d.ts +1223 -0
  492. package/types/PaymentRecords.d.ts +2438 -0
  493. package/types/PaymentRecordsResource.d.ts +657 -0
  494. package/types/Payouts.d.ts +177 -0
  495. package/types/PayoutsResource.d.ts +201 -0
  496. package/types/Persons.d.ts +824 -0
  497. package/types/Plans.d.ts +195 -0
  498. package/types/PlansResource.d.ts +303 -0
  499. package/types/Prices.d.ts +325 -0
  500. package/types/PricesResource.d.ts +607 -0
  501. package/types/ProductFeatures.d.ts +57 -0
  502. package/types/Products.d.ts +170 -0
  503. package/types/ProductsResource.d.ts +616 -0
  504. package/types/PromotionCodes.d.ts +125 -0
  505. package/types/PromotionCodesResource.d.ts +233 -0
  506. package/types/Quotes.d.ts +690 -0
  507. package/types/QuotesResource.d.ts +898 -0
  508. package/types/Radar/EarlyFraudWarnings.d.ts +55 -0
  509. package/types/Radar/EarlyFraudWarningsResource.d.ts +64 -0
  510. package/types/Radar/PaymentEvaluations.d.ts +580 -0
  511. package/types/Radar/PaymentEvaluationsResource.d.ts +208 -0
  512. package/types/Radar/ValueListItems.d.ts +74 -0
  513. package/types/Radar/ValueListItemsResource.d.ts +99 -0
  514. package/types/Radar/ValueLists.d.ts +104 -0
  515. package/types/Radar/ValueListsResource.d.ts +156 -0
  516. package/types/Refunds.d.ts +487 -0
  517. package/types/RefundsResource.d.ts +187 -0
  518. package/types/Reporting/ReportRuns.d.ts +115 -0
  519. package/types/Reporting/ReportRunsResource.d.ts +763 -0
  520. package/types/Reporting/ReportTypes.d.ts +64 -0
  521. package/types/Reporting/ReportTypesResource.d.ts +47 -0
  522. package/types/Reserve/Holds.d.ts +104 -0
  523. package/types/Reserve/Plans.d.ts +103 -0
  524. package/types/Reserve/Releases.d.ts +105 -0
  525. package/types/ReserveTransactions.d.ts +32 -0
  526. package/types/Reviews.d.ts +146 -0
  527. package/types/ReviewsResource.d.ts +68 -0
  528. package/types/SetupAttempts.d.ts +878 -0
  529. package/types/SetupAttemptsResource.d.ts +35 -0
  530. package/types/SetupIntents.d.ts +1105 -0
  531. package/types/SetupIntentsResource.d.ts +5251 -0
  532. package/types/ShippingRates.d.ts +155 -0
  533. package/types/ShippingRatesResource.d.ts +262 -0
  534. package/types/Sigma/ScheduledQueryRuns.d.ts +76 -0
  535. package/types/Sigma/ScheduledQueryRunsResource.d.ts +47 -0
  536. package/types/SourceMandateNotifications.d.ts +105 -0
  537. package/types/SourceTransactions.d.ts +203 -0
  538. package/types/Sources.d.ts +746 -0
  539. package/types/SourcesResource.d.ts +611 -0
  540. package/types/SubscriptionItems.d.ts +122 -0
  541. package/types/SubscriptionItemsResource.d.ts +441 -0
  542. package/types/SubscriptionSchedules.d.ts +687 -0
  543. package/types/SubscriptionSchedulesResource.d.ts +1565 -0
  544. package/types/Subscriptions.d.ts +852 -0
  545. package/types/SubscriptionsResource.d.ts +2326 -0
  546. package/types/Tax/Associations.d.ts +82 -0
  547. package/types/Tax/AssociationsResource.d.ts +29 -0
  548. package/types/Tax/CalculationLineItems.d.ts +187 -0
  549. package/types/Tax/Calculations.d.ts +511 -0
  550. package/types/Tax/CalculationsResource.d.ts +406 -0
  551. package/types/Tax/Registrations.d.ts +1710 -0
  552. package/types/Tax/RegistrationsResource.d.ts +2583 -0
  553. package/types/Tax/Settings.d.ts +86 -0
  554. package/types/Tax/SettingsResource.d.ts +77 -0
  555. package/types/Tax/TransactionLineItems.d.ts +90 -0
  556. package/types/Tax/Transactions.d.ts +418 -0
  557. package/types/Tax/TransactionsResource.d.ts +182 -0
  558. package/types/TaxCodes.d.ts +30 -0
  559. package/types/TaxCodesResource.d.ts +43 -0
  560. package/types/TaxDeductedAtSources.d.ts +35 -0
  561. package/types/TaxIds.d.ts +262 -0
  562. package/types/TaxIdsResource.d.ts +263 -0
  563. package/types/TaxRates.d.ts +144 -0
  564. package/types/TaxRatesResource.d.ts +215 -0
  565. package/types/Terminal/Configurations.d.ts +630 -0
  566. package/types/Terminal/ConfigurationsResource.d.ts +1469 -0
  567. package/types/Terminal/ConnectionTokens.d.ts +29 -0
  568. package/types/Terminal/ConnectionTokensResource.d.ts +32 -0
  569. package/types/Terminal/Locations.d.ts +166 -0
  570. package/types/Terminal/LocationsResource.d.ts +233 -0
  571. package/types/Terminal/OnboardingLinks.d.ts +57 -0
  572. package/types/Terminal/OnboardingLinksResource.d.ts +62 -0
  573. package/types/Terminal/Readers.d.ts +676 -0
  574. package/types/Terminal/ReadersResource.d.ts +665 -0
  575. package/types/TestHelpers/ConfirmationTokensResource.d.ts +936 -0
  576. package/types/TestHelpers/CustomersResource.d.ts +40 -0
  577. package/types/TestHelpers/Issuing/AuthorizationsResource.d.ts +1404 -0
  578. package/types/TestHelpers/Issuing/CardsResource.d.ts +121 -0
  579. package/types/TestHelpers/Issuing/PersonalizationDesignsResource.d.ts +113 -0
  580. package/types/TestHelpers/Issuing/TransactionsResource.d.ts +1354 -0
  581. package/types/TestHelpers/RefundsResource.d.ts +29 -0
  582. package/types/TestHelpers/Terminal/ReadersResource.d.ts +151 -0
  583. package/types/TestHelpers/TestClocks.d.ts +98 -0
  584. package/types/TestHelpers/TestClocksResource.d.ts +108 -0
  585. package/types/TestHelpers/Treasury/InboundTransfersResource.d.ts +108 -0
  586. package/types/TestHelpers/Treasury/OutboundPaymentsResource.d.ts +175 -0
  587. package/types/TestHelpers/Treasury/OutboundTransfersResource.d.ts +175 -0
  588. package/types/TestHelpers/Treasury/ReceivedCreditsResource.d.ts +93 -0
  589. package/types/TestHelpers/Treasury/ReceivedDebitsResource.d.ts +91 -0
  590. package/types/Tokens.d.ts +84 -0
  591. package/types/TokensResource.d.ts +1086 -0
  592. package/types/Topups.d.ts +103 -0
  593. package/types/TopupsResource.d.ts +158 -0
  594. package/types/TransferReversals.d.ts +72 -0
  595. package/types/Transfers.d.ts +104 -0
  596. package/types/TransfersResource.d.ts +260 -0
  597. package/types/Treasury/CreditReversals.d.ts +92 -0
  598. package/types/Treasury/CreditReversalsResource.d.ts +88 -0
  599. package/types/Treasury/DebitReversals.d.ts +104 -0
  600. package/types/Treasury/DebitReversalsResource.d.ts +95 -0
  601. package/types/Treasury/FinancialAccountFeatures.d.ts +623 -0
  602. package/types/Treasury/FinancialAccounts.d.ts +250 -0
  603. package/types/Treasury/FinancialAccountsResource.d.ts +733 -0
  604. package/types/Treasury/InboundTransfers.d.ts +235 -0
  605. package/types/Treasury/InboundTransfersResource.d.ts +128 -0
  606. package/types/Treasury/OutboundPayments.d.ts +324 -0
  607. package/types/Treasury/OutboundPaymentsResource.d.ts +285 -0
  608. package/types/Treasury/OutboundTransfers.d.ts +299 -0
  609. package/types/Treasury/OutboundTransfersResource.d.ts +179 -0
  610. package/types/Treasury/ReceivedCredits.d.ts +279 -0
  611. package/types/Treasury/ReceivedCreditsResource.d.ts +79 -0
  612. package/types/Treasury/ReceivedDebits.d.ts +227 -0
  613. package/types/Treasury/ReceivedDebitsResource.d.ts +58 -0
  614. package/types/Treasury/TransactionEntries.d.ts +203 -0
  615. package/types/Treasury/TransactionEntriesResource.d.ts +70 -0
  616. package/types/Treasury/Transactions.d.ts +202 -0
  617. package/types/Treasury/TransactionsResource.d.ts +82 -0
  618. package/types/UpcomingInvoices.d.ts +5 -0
  619. package/types/V2/Billing/MeterEventAdjustments.d.ts +65 -0
  620. package/types/V2/Billing/MeterEventAdjustmentsResource.d.ts +47 -0
  621. package/types/V2/Billing/MeterEventSessionResource.d.ts +26 -0
  622. package/types/V2/Billing/MeterEventSessions.d.ts +45 -0
  623. package/types/V2/Billing/MeterEventStreamResource.d.ts +62 -0
  624. package/types/V2/Billing/MeterEvents.d.ts +55 -0
  625. package/types/V2/Billing/MeterEventsResource.d.ts +52 -0
  626. package/types/V2/Core/AccountLinks.d.ts +160 -0
  627. package/types/V2/Core/AccountLinksResource.d.ts +145 -0
  628. package/types/V2/Core/AccountPersonTokens.d.ts +44 -0
  629. package/types/V2/Core/AccountPersons.d.ts +661 -0
  630. package/types/V2/Core/AccountTokens.d.ts +44 -0
  631. package/types/V2/Core/AccountTokensResource.d.ts +1149 -0
  632. package/types/V2/Core/Accounts/PersonTokensResource.d.ts +556 -0
  633. package/types/V2/Core/Accounts/PersonsResource.d.ts +1260 -0
  634. package/types/V2/Core/Accounts.d.ts +5422 -0
  635. package/types/V2/Core/AccountsResource.d.ts +5042 -0
  636. package/types/V2/Core/EventDestinations.d.ts +168 -0
  637. package/types/V2/Core/EventDestinationsResource.d.ts +278 -0
  638. package/types/V2/Core/EventTypes.d.ts +798 -0
  639. package/types/V2/Core/Events.d.ts +86 -0
  640. package/types/V2/Core/EventsResource.d.ts +63 -0
  641. package/types/V2/DeletedObject.d.ts +22 -0
  642. package/types/V2/EventMisc.d.ts +80 -0
  643. package/types/WebhookEndpoints.d.ts +101 -0
  644. package/types/WebhookEndpointsResource.d.ts +798 -0
  645. package/types/Webhooks.d.ts +164 -0
  646. package/types/apiVersion.d.ts +4 -0
  647. package/types/crypto/crypto.d.ts +59 -0
  648. package/types/index.d.ts +596 -0
  649. package/types/lib.d.ts +420 -0
  650. package/types/net/net.d.ts +99 -0
  651. package/types/shared.d.ts +178 -0
  652. package/types/test/.eslintrc.js +6 -0
  653. package/types/test/tsconfig.json +67 -0
  654. package/types/test/typescriptTest.ts +357 -0
package/esm/Decimal.js ADDED
@@ -0,0 +1,850 @@
1
+ /**
2
+ * Maps built-in preset names to their {@link DecimalRoundingOptions}.
3
+ * Used internally by {@link DecimalImpl.round}.
4
+ *
5
+ * @internal
6
+ */
7
+ const ROUNDING_PRESETS = {
8
+ 'ubb-usage-count': { mode: 'significant-figures', value: 15 },
9
+ 'v1-api': { mode: 'decimal-places', value: 12 },
10
+ };
11
+ /**
12
+ * The IEEE 754 decimal128 coefficient size (34 digits) — the recommended
13
+ * precision for {@link DecimalImpl.div} when full precision is desired.
14
+ *
15
+ * @remarks
16
+ * Pass this as the `precision` argument to `div()` when you want the
17
+ * maximum available precision. Division requires explicit precision —
18
+ * no invisible defaults in financial code.
19
+ *
20
+ * @example
21
+ * ```ts
22
+ * // Use the full decimal128 precision explicitly
23
+ * a.div(b, DEFAULT_DIV_PRECISION, 'half-even');
24
+ * ```
25
+ *
26
+ * @public
27
+ */
28
+ export const DEFAULT_DIV_PRECISION = 34;
29
+ /**
30
+ * Maximum number of digits in plain (non-exponential) notation produced
31
+ * by {@link DecimalImpl.toString}. Values exceeding this threshold are
32
+ * emitted in scientific notation (`1.23E+40`).
33
+ *
34
+ * @internal
35
+ */
36
+ const PLAIN_NOTATION_DIGIT_LIMIT = 30;
37
+ /**
38
+ * Maximum absolute value for the internal exponent.
39
+ *
40
+ * @remarks
41
+ * This bound also implicitly limits exponent differences used in
42
+ * arithmetic (e.g., scaling by `10^exponentDiff`), preventing
43
+ * astronomically large BigInt allocations that could hang or
44
+ * exhaust the process.
45
+ *
46
+ * The chosen limit is intentionally conservative but still far beyond
47
+ * any magnitude needed for typical financial or billing calculations.
48
+ *
49
+ * @internal
50
+ */
51
+ const MAX_EXPONENT = 1000000;
52
+ /**
53
+ * Internal implementation of arbitrary-precision decimal arithmetic.
54
+ *
55
+ * @remarks
56
+ * Represents a decimal value as `coefficient × 10^exponent` using
57
+ * native `BigInt` for the coefficient, giving unlimited precision with
58
+ * no rounding on construction. Instances are always
59
+ * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/freeze | frozen}
60
+ * and all arithmetic produces new instances.
61
+ *
62
+ * This class is **not** exported directly — consumers interact with
63
+ * the branded {@link Decimal} type and the {@link Decimal | Decimal companion object}.
64
+ *
65
+ * @internal
66
+ */
67
+ class DecimalImpl {
68
+ /**
69
+ * Construct and normalise a decimal value.
70
+ *
71
+ * @param coefficient - The unscaled integer value.
72
+ * @param exponent - The power-of-ten scale factor.
73
+ *
74
+ * @internal
75
+ */
76
+ constructor(coefficient, exponent) {
77
+ const [normalizedCoef, normalizedExp] = DecimalImpl.normalize(coefficient, exponent);
78
+ this._coefficient = normalizedCoef;
79
+ this._exponent = normalizedExp;
80
+ Object.freeze(this);
81
+ }
82
+ /**
83
+ * Strip trailing zeros from `coefficient`, incrementing `exponent`
84
+ * for each zero removed. Zero always normalises to `(0n, 0)`.
85
+ *
86
+ * @param coefficient - Raw coefficient before normalisation.
87
+ * @param exponent - Raw exponent before normalisation.
88
+ * @returns A `[coefficient, exponent]` tuple with trailing zeros removed.
89
+ *
90
+ * @internal
91
+ */
92
+ static normalize(coefficient, exponent) {
93
+ if (coefficient === 0n) {
94
+ return [0n, 0];
95
+ }
96
+ let coef = coefficient;
97
+ let exp = exponent;
98
+ while (coef !== 0n && coef % 10n === 0n) {
99
+ coef /= 10n;
100
+ exp += 1;
101
+ }
102
+ return [coef, exp];
103
+ }
104
+ /**
105
+ * Apply rounding to the result of an integer division.
106
+ *
107
+ * @remarks
108
+ * BigInt division truncates toward zero. This helper inspects the
109
+ * `remainder` to decide whether to adjust the truncated `quotient`
110
+ * by ±1 according to the chosen {@link RoundDirection}.
111
+ *
112
+ * The rounding direction is derived from the signs of `remainder`
113
+ * and `divisor`: when they agree the exact fractional part is
114
+ * positive (the truncation point is below the true value, so +1
115
+ * rounds to nearest); when they disagree the fractional part is
116
+ * negative (−1 rounds to nearest).
117
+ *
118
+ * @param quotient - Truncated integer quotient (`dividend / divisor`).
119
+ * @param remainder - Division remainder (`dividend % divisor`).
120
+ * @param divisor - The divisor used in the division.
121
+ * @param direction - The rounding strategy to apply.
122
+ * @returns The rounded quotient.
123
+ *
124
+ * @internal
125
+ */
126
+ static roundDivision(quotient, remainder, divisor, direction) {
127
+ if (remainder === 0n) {
128
+ return quotient;
129
+ }
130
+ // 'round-down': truncate toward zero — BigInt division already does this.
131
+ if (direction === 'round-down') {
132
+ return quotient;
133
+ }
134
+ // The sign of remainder/divisor tells us which side of the truncation
135
+ // point the exact value lies on.
136
+ // Same sign → fractional part is positive (exact value > quotient) → +1 adjusts upward.
137
+ // Opposite sign → fractional part is negative (exact value < quotient) → -1 adjusts downward.
138
+ const roundDir = remainder > 0n === divisor > 0n ? 1n : -1n;
139
+ // 'round-up': away from zero whenever there is any remainder.
140
+ if (direction === 'round-up') {
141
+ return quotient + roundDir;
142
+ }
143
+ // 'ceil': toward positive infinity.
144
+ // If the fractional part is positive (roundDir === 1n), round up.
145
+ // If the fractional part is negative (roundDir === -1n), truncation already went toward +∞.
146
+ if (direction === 'ceil') {
147
+ return roundDir === 1n ? quotient + 1n : quotient;
148
+ }
149
+ // 'floor': toward negative infinity.
150
+ // If the fractional part is negative (roundDir === -1n), round down.
151
+ // If the fractional part is positive (roundDir === 1n), truncation already went toward -∞.
152
+ if (direction === 'floor') {
153
+ return roundDir === -1n ? quotient - 1n : quotient;
154
+ }
155
+ // For the half-* modes we need to compare the remainder to exactly half the divisor.
156
+ const absRemainder = remainder < 0n ? -remainder : remainder;
157
+ const absDivisor = divisor < 0n ? -divisor : divisor;
158
+ const doubled = absRemainder * 2n;
159
+ let cmp;
160
+ if (doubled === absDivisor) {
161
+ cmp = 0;
162
+ }
163
+ else if (doubled < absDivisor) {
164
+ cmp = -1;
165
+ }
166
+ else {
167
+ cmp = 1;
168
+ }
169
+ if (cmp < 0) {
170
+ // Less than half — truncation is already the nearest value.
171
+ return quotient;
172
+ }
173
+ if (cmp > 0) {
174
+ // More than half — round to nearest (away from truncation point).
175
+ return quotient + roundDir;
176
+ }
177
+ // Exactly half — tie-breaking depends on the chosen mode.
178
+ if (direction === 'half-up') {
179
+ // Round away from zero.
180
+ return quotient + roundDir;
181
+ }
182
+ if (direction === 'half-down') {
183
+ // Round toward zero — stay at the truncated quotient.
184
+ return quotient;
185
+ }
186
+ // HALF_EVEN: round to nearest even.
187
+ if (quotient % 2n === 0n) {
188
+ // Already even — stay at truncation.
189
+ return quotient;
190
+ }
191
+ else {
192
+ // Odd — adjust to make even.
193
+ return quotient + roundDir;
194
+ }
195
+ }
196
+ // -------------------------------------------------------------------
197
+ // Arithmetic
198
+ // -------------------------------------------------------------------
199
+ /**
200
+ * Return the sum of this value and `other`.
201
+ *
202
+ * @param other - The addend.
203
+ * @returns A new {@link Decimal} equal to `this + other`.
204
+ *
205
+ * @public
206
+ */
207
+ add(other) {
208
+ const otherImpl = other;
209
+ // Align exponents — use the smaller (more precision) exponent as target.
210
+ if (this._exponent === otherImpl._exponent) {
211
+ return new DecimalImpl(this._coefficient + otherImpl._coefficient, this._exponent);
212
+ }
213
+ if (this._exponent < otherImpl._exponent) {
214
+ const scale = 10n ** BigInt(otherImpl._exponent - this._exponent);
215
+ return new DecimalImpl(this._coefficient + otherImpl._coefficient * scale, this._exponent);
216
+ }
217
+ else {
218
+ const scale = 10n ** BigInt(this._exponent - otherImpl._exponent);
219
+ return new DecimalImpl(this._coefficient * scale + otherImpl._coefficient, otherImpl._exponent);
220
+ }
221
+ }
222
+ /**
223
+ * Return the difference of this value and `other`.
224
+ *
225
+ * @param other - The subtrahend.
226
+ * @returns A new {@link Decimal} equal to `this - other`.
227
+ *
228
+ * @public
229
+ */
230
+ sub(other) {
231
+ const otherImpl = other;
232
+ if (this._exponent === otherImpl._exponent) {
233
+ return new DecimalImpl(this._coefficient - otherImpl._coefficient, this._exponent);
234
+ }
235
+ if (this._exponent < otherImpl._exponent) {
236
+ const scale = 10n ** BigInt(otherImpl._exponent - this._exponent);
237
+ return new DecimalImpl(this._coefficient - otherImpl._coefficient * scale, this._exponent);
238
+ }
239
+ else {
240
+ const scale = 10n ** BigInt(this._exponent - otherImpl._exponent);
241
+ return new DecimalImpl(this._coefficient * scale - otherImpl._coefficient, otherImpl._exponent);
242
+ }
243
+ }
244
+ /**
245
+ * Return the product of this value and `other`.
246
+ *
247
+ * @param other - The multiplicand.
248
+ * @returns A new {@link Decimal} equal to `this × other`.
249
+ *
250
+ * @public
251
+ */
252
+ mul(other) {
253
+ const otherImpl = other;
254
+ return new DecimalImpl(this._coefficient * otherImpl._coefficient, this._exponent + otherImpl._exponent);
255
+ }
256
+ /**
257
+ * Return the quotient of this value divided by `other`.
258
+ *
259
+ * @remarks
260
+ * Division scales the dividend to produce `precision` decimal digits
261
+ * in the result, then applies integer division and rounds the
262
+ * remainder according to `direction`.
263
+ *
264
+ * Division requires explicit rounding control — no invisible defaults
265
+ * in financial code. For full precision use {@link DEFAULT_DIV_PRECISION}
266
+ * (34, matching the IEEE 754 decimal128 coefficient size).
267
+ *
268
+ * @example
269
+ * ```ts
270
+ * Decimal.from('1').div(Decimal.from('3'), 5, 'half-up'); // "0.33333"
271
+ * Decimal.from('5').div(Decimal.from('2'), 0, 'half-up'); // "3"
272
+ * Decimal.from('5').div(Decimal.from('2'), 0, 'half-even'); // "2"
273
+ * ```
274
+ *
275
+ * @param other - The divisor. Must not be zero.
276
+ * @param precision - Maximum number of decimal digits in the result.
277
+ * @param direction - How to round when the exact quotient cannot
278
+ * be represented at the requested precision.
279
+ * @returns A new {@link Decimal} equal to `this ÷ other`, rounded to
280
+ * `precision` decimal places.
281
+ * @throws {@link Error} if `other` is zero.
282
+ * @throws {@link Error} if `precision` is negative or non-integer.
283
+ *
284
+ * @public
285
+ */
286
+ div(other, precision, direction) {
287
+ if (precision < 0 || !Number.isInteger(precision)) {
288
+ throw new Error('precision must be a non-negative integer');
289
+ }
290
+ const otherImpl = other;
291
+ if (otherImpl._coefficient === 0n) {
292
+ throw new Error('Division by zero');
293
+ }
294
+ // result_coefficient = this.coefficient × 10^(thisExp - otherExp + precision) / other.coefficient
295
+ // result_exponent = -precision
296
+ const scale = this._exponent - otherImpl._exponent + precision;
297
+ let quotient;
298
+ let remainder;
299
+ let roundingDivisor;
300
+ if (scale >= 0) {
301
+ const scaledDividend = this._coefficient * 10n ** BigInt(scale);
302
+ quotient = scaledDividend / otherImpl._coefficient;
303
+ remainder = scaledDividend % otherImpl._coefficient;
304
+ roundingDivisor = otherImpl._coefficient;
305
+ }
306
+ else {
307
+ // Negative scale: shift the power onto the divisor side to avoid
308
+ // BigInt exponentiation with a negative exponent (which throws).
309
+ const scaledDivisor = otherImpl._coefficient * 10n ** BigInt(-scale);
310
+ quotient = this._coefficient / scaledDivisor;
311
+ remainder = this._coefficient % scaledDivisor;
312
+ roundingDivisor = scaledDivisor;
313
+ }
314
+ const roundedQuotient = DecimalImpl.roundDivision(quotient, remainder, roundingDivisor, direction);
315
+ return new DecimalImpl(roundedQuotient, -precision);
316
+ }
317
+ // -------------------------------------------------------------------
318
+ // Comparison
319
+ // -------------------------------------------------------------------
320
+ /**
321
+ * Three-way comparison of this value with `other`.
322
+ *
323
+ * @example
324
+ * ```ts
325
+ * const a = Decimal.from('1.5');
326
+ * const b = Decimal.from('2');
327
+ * a.cmp(b); // -1
328
+ * b.cmp(a); // 1
329
+ * a.cmp(a); // 0
330
+ * ```
331
+ *
332
+ * @param other - The value to compare against.
333
+ * @returns `-1` if `this \< other`, `0` if equal, `1` if `this \> other`.
334
+ *
335
+ * @public
336
+ */
337
+ cmp(other) {
338
+ const otherImpl = other;
339
+ if (this._exponent === otherImpl._exponent) {
340
+ if (this._coefficient < otherImpl._coefficient)
341
+ return -1;
342
+ if (this._coefficient > otherImpl._coefficient)
343
+ return 1;
344
+ return 0;
345
+ }
346
+ if (this._exponent < otherImpl._exponent) {
347
+ // this has smaller exponent — scale other's coefficient to match.
348
+ const scale = 10n ** BigInt(otherImpl._exponent - this._exponent);
349
+ const scaledOther = otherImpl._coefficient * scale;
350
+ if (this._coefficient < scaledOther)
351
+ return -1;
352
+ if (this._coefficient > scaledOther)
353
+ return 1;
354
+ return 0;
355
+ }
356
+ else {
357
+ // other has smaller exponent — scale this's coefficient to match.
358
+ const scale = 10n ** BigInt(this._exponent - otherImpl._exponent);
359
+ const scaledThis = this._coefficient * scale;
360
+ if (scaledThis < otherImpl._coefficient)
361
+ return -1;
362
+ if (scaledThis > otherImpl._coefficient)
363
+ return 1;
364
+ return 0;
365
+ }
366
+ }
367
+ /**
368
+ * Return `true` if this value is numerically equal to `other`.
369
+ *
370
+ * @param other - The value to compare against.
371
+ * @returns `true` if `this === other` in value, `false` otherwise.
372
+ *
373
+ * @public
374
+ */
375
+ eq(other) {
376
+ return this.cmp(other) === 0;
377
+ }
378
+ /**
379
+ * Return `true` if this value is strictly less than `other`.
380
+ *
381
+ * @param other - The value to compare against.
382
+ * @returns `true` if `this \< other`, `false` otherwise.
383
+ *
384
+ * @public
385
+ */
386
+ lt(other) {
387
+ return this.cmp(other) === -1;
388
+ }
389
+ /**
390
+ * Return `true` if this value is less than or equal to `other`.
391
+ *
392
+ * @param other - The value to compare against.
393
+ * @returns `true` if `this ≤ other`, `false` otherwise.
394
+ *
395
+ * @public
396
+ */
397
+ lte(other) {
398
+ return this.cmp(other) <= 0;
399
+ }
400
+ /**
401
+ * Return `true` if this value is strictly greater than `other`.
402
+ *
403
+ * @param other - The value to compare against.
404
+ * @returns `true` if `this \> other`, `false` otherwise.
405
+ *
406
+ * @public
407
+ */
408
+ gt(other) {
409
+ return this.cmp(other) === 1;
410
+ }
411
+ /**
412
+ * Return `true` if this value is greater than or equal to `other`.
413
+ *
414
+ * @param other - The value to compare against.
415
+ * @returns `true` if `this ≥ other`, `false` otherwise.
416
+ *
417
+ * @public
418
+ */
419
+ gte(other) {
420
+ return this.cmp(other) >= 0;
421
+ }
422
+ // -------------------------------------------------------------------
423
+ // Predicates
424
+ // -------------------------------------------------------------------
425
+ /**
426
+ * Return `true` if this value is exactly zero.
427
+ *
428
+ * @returns `true` if the value is zero, `false` otherwise.
429
+ *
430
+ * @public
431
+ */
432
+ isZero() {
433
+ return this._coefficient === 0n;
434
+ }
435
+ /**
436
+ * Return `true` if this value is strictly less than zero.
437
+ *
438
+ * @returns `true` if negative, `false` if zero or positive.
439
+ *
440
+ * @public
441
+ */
442
+ isNegative() {
443
+ return this._coefficient < 0n;
444
+ }
445
+ /**
446
+ * Return `true` if this value is strictly greater than zero.
447
+ *
448
+ * @returns `true` if positive, `false` if zero or negative.
449
+ *
450
+ * @public
451
+ */
452
+ isPositive() {
453
+ return this._coefficient > 0n;
454
+ }
455
+ // -------------------------------------------------------------------
456
+ // Unary operations
457
+ // -------------------------------------------------------------------
458
+ /**
459
+ * Return the additive inverse of this value.
460
+ *
461
+ * @returns A new {@link Decimal} equal to `-this`.
462
+ *
463
+ * @public
464
+ */
465
+ neg() {
466
+ return new DecimalImpl(-this._coefficient, this._exponent);
467
+ }
468
+ /**
469
+ * Return the absolute value.
470
+ *
471
+ * @returns A new {@link Decimal} equal to `|this|`. If this value is
472
+ * already non-negative, returns `this` (no allocation).
473
+ *
474
+ * @public
475
+ */
476
+ abs() {
477
+ if (this._coefficient < 0n) {
478
+ return new DecimalImpl(-this._coefficient, this._exponent);
479
+ }
480
+ return this;
481
+ }
482
+ // -------------------------------------------------------------------
483
+ // Rounding
484
+ // -------------------------------------------------------------------
485
+ /**
486
+ * Round this value to a specified precision.
487
+ *
488
+ * @remarks
489
+ * **Rounding directions** (IEEE 754-2019 §4.3):
490
+ *
491
+ * | Direction | Behavior |
492
+ * | -------------- | ---------------------------------------------- |
493
+ * | `'ceil'` | 1.1→2, -1.1→-1, 1.0→1 (toward +∞) |
494
+ * | `'floor'` | 1.9→1, -1.1→-2, 1.0→1 (toward -∞) |
495
+ * | `'round-down'` | 1.9→1, -1.9→-1 (toward zero / truncate) |
496
+ * | `'round-up'` | 1.1→2, -1.1→-2 (away from zero) |
497
+ * | `'half-up'` | 0.5→1, 1.5→2, -0.5→-1 (ties away from zero) |
498
+ * | `'half-down'` | 0.5→0, 1.5→1, -0.5→0 (ties toward zero) |
499
+ * | `'half-even'` | 0.5→0, 1.5→2, 2.5→2, 3.5→4 (ties to even) |
500
+ *
501
+ * **Precision** is specified as a {@link DecimalRoundingOptions} object
502
+ * or a preset name from {@link DecimalRoundingPresets}:
503
+ *
504
+ * @example
505
+ * ```ts
506
+ * // Using a preset
507
+ * amount.round('half-even', 'v1-api');
508
+ *
509
+ * // Using explicit options
510
+ * amount.round('half-even', { mode: 'decimal-places', value: 2 });
511
+ * amount.round('half-up', { mode: 'significant-figures', value: 4 });
512
+ * ```
513
+ *
514
+ * @param direction - How to round.
515
+ * @param options - A {@link DecimalRoundingOptions} object or key of {@link DecimalRoundingPresets}.
516
+ * @returns A new {@link Decimal} rounded to the specified precision.
517
+ * @throws {@link Error} if `options.value` is negative or non-integer.
518
+ * @throws {@link Error} if the preset name is not recognized.
519
+ *
520
+ * @public
521
+ */
522
+ round(direction, options) {
523
+ const resolved = typeof options === 'string'
524
+ ? // Declaration merging allows consumers to add keys at compile time, but
525
+ // ROUNDING_PRESETS only knows about built-in keys at runtime. The double
526
+ // cast through `unknown` is intentional: we want an undefined-safe lookup
527
+ // so the runtime guard below can produce a clear error for unrecognised
528
+ // (e.g. declaration-merged) preset names that were not also added to
529
+ // ROUNDING_PRESETS.
530
+ ROUNDING_PRESETS[options]
531
+ : options;
532
+ if (resolved === undefined) {
533
+ throw new Error(`Unknown rounding preset: "${options}"`);
534
+ }
535
+ if (resolved.value < 0 || !Number.isInteger(resolved.value)) {
536
+ throw new Error('DecimalRoundingOptions.value must be a non-negative integer');
537
+ }
538
+ if (resolved.mode === 'decimal-places') {
539
+ // Reuse toFixed logic: round to resolved.value decimal places then re-parse.
540
+ const fixed = this.toFixed(resolved.value, direction);
541
+ return Decimal.from(fixed);
542
+ }
543
+ // significant-figures: round to resolved.value total significant digits.
544
+ if (this._coefficient === 0n) {
545
+ return this;
546
+ }
547
+ const coeffStr = this._coefficient < 0n
548
+ ? (-this._coefficient).toString()
549
+ : this._coefficient.toString();
550
+ const currentSigFigs = coeffStr.length;
551
+ if (resolved.value === 0) {
552
+ // 0 significant figures is a degenerate case — return zero.
553
+ return Decimal.zero;
554
+ }
555
+ if (currentSigFigs <= resolved.value) {
556
+ // Already at or below requested precision — no rounding needed.
557
+ return this;
558
+ }
559
+ // We need to reduce the number of significant figures.
560
+ // The number of digits to drop from the coefficient:
561
+ const digitsToTrim = currentSigFigs - resolved.value;
562
+ const divisor = 10n ** BigInt(digitsToTrim);
563
+ const quotient = this._coefficient / divisor;
564
+ const remainder = this._coefficient % divisor;
565
+ const rounded = DecimalImpl.roundDivision(quotient, remainder, divisor, direction);
566
+ // The new exponent shifts to account for trimmed digits.
567
+ return new DecimalImpl(rounded, this._exponent + digitsToTrim);
568
+ }
569
+ // -------------------------------------------------------------------
570
+ // Conversion / serialisation
571
+ // -------------------------------------------------------------------
572
+ /**
573
+ * Return a human-readable string representation.
574
+ *
575
+ * @remarks
576
+ * Plain notation for values whose digit count is at most 30, and
577
+ * scientific notation (`1.23E+40`) for larger values. Trailing zeros
578
+ * are never present because the internal representation is normalised.
579
+ *
580
+ * @public
581
+ */
582
+ toString() {
583
+ if (this._coefficient === 0n) {
584
+ return '0';
585
+ }
586
+ const coeffStr = this._coefficient.toString();
587
+ const isNeg = coeffStr.startsWith('-');
588
+ const absCoeffStr = isNeg ? coeffStr.slice(1) : coeffStr;
589
+ if (this._exponent < 0) {
590
+ const decimalPlaces = -this._exponent;
591
+ // Guard against unbounded string allocation for extreme negative
592
+ // exponents (e.g. 1e-1000000 would otherwise produce a million-char
593
+ // string of leading zeros). Switch to scientific notation when the
594
+ // number of leading zeros alone exceeds the digit limit. Normal
595
+ // fractional values (e.g. 34-digit division results) pass through.
596
+ const leadingZeroCount = decimalPlaces >= absCoeffStr.length
597
+ ? decimalPlaces - absCoeffStr.length
598
+ : 0;
599
+ if (leadingZeroCount > PLAIN_NOTATION_DIGIT_LIMIT) {
600
+ if (absCoeffStr.length === 1) {
601
+ return `${coeffStr}E${String(this._exponent)}`;
602
+ }
603
+ const intPart = absCoeffStr[0] ?? '';
604
+ const fracPart = absCoeffStr.slice(1);
605
+ const adjustedExp = this._exponent + absCoeffStr.length - 1;
606
+ return `${isNeg ? '-' : ''}${intPart}.${fracPart}E${String(adjustedExp)}`;
607
+ }
608
+ if (decimalPlaces >= absCoeffStr.length) {
609
+ const leadingZeros = '0'.repeat(decimalPlaces - absCoeffStr.length);
610
+ return `${isNeg ? '-' : ''}0.${leadingZeros}${absCoeffStr}`;
611
+ }
612
+ else {
613
+ const integerPart = absCoeffStr.slice(0, absCoeffStr.length - decimalPlaces);
614
+ const fractionalPart = absCoeffStr.slice(absCoeffStr.length - decimalPlaces);
615
+ return `${isNeg ? '-' : ''}${integerPart}.${fractionalPart}`;
616
+ }
617
+ }
618
+ const plainLength = absCoeffStr.length + this._exponent;
619
+ if (plainLength <= PLAIN_NOTATION_DIGIT_LIMIT) {
620
+ if (this._exponent === 0) {
621
+ return coeffStr;
622
+ }
623
+ const trailingZeros = '0'.repeat(this._exponent);
624
+ return `${isNeg ? '-' : ''}${absCoeffStr}${trailingZeros}`;
625
+ }
626
+ else {
627
+ if (absCoeffStr.length === 1) {
628
+ return `${coeffStr}E+${String(this._exponent)}`;
629
+ }
630
+ const integerPart = absCoeffStr[0] ?? '';
631
+ const fractionalPart = absCoeffStr.slice(1);
632
+ const adjustedExponent = this._exponent + absCoeffStr.length - 1;
633
+ return `${isNeg ? '-' : ''}${integerPart}.${fractionalPart}E+${String(adjustedExponent)}`;
634
+ }
635
+ }
636
+ /**
637
+ * Return the JSON-serialisable representation.
638
+ *
639
+ * @remarks
640
+ * Returns a plain string matching the Stripe API convention where
641
+ * decimal values are serialised as strings in JSON. Called
642
+ * automatically by `JSON.stringify`.
643
+ *
644
+ * @public
645
+ */
646
+ toJSON() {
647
+ return this.toString();
648
+ }
649
+ /**
650
+ * Convert to a JavaScript `number`.
651
+ *
652
+ * @remarks
653
+ * This is an explicit, intentionally lossy conversion. Use it only
654
+ * when you need a numeric value for display or interop with APIs
655
+ * that require `number`. Prefer {@link Decimal.toString | toString}
656
+ * or {@link Decimal.toFixed | toFixed} for lossless output.
657
+ *
658
+ * @public
659
+ */
660
+ toNumber() {
661
+ return Number(this.toString());
662
+ }
663
+ /**
664
+ * Format this value as a fixed-point string with exactly
665
+ * `decimalPlaces` digits after the decimal point.
666
+ *
667
+ * @remarks
668
+ * Values are rounded according to `direction` when the internal
669
+ * precision exceeds the requested number of decimal places.
670
+ * The rounding direction is always required — no invisible defaults
671
+ * in financial code.
672
+ *
673
+ * @example
674
+ * ```ts
675
+ * Decimal.from('1.235').toFixed(2, 'half-up'); // "1.24"
676
+ * Decimal.from('1.225').toFixed(2, 'half-even'); // "1.22"
677
+ * Decimal.from('42').toFixed(3, 'half-up'); // "42.000"
678
+ * ```
679
+ *
680
+ * @param decimalPlaces - Number of digits after the decimal point.
681
+ * Must be a non-negative integer.
682
+ * @param direction - How to round when truncating excess digits.
683
+ * @returns A string with exactly `decimalPlaces` fractional digits.
684
+ * @throws {@link Error} if `decimalPlaces` is negative or non-integer.
685
+ *
686
+ * @public
687
+ */
688
+ toFixed(decimalPlaces, direction) {
689
+ if (decimalPlaces < 0 || !Number.isInteger(decimalPlaces)) {
690
+ throw new Error('decimalPlaces must be a non-negative integer');
691
+ }
692
+ const formatFixed = (coef) => {
693
+ const coeffStr = coef.toString();
694
+ const isNeg = coeffStr.startsWith('-');
695
+ const absCoeffStr = isNeg ? coeffStr.slice(1) : coeffStr;
696
+ if (decimalPlaces === 0) {
697
+ return coeffStr;
698
+ }
699
+ if (decimalPlaces >= absCoeffStr.length) {
700
+ const leadingZeros = '0'.repeat(decimalPlaces - absCoeffStr.length);
701
+ return `${isNeg ? '-' : ''}0.${leadingZeros}${absCoeffStr}`;
702
+ }
703
+ else {
704
+ const integerPart = absCoeffStr.slice(0, absCoeffStr.length - decimalPlaces);
705
+ const fractionalPart = absCoeffStr.slice(absCoeffStr.length - decimalPlaces);
706
+ return `${isNeg ? '-' : ''}${integerPart}.${fractionalPart}`;
707
+ }
708
+ };
709
+ const targetExponent = -decimalPlaces;
710
+ if (this._exponent === targetExponent) {
711
+ return formatFixed(this._coefficient);
712
+ }
713
+ if (this._exponent < targetExponent) {
714
+ // Need to reduce precision — round the excess digits.
715
+ const scaleDiff = targetExponent - this._exponent;
716
+ const divisor = 10n ** BigInt(scaleDiff);
717
+ const quotient = this._coefficient / divisor;
718
+ const remainder = this._coefficient % divisor;
719
+ const rounded = DecimalImpl.roundDivision(quotient, remainder, divisor, direction);
720
+ return formatFixed(rounded);
721
+ }
722
+ else {
723
+ // Need to increase precision — pad with trailing zeros.
724
+ const scaleDiff = this._exponent - targetExponent;
725
+ const scaled = this._coefficient * 10n ** BigInt(scaleDiff);
726
+ return formatFixed(scaled);
727
+ }
728
+ }
729
+ /**
730
+ * Return a string primitive when the runtime coerces the value.
731
+ *
732
+ * @remarks
733
+ * Deliberately returns a `string` (not a `number`) to discourage
734
+ * silent precision loss through implicit arithmetic coercion.
735
+ * When used in a numeric context (for example, `+myDecimal`), the
736
+ * JavaScript runtime will first call this method and then coerce
737
+ * the resulting string to a `number`, which may lose precision.
738
+ * Callers should prefer the explicit
739
+ * {@link Decimal.toNumber | toNumber} method when an IEEE 754
740
+ * `number` is required.
741
+ *
742
+ * @public
743
+ */
744
+ valueOf() {
745
+ return this.toString();
746
+ }
747
+ }
748
+ /**
749
+ * Check whether a value is a {@link Decimal} instance.
750
+ *
751
+ * @remarks
752
+ * Use this instead of `instanceof` — the underlying class is not
753
+ * publicly exported, so `instanceof` checks are not available to
754
+ * consumers.
755
+ *
756
+ * @example
757
+ * ```ts
758
+ * if (isDecimal(value)) {
759
+ * value.add(Decimal.from('1')); // value is Decimal
760
+ * }
761
+ * ```
762
+ *
763
+ * @public
764
+ */
765
+ export function isDecimal(value) {
766
+ return value instanceof DecimalImpl;
767
+ }
768
+ /**
769
+ * Companion object for creating {@link Decimal} instances.
770
+ *
771
+ * @public
772
+ */
773
+ export const Decimal = {
774
+ /**
775
+ * Create a {@link Decimal} from a string, number, or bigint.
776
+ *
777
+ * @remarks
778
+ * - **string**: Parsed as a decimal literal. Accepts an optional sign,
779
+ * integer digits, an optional fractional part, and an optional `e`/`E`
780
+ * exponent. Leading/trailing whitespace is trimmed.
781
+ * - **number**: Must be finite. Converted via `Number.prototype.toString()`
782
+ * then parsed, so `Decimal.from(0.1)` produces `"0.1"` (not the
783
+ * 53-bit binary approximation).
784
+ * - **bigint**: Treated as an integer with exponent 0.
785
+ *
786
+ * @example
787
+ * ```ts
788
+ * Decimal.from('1.23'); // string
789
+ * Decimal.from(42); // number
790
+ * Decimal.from(100n); // bigint
791
+ * Decimal.from('1.5e3'); // scientific notation → 1500
792
+ * ```
793
+ *
794
+ * @param value - The value to convert.
795
+ * @returns A new frozen {@link Decimal} instance.
796
+ * @throws {@link Error} if `value` is a non-finite number, an empty
797
+ * string, or a string that does not match the decimal literal grammar.
798
+ *
799
+ * @public
800
+ */
801
+ from(value) {
802
+ if (typeof value === 'bigint') {
803
+ return new DecimalImpl(value, 0);
804
+ }
805
+ if (typeof value === 'number') {
806
+ if (!Number.isFinite(value)) {
807
+ throw new Error('Number must be finite');
808
+ }
809
+ return Decimal.from(value.toString());
810
+ }
811
+ // Parse string.
812
+ const trimmed = value.trim();
813
+ if (trimmed === '') {
814
+ throw new Error('Cannot parse empty string as Decimal');
815
+ }
816
+ // Match: optional sign, integer digits, optional fraction, optional exponent.
817
+ const match = /^([+-]?)(\d+)(?:\.(\d+))?(?:[eE]([+-]?\d+))?$/.exec(trimmed);
818
+ if (!match) {
819
+ throw new Error(`Invalid decimal string: ${value}`);
820
+ }
821
+ const sign = match[1] === '-' ? -1n : 1n;
822
+ const integerPart = match[2] ?? '';
823
+ const fractionalPart = match[3] ?? '';
824
+ const exponentPart = match[4] ? Number(match[4]) : 0;
825
+ if (!Number.isSafeInteger(exponentPart) ||
826
+ exponentPart > MAX_EXPONENT ||
827
+ exponentPart < -MAX_EXPONENT) {
828
+ throw new Error(`Exponent out of range: ${String(match[4])} exceeds safe integer bounds`);
829
+ }
830
+ const coefficientStr = integerPart + fractionalPart;
831
+ const coefficient = sign * BigInt(coefficientStr);
832
+ const exponent = exponentPart - fractionalPart.length;
833
+ if (!Number.isSafeInteger(exponent) ||
834
+ exponent > MAX_EXPONENT ||
835
+ exponent < -MAX_EXPONENT) {
836
+ throw new Error(`Computed exponent out of range: ${String(exponent)} exceeds safe integer bounds`);
837
+ }
838
+ return new DecimalImpl(coefficient, exponent);
839
+ },
840
+ /**
841
+ * The {@link Decimal} value representing zero.
842
+ *
843
+ * @remarks
844
+ * Pre-allocated singleton — prefer `Decimal.zero` over
845
+ * `Decimal.from(0)` to avoid an unnecessary allocation.
846
+ *
847
+ * @public
848
+ */
849
+ zero: new DecimalImpl(0n, 0),
850
+ };