@danielsimonjr/mathts-core 0.15.4 → 0.16.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.
@@ -1,29 +1,33 @@
1
1
  /**
2
2
  * Structural contract for the BigNumber values handled by this formatter.
3
- * Captures exactly the methods/properties used here. The configured BigNumber
4
- * implementation (e.g. decimal.js) provides these; the project's `BigNumber`
5
- * type alias points at a minimal local Decimal that does not declare them all,
6
- * so we model the runtime contract explicitly.
3
+ * Captures exactly the methods/properties used here, with the argument types this
4
+ * module actually passes. The configured BigNumber implementation (e.g. decimal.js)
5
+ * and core's own `BigNumber` both provide these.
6
+ *
7
+ * `Self` is the implementation's own type: the formatter only ever combines a value
8
+ * with numbers and with values of the same class (built through `ctorOf`). Typing an
9
+ * operand as `BigNumberValue` instead would demand that every implementation accept
10
+ * every other one, and neither decimal.js nor core's `BigNumber` does, so no real
11
+ * value was assignable and every export here was uncallable without a cast.
7
12
  */
8
- export interface BigNumberValue {
13
+ export interface BigNumberValue<Self> {
9
14
  e: number;
10
- constructor: new (value: number | string) => BigNumberValue;
11
15
  isFinite(): boolean;
12
16
  isNaN(): boolean;
13
17
  isZero(): boolean;
14
18
  isInteger(): boolean;
15
- gt(other: number | BigNumberValue): boolean;
16
- greaterThan(other: number | BigNumberValue): boolean;
17
- lessThan(other: number | BigNumberValue): boolean;
18
- add(other: number | BigNumberValue): BigNumberValue;
19
- sub(other: number | BigNumberValue): BigNumberValue;
20
- mul(other: number | BigNumberValue): BigNumberValue;
21
- pow(exp: number | BigNumberValue): BigNumberValue;
19
+ gt(other: number): boolean;
20
+ greaterThan(other: number | Self): boolean;
21
+ lessThan(other: number | Self): boolean;
22
+ add(other: Self): Self;
23
+ sub(other: number): Self;
24
+ mul(other: number): Self;
25
+ pow(exp: number): Self;
22
26
  toNumber(): number;
23
27
  toFixed(places?: number): string;
24
28
  toExponential(places?: number): string;
25
29
  toPrecision(sd?: number): string;
26
- toSignificantDigits(sd?: number): BigNumberValue;
30
+ toSignificantDigits(sd?: number): Self;
27
31
  toBinary(): string;
28
32
  toOctal(): string;
29
33
  toHexadecimal(): string;
@@ -115,7 +119,7 @@ export declare function format(value: unknown, options?: unknown): string;
115
119
  * @param value
116
120
  * @param precision - Optional number of significant figures to return.
117
121
  */
118
- export declare function toEngineering(value: BigNumberValue, precision?: number): string;
122
+ export declare function toEngineering<T extends BigNumberValue<T>>(value: T, precision?: number): string;
119
123
  /**
120
124
  * Format a number in exponential notation. Like '1.23e+5', '2.3e+0', '3.500e-3'
121
125
  * @param value
@@ -124,12 +128,12 @@ export declare function toEngineering(value: BigNumberValue, precision?: number)
124
128
  * is used.
125
129
  * @returns str
126
130
  */
127
- export declare function toExponential(value: BigNumberValue, precision?: number): string;
131
+ export declare function toExponential<T extends BigNumberValue<T>>(value: T, precision?: number): string;
128
132
  /**
129
133
  * Format a number with fixed notation.
130
134
  * @param value
131
135
  * @param precision - Optional number of decimals after the
132
136
  * decimal point. Undefined by default.
133
137
  */
134
- export declare function toFixed(value: BigNumberValue, precision?: number): string;
138
+ export declare function toFixed<T extends BigNumberValue<T>>(value: T, precision?: number): string;
135
139
  //# sourceMappingURL=bignumber-formatter.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"bignumber-formatter.d.ts","sourceRoot":"","sources":["../src/bignumber-formatter.ts"],"names":[],"mappings":"AAqBA;;;;;;GAMG;AACH,MAAM,WAAW,cAAc;IAC7B,CAAC,EAAE,MAAM,CAAC;IACV,WAAW,EAAE,KAAK,KAAK,EAAE,MAAM,GAAG,MAAM,KAAK,cAAc,CAAC;IAC5D,QAAQ,IAAI,OAAO,CAAC;IACpB,KAAK,IAAI,OAAO,CAAC;IACjB,MAAM,IAAI,OAAO,CAAC;IAClB,SAAS,IAAI,OAAO,CAAC;IACrB,EAAE,CAAC,KAAK,EAAE,MAAM,GAAG,cAAc,GAAG,OAAO,CAAC;IAC5C,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,cAAc,G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