• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

forzagreen / n2words / 27038711375

05 Jun 2026 08:35PM UTC coverage: 96.836% (-0.006%) from 96.842%
27038711375

Pull #372

github

web-flow
Merge a33d3d5aa into 3362118f9
Pull Request #372: feat(core): prove the range-contract shape on four representative languages

6375 of 6716 branches covered (94.92%)

Branch coverage included in aggregate %.

132 of 136 new or added lines in 6 files covered. (97.06%)

3 existing lines in 1 file now uncovered.

30566 of 31432 relevant lines covered (97.24%)

1134.0 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

94.51
/src/utils/scale.js
1
/**
3✔
2
 * Scale-range helpers — pure.
3✔
3
 *
3✔
4
 * Each form declares its maximum supported value as a bigint export
3✔
5
 * (`cardinalMax`, `ordinalMax`, `currencyMax`): the smallest value the form
3✔
6
 * refuses, so the largest it converts is that minus one. `UNBOUNDED` (null)
3✔
7
 * means no fixed limit.
3✔
8
 *
3✔
9
 * These helpers derive that bigint from a language's own scale-table size, so
3✔
10
 * the ceiling tracks the vocabulary and can't drift. A language whose shape
3✔
11
 * fits none of them declares the value directly (`bounded(n)` or a literal
3✔
12
 * bigint). They are pure — derivations and one comparison (`exceedsMax`) the
3✔
13
 * entry guards use. Nothing here throws; the language throws, and the
3✔
14
 * verification checks (boundary, gaps, injectivity) live in the gate.
3✔
15
 */
3✔
16

3✔
17
/** No fixed ceiling — recursive/compounding spellers (th-TH, fa-IR, …). */
3✔
18
export const UNBOUNDED = null
3✔
19

3✔
20
/**
3✔
21
 * Whether a parsed value is out of a form's range — pure; the caller throws.
3✔
22
 * Pass `fraction` (the decimal digit string) only when the fraction is spelled
3✔
23
 * via the scale builder; digit-by-digit forms omit it so long fractions stay
3✔
24
 * valid. A `max` of `null` (unbounded) is never exceeded.
3✔
25
 * @param {bigint} value The integer magnitude to test (integer part, dollars, …)
3✔
26
 * @param {bigint | null} max The form's ceiling, or null for no limit
3✔
27
 * @param {string} [fraction] The decimal digit string, when integer-spelled
3✔
28
 * @returns {boolean} true if `value` — or its integer-spelled fraction — exceeds `max`
3✔
29
 */
3✔
30
export function exceedsMax(value, max, fraction) {
3✔
31
  if (max === null) return false
5,140!
32
  if (value >= max) return true
5,140✔
33
  return fraction ? BigInt(fraction) >= max : false
5,140✔
34
}
5,140✔
35

3✔
36
/**
3✔
37
 * 3-digit grouping, scale array starting at "thousand" (en-US, de-DE, ru-RU, …).
3✔
38
 * @param {number} scaleCount Number of scale words in the table
3✔
39
 * @returns {bigint} The first unsupported value (10^((scaleCount + 1) * 3))
3✔
40
 */
3✔
41
export function western(scaleCount) {
3✔
42
  return 10n ** BigInt((scaleCount + 1) * 3)
9✔
43
}
9✔
44

3✔
45
/**
3✔
46
 * Myriad (4-digit) grouping — one scale word per power of 10,000 (ja-JP, ko-KR).
3✔
47
 * @param {number} scaleCount Number of scale words in the table
3✔
48
 * @returns {bigint} The first unsupported value
3✔
49
 */
3✔
50
export function myriad(scaleCount) {
3✔
NEW
51
  return 10n ** BigInt((scaleCount + 1) * 4)
×
NEW
52
}
×
53

3✔
54
/**
3✔
55
 * South Asian 3-2-2 grouping: a 3-digit base segment then 2 digits per scale
3✔
56
 * word, with the table's index 0 reserved for the (empty) units slot.
3✔
57
 * @param {number} wordCount Length of the scale-word table (including the units slot)
3✔
58
 * @returns {bigint} The first unsupported value
3✔
59
 */
3✔
60
export function indian(wordCount) {
3✔
NEW
61
  return 10n ** BigInt(3 + 2 * (wordCount - 1))
×
NEW
62
}
×
63

3✔
64
/**
3✔
65
 * Long scale — each unit (a base scale word, or a prefix) yields two levels
3✔
66
 * (-illion / -illiard), spanning 6 powers of ten. es-*, fr-*, it-IT.
3✔
67
 * @param {number} unitCount Number of base scale words or prefixes
3✔
68
 * @returns {bigint} The first unsupported value (10^(6 * (unitCount + 1)))
3✔
69
 */
3✔
70
export function longScale(unitCount) {
3✔
71
  return 10n ** BigInt(6 * (unitCount + 1))
9✔
72
}
9✔
73

3✔
74
/**
3✔
75
 * Escape hatch: a structural bound given as its base-10 exponent (zh: `bounded(16)`).
3✔
76
 * @param {number} exponent The base-10 exponent of the ceiling
3✔
77
 * @returns {bigint} 10^exponent
3✔
78
 */
3✔
79
export function bounded(exponent) {
3✔
80
  return 10n ** BigInt(exponent)
9✔
81
}
9✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc