arbitrary-numbers 1.0.1 → 1.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.
- package/README.md +311 -77
- package/dist/index.cjs +392 -46
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +262 -25
- package/dist/index.d.ts +262 -25
- package/dist/index.js +392 -46
- package/dist/index.js.map +1 -1
- package/package.json +9 -1
package/dist/index.d.cts
CHANGED
|
@@ -27,6 +27,44 @@ interface AnFunction {
|
|
|
27
27
|
from(value: number): ArbitraryNumber;
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
+
/**
|
|
31
|
+
* A value that can be either a plain `number` or an `ArbitraryNumber`.
|
|
32
|
+
*/
|
|
33
|
+
type ArbitraryNumberish = ArbitraryNumber | number;
|
|
34
|
+
/**
|
|
35
|
+
* A value that is either `T` or `undefined`.
|
|
36
|
+
*
|
|
37
|
+
* Use for genuinely optional values where the absence is meaningful
|
|
38
|
+
* (e.g. optional names, optional fallback plugins).
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* let label: Maybe<string>; // string | undefined
|
|
42
|
+
*/
|
|
43
|
+
type Maybe<T> = T | undefined;
|
|
44
|
+
/**
|
|
45
|
+
* A value that is either `T` or `null`.
|
|
46
|
+
*
|
|
47
|
+
* Use for explicit "no result" returns from functions that would otherwise throw
|
|
48
|
+
* (e.g. `tryFrom` at system boundaries where bad input should be handled gracefully).
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* function parse(s: string): Nullable<ArbitraryNumber> { ... }
|
|
52
|
+
*/
|
|
53
|
+
type Nullable<T> = T | null;
|
|
54
|
+
/**
|
|
55
|
+
* A stable, compact JSON representation of an {@link ArbitraryNumber}.
|
|
56
|
+
*
|
|
57
|
+
* Keys are intentionally short (`c`/`e`) to keep save-game blobs small.
|
|
58
|
+
* Produced by {@link ArbitraryNumber.toJSON} and consumed by {@link ArbitraryNumber.fromJSON}.
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* const saved: ArbitraryNumberJson = an(1500).toJSON(); // { c: 1.5, e: 3 }
|
|
62
|
+
*/
|
|
63
|
+
type ArbitraryNumberJson = {
|
|
64
|
+
c: number;
|
|
65
|
+
e: number;
|
|
66
|
+
};
|
|
67
|
+
|
|
30
68
|
/**
|
|
31
69
|
* A plugin that formats a normalised scientific notation number into a display string.
|
|
32
70
|
*
|
|
@@ -91,7 +129,7 @@ interface SuffixNotationPluginOptions {
|
|
|
91
129
|
*
|
|
92
130
|
* @example " " -> "1.50 K" | "" -> "1.50K"
|
|
93
131
|
*/
|
|
94
|
-
separator?: string
|
|
132
|
+
separator?: Maybe<string>;
|
|
95
133
|
}
|
|
96
134
|
/**
|
|
97
135
|
* A display label for one tier of magnitude, used by {@link UnitNotation}.
|
|
@@ -108,7 +146,7 @@ interface Unit {
|
|
|
108
146
|
/** Short symbol displayed after the number, e.g. `"M"`. */
|
|
109
147
|
symbol: string;
|
|
110
148
|
/** Optional full name, e.g. `"Million"`. Used for display purposes only. */
|
|
111
|
-
name?: string
|
|
149
|
+
name?: Maybe<string>;
|
|
112
150
|
}
|
|
113
151
|
/**
|
|
114
152
|
* A tier-indexed array of units for use with {@link UnitNotation}.
|
|
@@ -126,7 +164,7 @@ interface Unit {
|
|
|
126
164
|
* { symbol: "M" }, // tier 2: millions
|
|
127
165
|
* ];
|
|
128
166
|
*/
|
|
129
|
-
type UnitArray = ReadonlyArray<Unit
|
|
167
|
+
type UnitArray = ReadonlyArray<Maybe<Unit>>;
|
|
130
168
|
/**
|
|
131
169
|
* Options for constructing an {@link AlphabetNotation} instance.
|
|
132
170
|
*/
|
|
@@ -140,7 +178,7 @@ interface AlphabetNotationOptions extends SuffixNotationPluginOptions {
|
|
|
140
178
|
*
|
|
141
179
|
* @default `"abcdefghijklmnopqrstuvwxyz"`
|
|
142
180
|
*/
|
|
143
|
-
alphabet?: string
|
|
181
|
+
alphabet?: Maybe<string>;
|
|
144
182
|
}
|
|
145
183
|
/**
|
|
146
184
|
* Options for constructing a {@link UnitNotation} instance.
|
|
@@ -168,7 +206,21 @@ interface UnitNotationOptions extends SuffixNotationPluginOptions {
|
|
|
168
206
|
*
|
|
169
207
|
* @default undefined
|
|
170
208
|
*/
|
|
171
|
-
fallback?: SuffixProvider
|
|
209
|
+
fallback?: Maybe<SuffixProvider>;
|
|
210
|
+
/**
|
|
211
|
+
* When `true` (default), the fallback's tier is offset by the last defined tier in `units`
|
|
212
|
+
* so that fallback suffixes are visually distinct from those the fallback would generate
|
|
213
|
+
* for low tiers.
|
|
214
|
+
*
|
|
215
|
+
* Example with `CLASSIC_UNITS` (last defined tier = 33) and `letterNotation` as fallback:
|
|
216
|
+
* - `offsetFallback: true` → exponent 102 (tier 34) → `"a"` (fallback tier 1, distinct from "K")
|
|
217
|
+
* - `offsetFallback: false` → exponent 102 (tier 34) → `"h"` (fallback tier 34, same as exponent 24)
|
|
218
|
+
*
|
|
219
|
+
* Set to `false` only for backwards compatibility with pre-1.1 behaviour.
|
|
220
|
+
*
|
|
221
|
+
* @default true
|
|
222
|
+
*/
|
|
223
|
+
offsetFallback?: Maybe<boolean>;
|
|
172
224
|
}
|
|
173
225
|
|
|
174
226
|
/**
|
|
@@ -220,8 +272,9 @@ declare class ArbitraryNumber implements NormalizedNumber {
|
|
|
220
272
|
* ArbitraryNumber.from(1500); // { coefficient: 1.5, exponent: 3 }
|
|
221
273
|
* ArbitraryNumber.from(0.005); // { coefficient: 5, exponent: -3 }
|
|
222
274
|
* ArbitraryNumber.from(0); // ArbitraryNumber.Zero
|
|
275
|
+
* ArbitraryNumber.from(-0); // ArbitraryNumber.Zero (signed zero is normalised to +0)
|
|
223
276
|
*
|
|
224
|
-
* @param value - Any finite number.
|
|
277
|
+
* @param value - Any finite number. Signed zero (`-0`) is treated as `0`.
|
|
225
278
|
* @throws `"ArbitraryNumber.from: value must be finite"` for `NaN`, `Infinity`, or `-Infinity`.
|
|
226
279
|
*/
|
|
227
280
|
static from(value: number): ArbitraryNumber;
|
|
@@ -246,14 +299,6 @@ declare class ArbitraryNumber implements NormalizedNumber {
|
|
|
246
299
|
* Do NOT use for unnormalised inputs - call new ArbitraryNumber(c, e) instead.
|
|
247
300
|
*/
|
|
248
301
|
private static createNormalized;
|
|
249
|
-
/**
|
|
250
|
-
* Normalises raw (coefficient, exponent) into a new ArbitraryNumber.
|
|
251
|
-
*
|
|
252
|
-
* INVARIANT: all ArbitraryNumber values must have coefficient in [1, 10).
|
|
253
|
-
* Algorithm: shift = floor(log10(|c|)); scale c by 10^-shift; adjust exponent.
|
|
254
|
-
* Cost: one Math.log10 call (~3-4 ns). This is the fundamental cost floor - logarithm
|
|
255
|
-
* is the only way to compute magnitude in JavaScript.
|
|
256
|
-
*/
|
|
257
302
|
private static normalizeFrom;
|
|
258
303
|
/**
|
|
259
304
|
* Returns `this + other`.
|
|
@@ -370,6 +415,21 @@ declare class ArbitraryNumber implements NormalizedNumber {
|
|
|
370
415
|
* @throws `"Division by zero"` when divisor is zero.
|
|
371
416
|
*/
|
|
372
417
|
divAdd(divisor: ArbitraryNumber, addend: ArbitraryNumber): ArbitraryNumber;
|
|
418
|
+
/**
|
|
419
|
+
* Fused multiply-divide: `(this * multiplier) / divisor`.
|
|
420
|
+
*
|
|
421
|
+
* Avoids one intermediate allocation vs `.mul(multiplier).div(divisor)`.
|
|
422
|
+
* The divisor zero-check is performed before the multiply to avoid unnecessary work.
|
|
423
|
+
*
|
|
424
|
+
* Common pattern - idle-tick math: `(production * deltaTime) / cost`
|
|
425
|
+
*
|
|
426
|
+
* @example
|
|
427
|
+
* // Equivalent to production.mul(deltaTime).div(cost) but ~30-40% faster
|
|
428
|
+
* const consumed = production.mulDiv(deltaTime, cost);
|
|
429
|
+
*
|
|
430
|
+
* @throws `"Division by zero"` when divisor is zero.
|
|
431
|
+
*/
|
|
432
|
+
mulDiv(multiplier: ArbitraryNumber, divisor: ArbitraryNumber): ArbitraryNumber;
|
|
373
433
|
/**
|
|
374
434
|
* Efficiently sums an array of ArbitraryNumbers in a single normalisation pass.
|
|
375
435
|
*
|
|
@@ -388,6 +448,36 @@ declare class ArbitraryNumber implements NormalizedNumber {
|
|
|
388
448
|
* @param numbers - Array to sum. Empty array returns {@link Zero}. Single element returned as-is.
|
|
389
449
|
*/
|
|
390
450
|
static sumArray(numbers: ArbitraryNumber[]): ArbitraryNumber;
|
|
451
|
+
/**
|
|
452
|
+
* Multiplies an array of `ArbitraryNumber`s in a single pass.
|
|
453
|
+
*
|
|
454
|
+
* Coefficients are multiplied together with intermediate normalisation after each step
|
|
455
|
+
* to keep values in [1, 10). Exponents are summed. One total normalisation at the end.
|
|
456
|
+
*
|
|
457
|
+
* Empty array returns {@link One}. Single element returned as-is.
|
|
458
|
+
*
|
|
459
|
+
* @example
|
|
460
|
+
* ArbitraryNumber.productArray([an(2), an(3), an(4)]); // 24
|
|
461
|
+
*/
|
|
462
|
+
static productArray(numbers: ArbitraryNumber[]): ArbitraryNumber;
|
|
463
|
+
/**
|
|
464
|
+
* Returns the largest value in an array.
|
|
465
|
+
*
|
|
466
|
+
* Empty array returns {@link Zero}. Single element returned as-is.
|
|
467
|
+
*
|
|
468
|
+
* @example
|
|
469
|
+
* ArbitraryNumber.maxOfArray([an(1), an(3), an(2)]); // an(3)
|
|
470
|
+
*/
|
|
471
|
+
static maxOfArray(numbers: ArbitraryNumber[]): ArbitraryNumber;
|
|
472
|
+
/**
|
|
473
|
+
* Returns the smallest value in an array.
|
|
474
|
+
*
|
|
475
|
+
* Empty array returns {@link Zero}. Single element returned as-is.
|
|
476
|
+
*
|
|
477
|
+
* @example
|
|
478
|
+
* ArbitraryNumber.minOfArray([an(3), an(1), an(2)]); // an(1)
|
|
479
|
+
*/
|
|
480
|
+
static minOfArray(numbers: ArbitraryNumber[]): ArbitraryNumber;
|
|
391
481
|
/**
|
|
392
482
|
* Compares this number to `other`.
|
|
393
483
|
*
|
|
@@ -499,6 +589,62 @@ declare class ArbitraryNumber implements NormalizedNumber {
|
|
|
499
589
|
* new ArbitraryNumber(1, 4).sqrt(); // 1*10^2 (= 100)
|
|
500
590
|
*/
|
|
501
591
|
sqrt(): ArbitraryNumber;
|
|
592
|
+
/**
|
|
593
|
+
* Returns the cube root of this number: `∛this`.
|
|
594
|
+
*
|
|
595
|
+
* Computed without `Math.log10`. For exponents divisible by 3: `cbrt(c) * 10^(e/3)`.
|
|
596
|
+
* For remainder 1: `cbrt(c * 10) * 10^((e-1)/3)`.
|
|
597
|
+
* For remainder 2: `cbrt(c * 100) * 10^((e-2)/3)`.
|
|
598
|
+
*
|
|
599
|
+
* Supports negative numbers (cube root of a negative is negative).
|
|
600
|
+
*
|
|
601
|
+
* @example
|
|
602
|
+
* new ArbitraryNumber(8, 0).cbrt(); // 2
|
|
603
|
+
* new ArbitraryNumber(1, 9).cbrt(); // 1*10^3 (= 1,000)
|
|
604
|
+
* new ArbitraryNumber(-8, 0).cbrt(); // -2
|
|
605
|
+
*/
|
|
606
|
+
cbrt(): ArbitraryNumber;
|
|
607
|
+
/**
|
|
608
|
+
* Returns `log_base(this)` as a plain JavaScript `number`.
|
|
609
|
+
*
|
|
610
|
+
* Computed as `log10(this) / log10(base)`. The numerator is exact due to the
|
|
611
|
+
* stored `coefficient × 10^exponent` form.
|
|
612
|
+
*
|
|
613
|
+
* @param base - The logarithm base. Must be positive and not 1.
|
|
614
|
+
* @throws `"Logarithm of zero is undefined"` when this is zero.
|
|
615
|
+
* @throws `"Logarithm of a negative number is undefined"` when this is negative.
|
|
616
|
+
* @throws `"Logarithm base must be positive and not 1"` for invalid base.
|
|
617
|
+
*
|
|
618
|
+
* @example
|
|
619
|
+
* new ArbitraryNumber(8, 0).log(2); // 3
|
|
620
|
+
* new ArbitraryNumber(1, 6).log(10); // 6
|
|
621
|
+
*/
|
|
622
|
+
log(base: number): number;
|
|
623
|
+
/**
|
|
624
|
+
* Returns `ln(this)` — the natural logarithm — as a plain JavaScript `number`.
|
|
625
|
+
*
|
|
626
|
+
* Computed as `log10(this) / log10(e)`.
|
|
627
|
+
*
|
|
628
|
+
* @throws `"Logarithm of zero is undefined"` when this is zero.
|
|
629
|
+
* @throws `"Logarithm of a negative number is undefined"` when this is negative.
|
|
630
|
+
*
|
|
631
|
+
* @example
|
|
632
|
+
* new ArbitraryNumber(1, 0).ln(); // 0
|
|
633
|
+
*/
|
|
634
|
+
ln(): number;
|
|
635
|
+
/**
|
|
636
|
+
* Returns `10^n` as an `ArbitraryNumber`, where `n` is a plain JS `number`.
|
|
637
|
+
*
|
|
638
|
+
* This is the inverse of {@link log10}. Useful for converting a log10 result
|
|
639
|
+
* back into an `ArbitraryNumber`.
|
|
640
|
+
*
|
|
641
|
+
* @example
|
|
642
|
+
* ArbitraryNumber.exp10(6); // 1*10^6 (= 1,000,000)
|
|
643
|
+
* ArbitraryNumber.exp10(3.5); // 10^3.5 ≈ 3162.3
|
|
644
|
+
*
|
|
645
|
+
* @throws `"ArbitraryNumber.exp10: n must be finite"` for non-finite `n`.
|
|
646
|
+
*/
|
|
647
|
+
static exp10(n: number): ArbitraryNumber;
|
|
502
648
|
/**
|
|
503
649
|
* Returns the nearest integer value (rounds half-up).
|
|
504
650
|
*
|
|
@@ -511,6 +657,20 @@ declare class ArbitraryNumber implements NormalizedNumber {
|
|
|
511
657
|
* new ArbitraryNumber(-1.5, 0).round(); // -1 (half-up toward positive infinity)
|
|
512
658
|
*/
|
|
513
659
|
round(): ArbitraryNumber;
|
|
660
|
+
/**
|
|
661
|
+
* Returns the integer part of this number, truncating toward zero.
|
|
662
|
+
*
|
|
663
|
+
* Unlike `floor()`, which rounds toward −∞, `trunc()` always rounds toward 0:
|
|
664
|
+
* - `trunc(1.7) = 1` (same as floor)
|
|
665
|
+
* - `trunc(-1.7) = -1` (different from floor, which gives -2)
|
|
666
|
+
*
|
|
667
|
+
* Numbers with `exponent >= PrecisionCutoff` are already integers and returned unchanged.
|
|
668
|
+
*
|
|
669
|
+
* @example
|
|
670
|
+
* new ArbitraryNumber(1.7, 0).trunc(); // 1
|
|
671
|
+
* new ArbitraryNumber(-1.7, 0).trunc(); // -1
|
|
672
|
+
*/
|
|
673
|
+
trunc(): ArbitraryNumber;
|
|
514
674
|
/**
|
|
515
675
|
* Returns `1` if positive, `-1` if negative, `0` if zero.
|
|
516
676
|
*
|
|
@@ -532,6 +692,55 @@ declare class ArbitraryNumber implements NormalizedNumber {
|
|
|
532
692
|
* new ArbitraryNumber(1, 400).toNumber(); // Infinity
|
|
533
693
|
*/
|
|
534
694
|
toNumber(): number;
|
|
695
|
+
/**
|
|
696
|
+
* Returns a stable, minimal JSON representation: `{ c: number, e: number }`.
|
|
697
|
+
*
|
|
698
|
+
* The keys `c` and `e` are intentionally short to keep save-game blobs small.
|
|
699
|
+
* Reconstruct via {@link ArbitraryNumber.fromJSON}.
|
|
700
|
+
*
|
|
701
|
+
* Round-trip guarantee: `ArbitraryNumber.fromJSON(x.toJSON()).equals(x)` is always `true`.
|
|
702
|
+
*
|
|
703
|
+
* @example
|
|
704
|
+
* JSON.stringify(an(1.5, 6)); // '{"c":1.5,"e":6}'
|
|
705
|
+
*/
|
|
706
|
+
toJSON(): ArbitraryNumberJson;
|
|
707
|
+
/**
|
|
708
|
+
* Returns a raw string representation: `"<coefficient>|<exponent>"`.
|
|
709
|
+
*
|
|
710
|
+
* Useful for compact textual serialization. Reconstruct via {@link ArbitraryNumber.parse}.
|
|
711
|
+
*
|
|
712
|
+
* @example
|
|
713
|
+
* an(1.5, 3).toRaw(); // "1.5|3"
|
|
714
|
+
* an(-2, 6).toRaw(); // "-2|6"
|
|
715
|
+
*/
|
|
716
|
+
toRaw(): string;
|
|
717
|
+
/**
|
|
718
|
+
* Reconstructs an `ArbitraryNumber` from a `toJSON()` blob.
|
|
719
|
+
*
|
|
720
|
+
* @example
|
|
721
|
+
* const n = an(1.5, 6);
|
|
722
|
+
* ArbitraryNumber.fromJSON(n.toJSON()).equals(n); // true
|
|
723
|
+
*
|
|
724
|
+
* @param obj - Object with numeric `c` (coefficient) and `e` (exponent) fields.
|
|
725
|
+
* @throws `ArbitraryNumberInputError` when the object shape is invalid or values are non-finite.
|
|
726
|
+
*/
|
|
727
|
+
static fromJSON(obj: unknown): ArbitraryNumber;
|
|
728
|
+
/**
|
|
729
|
+
* Parses a string into an `ArbitraryNumber`.
|
|
730
|
+
*
|
|
731
|
+
* Accepted formats:
|
|
732
|
+
* - Raw pipe format (exact round-trip): `"1.5|3"`, `"-2.5|-6"`
|
|
733
|
+
* - Standard scientific notation: `"1.5e+3"`, `"1.5e-3"`, `"1.5E3"`, `"1.5e3"`
|
|
734
|
+
* - Plain decimal: `"1500"`, `"-0.003"`, `"0"`
|
|
735
|
+
*
|
|
736
|
+
* @example
|
|
737
|
+
* ArbitraryNumber.parse("1.5|3"); // same as an(1.5, 3)
|
|
738
|
+
* ArbitraryNumber.parse("1.5e+3"); // same as ArbitraryNumber.from(1500)
|
|
739
|
+
* ArbitraryNumber.parse("1500"); // same as ArbitraryNumber.from(1500)
|
|
740
|
+
*
|
|
741
|
+
* @throws `ArbitraryNumberInputError` when the string cannot be parsed or produces a non-finite value.
|
|
742
|
+
*/
|
|
743
|
+
static parse(s: string): ArbitraryNumber;
|
|
535
744
|
/** Returns `true` when this number is zero. */
|
|
536
745
|
isZero(): boolean;
|
|
537
746
|
/** Returns `true` when this number is strictly positive. */
|
|
@@ -543,6 +752,13 @@ declare class ArbitraryNumber implements NormalizedNumber {
|
|
|
543
752
|
* Numbers with `exponent >= PrecisionCutoff` are always considered integers.
|
|
544
753
|
*/
|
|
545
754
|
isInteger(): boolean;
|
|
755
|
+
/**
|
|
756
|
+
* Allows implicit coercion via `+an(1500)` (returns `toNumber()`) and
|
|
757
|
+
* template literals / string concatenation (returns `toString()`).
|
|
758
|
+
*
|
|
759
|
+
* `hint === "number"` → `toNumber()`; all other hints → `toString()`.
|
|
760
|
+
*/
|
|
761
|
+
[Symbol.toPrimitive](hint: string): number | string;
|
|
546
762
|
/**
|
|
547
763
|
* Formats this number as a string using the given notation plugin.
|
|
548
764
|
*
|
|
@@ -715,14 +931,14 @@ type FormulaStep = (value: ArbitraryNumber) => ArbitraryNumber;
|
|
|
715
931
|
* const result = full.apply(baseDamage);
|
|
716
932
|
*/
|
|
717
933
|
declare class AnFormula {
|
|
718
|
-
private readonly _name
|
|
934
|
+
private readonly _name;
|
|
719
935
|
private readonly steps;
|
|
720
936
|
/**
|
|
721
937
|
* Prefer the {@link formula} factory function over calling this directly.
|
|
722
938
|
*/
|
|
723
|
-
constructor(name?: string
|
|
939
|
+
constructor(name?: Maybe<string>, steps?: ReadonlyArray<FormulaStep>);
|
|
724
940
|
/** The name passed to {@link formula}, if any. */
|
|
725
|
-
get name(): string
|
|
941
|
+
get name(): Maybe<string>;
|
|
726
942
|
/**
|
|
727
943
|
* Returns a copy of this formula with a new name, leaving the original unchanged.
|
|
728
944
|
*
|
|
@@ -816,7 +1032,7 @@ declare class AnFormula {
|
|
|
816
1032
|
* const full = armorReduction.then(critBonus);
|
|
817
1033
|
* const result = full.apply(baseDamage);
|
|
818
1034
|
*/
|
|
819
|
-
declare function formula(name?: string): AnFormula;
|
|
1035
|
+
declare function formula(name?: Maybe<string>): AnFormula;
|
|
820
1036
|
|
|
821
1037
|
/**
|
|
822
1038
|
* Formats numbers using standard scientific notation: `"1.50e+3"`, `"1.50e-5"`.
|
|
@@ -988,14 +1204,23 @@ declare const letterNotation: AlphabetNotation;
|
|
|
988
1204
|
declare class UnitNotation extends SuffixNotationBase {
|
|
989
1205
|
protected readonly fallback?: SuffixProvider;
|
|
990
1206
|
protected readonly units: UnitArray;
|
|
1207
|
+
/** The highest tier index that has a defined unit in `units`. Used to offset fallback calls. */
|
|
1208
|
+
private readonly lastDefinedTier;
|
|
1209
|
+
private readonly offsetFallback;
|
|
991
1210
|
/**
|
|
992
1211
|
* @param options - Tier-indexed unit array, optional suffix fallback plugin, and separator.
|
|
993
1212
|
* `separator` defaults to `" "` (a space between number and unit symbol).
|
|
1213
|
+
* `offsetFallback` defaults to `true` — the fallback tier is offset so its suffixes
|
|
1214
|
+
* are visually distinct from any low-tier suffixes the same fallback would produce.
|
|
994
1215
|
*/
|
|
995
1216
|
constructor(options: UnitNotationOptions);
|
|
996
1217
|
/**
|
|
997
1218
|
* Returns the suffix for the given tier: the own unit symbol if defined,
|
|
998
|
-
* otherwise the fallback's suffix
|
|
1219
|
+
* otherwise the fallback's suffix (offset by the last defined tier when
|
|
1220
|
+
* `offsetFallback` is `true`), otherwise `""`.
|
|
1221
|
+
*
|
|
1222
|
+
* The offset ensures fallback suffixes start at tier 1 of the fallback's sequence,
|
|
1223
|
+
* avoiding visual ambiguity with low-tier suffixes from the same fallback plugin.
|
|
999
1224
|
*
|
|
1000
1225
|
* @param tier - The exponent tier (`Math.floor(exponent / 3)`).
|
|
1001
1226
|
* @returns The suffix string, or `""` if neither own units nor fallback cover this tier.
|
|
@@ -1072,11 +1297,6 @@ declare class ArbitraryNumberGuard {
|
|
|
1072
1297
|
static isZero(obj: unknown): boolean;
|
|
1073
1298
|
}
|
|
1074
1299
|
|
|
1075
|
-
/**
|
|
1076
|
-
* A value that can be either a plain `number` or an `ArbitraryNumber`.
|
|
1077
|
-
*/
|
|
1078
|
-
type ArbitraryNumberish = ArbitraryNumber | number;
|
|
1079
|
-
|
|
1080
1300
|
/**
|
|
1081
1301
|
* Convenience helpers for mixed `number | ArbitraryNumber` inputs.
|
|
1082
1302
|
*
|
|
@@ -1099,8 +1319,25 @@ declare class ArbitraryNumberOps {
|
|
|
1099
1319
|
*
|
|
1100
1320
|
* @param value - A plain `number` or an existing `ArbitraryNumber`.
|
|
1101
1321
|
* @returns The corresponding `ArbitraryNumber`.
|
|
1322
|
+
* @throws `ArbitraryNumberInputError` when `value` is `NaN`, `Infinity`, or `-Infinity`.
|
|
1102
1323
|
*/
|
|
1103
1324
|
static from(value: ArbitraryNumberish): ArbitraryNumber;
|
|
1325
|
+
/**
|
|
1326
|
+
* Converts `value` to an `ArbitraryNumber`, returning `null` for non-finite inputs
|
|
1327
|
+
* instead of throwing.
|
|
1328
|
+
*
|
|
1329
|
+
* Use this at system boundaries (form inputs, external APIs) where you want to handle
|
|
1330
|
+
* bad input gracefully rather than catching an exception.
|
|
1331
|
+
*
|
|
1332
|
+
* @param value - A plain `number` or an existing `ArbitraryNumber`.
|
|
1333
|
+
* @returns The `ArbitraryNumber`, or `null` if the input is `NaN`, `Infinity`, or `-Infinity`.
|
|
1334
|
+
*
|
|
1335
|
+
* @example
|
|
1336
|
+
* ops.tryFrom(1500) // ArbitraryNumber { coefficient: 1.5, exponent: 3 }
|
|
1337
|
+
* ops.tryFrom(Infinity) // null
|
|
1338
|
+
* ops.tryFrom(NaN) // null
|
|
1339
|
+
*/
|
|
1340
|
+
static tryFrom(value: ArbitraryNumberish): Nullable<ArbitraryNumber>;
|
|
1104
1341
|
/**
|
|
1105
1342
|
* Returns `left + right`, coercing both operands as needed.
|
|
1106
1343
|
*
|
|
@@ -1208,4 +1445,4 @@ declare class ArbitraryNumberHelpers {
|
|
|
1208
1445
|
static subtractWithFloor(value: ArbitraryNumberish, delta: ArbitraryNumberish, floor?: ArbitraryNumberish): ArbitraryNumber;
|
|
1209
1446
|
}
|
|
1210
1447
|
|
|
1211
|
-
export { AlphabetNotation, type AlphabetNotationOptions, AnChain, AnFormula, type AnFunction, ArbitraryNumber, ArbitraryNumberDomainError, ArbitraryNumberError, ArbitraryNumberGuard, ArbitraryNumberHelpers, ArbitraryNumberInputError, ArbitraryNumberOps, type ArbitraryNumberish, CLASSIC_UNITS, COMPACT_UNITS, type Mod3, type NormalizedNumber, type NotationPlugin, ScientificNotation, type Signum, SuffixNotationBase, type SuffixNotationPlugin, type SuffixNotationPluginOptions, type SuffixProvider, type Unit, type UnitArray, UnitNotation, type UnitNotationOptions, alphabetSuffix, an, chain, formula, ArbitraryNumberGuard as guard, ArbitraryNumberHelpers as helpers, letterNotation, ArbitraryNumberOps as ops, scientificNotation, unitNotation };
|
|
1448
|
+
export { AlphabetNotation, type AlphabetNotationOptions, AnChain, AnFormula, type AnFunction, ArbitraryNumber, ArbitraryNumberDomainError, ArbitraryNumberError, ArbitraryNumberGuard, ArbitraryNumberHelpers, ArbitraryNumberInputError, type ArbitraryNumberJson, ArbitraryNumberOps, type ArbitraryNumberish, CLASSIC_UNITS, COMPACT_UNITS, type Maybe, type Mod3, type NormalizedNumber, type NotationPlugin, type Nullable, ScientificNotation, type Signum, SuffixNotationBase, type SuffixNotationPlugin, type SuffixNotationPluginOptions, type SuffixProvider, type Unit, type UnitArray, UnitNotation, type UnitNotationOptions, alphabetSuffix, an, chain, formula, ArbitraryNumberGuard as guard, ArbitraryNumberHelpers as helpers, letterNotation, ArbitraryNumberOps as ops, scientificNotation, unitNotation };
|