Road to v1: API revamp#20
Open
mhluongo wants to merge 19 commits into1.0/monorepofrom
Open
Conversation
Leaving it to app developers is unreasonable.
Down the road, we'll use them to point to documentation as appropriate.
... the idea here is to allow app devs to decide whether they want to enforce strict precision without rounding, as well as simple stuff like default config.
The constructor signature is (expected, actual, operation) but the 4 call sites in bounds methods passed (operation, expected, actual), causing the error's .expected and .actual fields to contain wrong values.
Replace parseFloat(value) fallback with FixedPointNumber.fromDecimalString() to avoid floating-point precision loss when parsing bare numeric strings in clamp/atLeast/atMost. Non-numeric strings now throw ParseError.
defaultRoundingMode, defaultCurrency, and strictPrecisions
Conditionally load AsyncLocalStorage from node:async_hooks so concurrent Isolate withConfig scopes in Node
Delete dead code and extract helpers where appropriate.
- New `Money.fromMinorUnits(amount, currency)` static delegates to the bigint factory overload, giving users a discoverable name for the "interpret bigint as minor units" convention. - Add @remarks to clamp/atLeast/atMost noting that bare numeric strings preserve full input precision; pass a Money instance for currency- canonical precision.
When AsyncLocalStorage is unavailable, withConfig() does sync save/restore. If the callback returns a Promise, the restore runs when the Promise is returned (not when it resolves), so concurrent async withConfig calls in the browser race on the global config. Detect a Promise return value via duck-typed `.then` and emit a one-time console.warn. Behavior is unchanged: the Promise is still returned to the caller. Tests exercise the warn-once dedup and confirm sync paths do not warn.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Expand the
MoneyAPI, loosening restrictions by default to make the experience easier for new developers.Rounding and
Numberarguments can still be disabled via global library config.