feat: Indian lakh/crore grouping + locale-derived group sizes (v0.6) - #16
Merged
Conversation
The Indian system groups the last three digits and then every two
(12,34,56,789), which the uniform regex grouper could not express — the
reason this sat in the backlog.
- group now accepts a [primary, secondary] pair; the regex grouper is
replaced by a right-to-left loop that handles both uniform and
non-uniform sizes. A plain number still means uniform grouping, and
group: 0 now disables separators instead of building a pathological
regex (\d{0}).
- data-numkey-group="3,2" parses the pair; garbage falls back to 3, and
a secondary of 0 means uniform.
- Fixes a latent bug the feature exposed: locale only derived the
separator and decimal mark, so locale: 'en-IN' rendered 123,456,789 —
right separator, wrong grouping for that locale. localeSeparators now
also reports group sizes (read out of Intl's formatToParts integer
runs, which is how CLDR models primary/secondary), and resolveOptions
applies them. Explicit group still wins.
- Caret math is untouched: it counts significant characters (digits),
so it is grouping-agnostic by construction.
Verified: 12 new tests (112 total) including an exhaustive cross-check of
both Indian and default grouping against Intl.NumberFormat across integer
widths 1-15. Also verified in a real browser char-by-char (this repo has
a history of DOM bugs whole-value tests missed): 1 -> 1,234 -> 12,345 ->
1,23,456 -> 12,34,56,789 with the caret tracking correctly, plus
mid-string insertion. Demo site locale switcher gains en-IN.
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.
The last backlog item. The Indian system groups the last three digits and then every two —
12,34,56,789, not123,456,789— which the uniform regex grouper couldn't express. That's why it sat demand-gated; now it's requested.Added
groupaccepts a[primary, secondary]pair:The regex grouper is replaced by a right-to-left loop covering both uniform and non-uniform sizes. A plain number still means uniform grouping (
4→1234,5678), andgroup: 0now disables separators instead of building a pathological\d{0}regex.Fixed — a latent bug this exposed
localeonly derived the separator and decimal mark, so a field withlocale: 'en-IN'rendered123,456,789: right separator, wrong grouping for that locale.localeSeparatorsnow also reports group sizes — read out ofIntl'sformatToPartsinteger runs, which is how CLDR models primary/secondary — andresolveOptionsapplies them. Locales with ordinary thousands grouping are unaffected; an explicitgroupstill wins.Not affected
Caret math counts significant characters (digits), so it is grouping-agnostic by construction — no changes needed there, and a caret test under lakh grouping proves it.
Verification
Intl.NumberFormatacross integer widths 1–15 — 0 mismatches.1→1,234→12,345→1,23,456→12,34,56,789with the caret tracking correctly at every step, plus a mid-string insertion (1,02,34,56,789, caret after the inserted digit).en-IN; verified rendering12,34,567.89while the canonical value stays"1234567.89".