@danielsimonjr/mathts-core 0.14.1 → 0.15.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.
Files changed (91) hide show
  1. package/dist/arithmetic/scalar.d.ts +56 -0
  2. package/dist/arithmetic/scalar.d.ts.map +1 -0
  3. package/dist/array.d.ts +253 -0
  4. package/dist/array.d.ts.map +1 -0
  5. package/dist/bignumber-formatter.d.ts +135 -0
  6. package/dist/bignumber-formatter.d.ts.map +1 -0
  7. package/dist/{chunk-VPK5YTKG.js → chunk-L5MWGOLB.js} +111 -29
  8. package/dist/collection.d.ts +67 -0
  9. package/dist/collection.d.ts.map +1 -0
  10. package/dist/config.d.ts +17 -0
  11. package/dist/config.d.ts.map +1 -0
  12. package/dist/constants.d.ts +30 -0
  13. package/dist/constants.d.ts.map +1 -0
  14. package/dist/customs.d.ts +44 -0
  15. package/dist/customs.d.ts.map +1 -0
  16. package/dist/error/DimensionError.d.ts +26 -0
  17. package/dist/error/DimensionError.d.ts.map +1 -0
  18. package/dist/error/IndexError.d.ts +33 -0
  19. package/dist/error/IndexError.d.ts.map +1 -0
  20. package/dist/error/MathjsError.d.ts +13 -0
  21. package/dist/error/MathjsError.d.ts.map +1 -0
  22. package/dist/factory/factory.d.ts +154 -0
  23. package/dist/factory/factory.d.ts.map +1 -0
  24. package/dist/factory/index.d.ts +6 -0
  25. package/dist/factory/index.d.ts.map +1 -0
  26. package/dist/factory.d.ts +112 -0
  27. package/dist/factory.d.ts.map +1 -0
  28. package/dist/index.d.ts +24 -2585
  29. package/dist/index.d.ts.map +1 -0
  30. package/dist/index.js +74 -18
  31. package/dist/internal.d.ts +33 -1344
  32. package/dist/internal.d.ts.map +1 -0
  33. package/dist/internal.js +5 -3
  34. package/dist/is.d.ts +102 -0
  35. package/dist/is.d.ts.map +1 -0
  36. package/dist/map.d.ts +113 -0
  37. package/dist/map.d.ts.map +1 -0
  38. package/dist/number.d.ts +314 -0
  39. package/dist/number.d.ts.map +1 -0
  40. package/dist/numeric/stable.d.ts +130 -0
  41. package/dist/numeric/stable.d.ts.map +1 -0
  42. package/dist/object.d.ts +119 -0
  43. package/dist/object.d.ts.map +1 -0
  44. package/dist/shared.d.ts +41 -0
  45. package/dist/shared.d.ts.map +1 -0
  46. package/dist/string.d.ts +70 -0
  47. package/dist/string.d.ts.map +1 -0
  48. package/dist/switch.d.ts +9 -0
  49. package/dist/switch.d.ts.map +1 -0
  50. package/dist/typed/index.d.ts +7 -0
  51. package/dist/typed/index.d.ts.map +1 -0
  52. package/dist/typed/mathts-typed.d.ts +246 -0
  53. package/dist/typed/mathts-typed.d.ts.map +1 -0
  54. package/dist/typed/type-bridge.d.ts +2 -0
  55. package/dist/typed/type-bridge.d.ts.map +1 -0
  56. package/dist/types/bignumber.d.ts +367 -0
  57. package/dist/types/bignumber.d.ts.map +1 -0
  58. package/dist/types/complex.d.ts +284 -0
  59. package/dist/types/complex.d.ts.map +1 -0
  60. package/dist/types/dual-rules.d.ts +129 -0
  61. package/dist/types/dual-rules.d.ts.map +1 -0
  62. package/dist/types/dual.d.ts +36 -0
  63. package/dist/types/dual.d.ts.map +1 -0
  64. package/dist/types/fraction.d.ts +215 -0
  65. package/dist/types/fraction.d.ts.map +1 -0
  66. package/dist/types/interfaces.d.ts +143 -0
  67. package/dist/types/interfaces.d.ts.map +1 -0
  68. package/dist/types/matrix/Range.d.ts +767 -0
  69. package/dist/types/matrix/Range.d.ts.map +1 -0
  70. package/dist/types/unit/Unit.d.ts +3 -0
  71. package/dist/types/unit/Unit.d.ts.map +1 -0
  72. package/dist/types/unit/dependencies.d.ts +4 -0
  73. package/dist/types/unit/dependencies.d.ts.map +1 -0
  74. package/dist/types/unit/errors.d.ts +18 -0
  75. package/dist/types/unit/errors.d.ts.map +1 -0
  76. package/dist/types/unit/index.d.ts +7 -0
  77. package/dist/types/unit/index.d.ts.map +1 -0
  78. package/dist/types/unit/unit-types.d.ts +231 -0
  79. package/dist/types/unit/unit-types.d.ts.map +1 -0
  80. package/dist/types/unit-definitions.d.ts +79 -0
  81. package/dist/types/unit-definitions.d.ts.map +1 -0
  82. package/dist/types/unit-prefixes.d.ts +29 -0
  83. package/dist/types/unit-prefixes.d.ts.map +1 -0
  84. package/dist/types/unit.d.ts +28 -0
  85. package/dist/types/unit.d.ts.map +1 -0
  86. package/dist/types/wasm-loader.d.ts +35 -0
  87. package/dist/types/wasm-loader.d.ts.map +1 -0
  88. package/dist/wasm-loader.d.ts +97 -0
  89. package/dist/wasm-loader.d.ts.map +1 -0
  90. package/package.json +9 -9
  91. package/dist/index-B4LIOfHN.d.ts +0 -449
@@ -0,0 +1,56 @@
1
+ import { BigNumber } from '../types/bignumber.js';
2
+ import { Complex } from '../types/complex.js';
3
+ import { Fraction } from '../types/fraction.js';
4
+ /** Any scalar core can do arithmetic on. */
5
+ export type NumericScalar = number | bigint | Complex | Fraction | BigNumber;
6
+ /** Add two scalar values, `x + y`. */
7
+ export declare function addScalar(x: NumericScalar, y: NumericScalar): NumericScalar;
8
+ /** Subtract two scalar values, `x − y` (order preserved through promotion). */
9
+ export declare function subtractScalar(x: NumericScalar, y: NumericScalar): NumericScalar;
10
+ /** Multiply two scalar values, `x · y`. */
11
+ export declare function multiplyScalar(x: NumericScalar, y: NumericScalar): NumericScalar;
12
+ /** Divide two scalar values, `x ÷ y` (order preserved through promotion). */
13
+ export declare function divideScalar(x: NumericScalar, y: NumericScalar): NumericScalar;
14
+ /**
15
+ * Raise `base` to the power `exp`, treating `exp` as a real exponent.
16
+ *
17
+ * The exact `.pow()` of an exact type (Fraction/BigNumber) only supports INTEGER
18
+ * exponents. A non-integer exponent of an exact base is generally irrational, so
19
+ * it cannot stay exact — those cases fall back to double-precision `Math.pow`,
20
+ * returning a plain `number`. (Without this guard, `BigNumber.pow(0.5)` silently
21
+ * returned 1 and `Fraction.pow(0.5)` threw `BigInt(0.5)`.)
22
+ */
23
+ export declare function pow(base: NumericScalar, exp: NumericScalar): NumericScalar;
24
+ /** Absolute value. `abs(Complex)` returns the magnitude (a real number). */
25
+ export declare function abs(x: NumericScalar): NumericScalar;
26
+ /** Round toward zero (truncate). Complex components are truncated independently. */
27
+ export declare function fix(x: NumericScalar): NumericScalar;
28
+ /**
29
+ * Round to the nearest integer, half toward +∞ — matching `Math.round` and
30
+ * `Fraction.round`. `BigNumber.round` defaults to half-away-from-zero, so it is
31
+ * given `'halfCeil'` explicitly; otherwise negative half-integers would round
32
+ * type-dependently (`round(-2.5)` = −2 for number/Fraction but −3 for BigNumber).
33
+ * Complex components are rounded independently.
34
+ */
35
+ export declare function round(x: NumericScalar): NumericScalar;
36
+ /**
37
+ * Equality. Floating-point operands compare with the configured tolerance
38
+ * (`relTol`/`absTol`); exact types (Fraction, BigNumber) compare exactly —
39
+ * tolerance is meaningless for an exact rational/decimal.
40
+ */
41
+ export declare function equal(x: NumericScalar, y: NumericScalar, relTol?: number, absTol?: number): boolean;
42
+ /**
43
+ * True for values math treats as real-numeric: `number`, `bigint`, `boolean`,
44
+ * `Fraction`, `BigNumber`. Mirrors mathjs semantics — `boolean` counts (it
45
+ * coerces to 0/1), while `Complex` is intentionally NOT numeric (callers test it
46
+ * separately), so `isNumeric(complex)` is `false`. The relocated Unit uses this as
47
+ * its value-type gate (`isNumeric(value) || isComplex(value)`), and mathjs accepts
48
+ * `new Unit(true)` — so booleans must pass.
49
+ */
50
+ export declare function isNumeric(x: unknown): boolean;
51
+ /**
52
+ * Convert any scalar to a plain JS `number`. A non-real `Complex` (nonzero
53
+ * imaginary part) has no real-number value and throws.
54
+ */
55
+ export declare function number(x: NumericScalar): number;
56
+ //# sourceMappingURL=scalar.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scalar.d.ts","sourceRoot":"","sources":["../../src/arithmetic/scalar.ts"],"names":[],"mappings":"AAuBA,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAClD,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAC9C,OAAO,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+ import { Index, Matrix } from './is.js';
2
+ export type NestedArray<T> = T | NestedArray<T>[];
3
+ export interface IdentifiedValue<T> {
4
+ value: T;
5
+ identifier: number;
6
+ }
7
+ /**
8
+ * Calculate the size of a multi dimensional array.
9
+ * This function checks the size of the first entry, it does not validate
10
+ * whether all dimensions match. (use function `validate` for that)
11
+ * @param {Array} x
12
+ * @return {number[]} size
13
+ */
14
+ export declare function arraySize<T>(x: NestedArray<T>): number[];
15
+ /**
16
+ * Validate whether each element in a multi dimensional array has
17
+ * a size corresponding to the provided size array.
18
+ * @param {Array} array Array to be validated
19
+ * @param {number[]} size Array with the size of each dimension
20
+ * @throws DimensionError
21
+ */
22
+ export declare function validate<T>(array: NestedArray<T>, size: number[]): void;
23
+ /**
24
+ * Validate whether the source of the index matches the size of the Array
25
+ * @param {Array | Matrix} value Array to be validated
26
+ * @param {Index} index Index with the source information to validate
27
+ * @throws DimensionError
28
+ */
29
+ export declare function validateIndexSourceSize(value: unknown[] | Matrix, index: Index): void;
30
+ /**
31
+ * Test whether index is an integer number with index >= 0 and index < length
32
+ * when length is provided
33
+ * @param {number} index Zero-based index
34
+ * @param {number} [length] Length of the array
35
+ */
36
+ export declare function validateIndex(index: number | undefined, length?: number): void;
37
+ /**
38
+ * Test if an index has empty values
39
+ * @param {Index} index Zero-based index
40
+ */
41
+ export declare function isEmptyIndex(index: Index): boolean;
42
+ /**
43
+ * Resize a multi dimensional array. The resized array is returned.
44
+ * @param {Array | number} array Array to be resized
45
+ * @param {number[]} size Array with the size of each dimension
46
+ * @param {*} [defaultValue=0] Value to be filled in new entries,
47
+ * zero by default. Specify for example `null`,
48
+ * to clearly see entries that are not explicitly
49
+ * set.
50
+ * @return {Array} array The resized array
51
+ */
52
+ export declare function resize<T = unknown>(array: T | T[] | NestedArray<T>, size: number[], defaultValue?: T): NestedArray<T>;
53
+ /**
54
+ * Re-shape a multi dimensional array to fit the specified dimensions
55
+ * @param {Array} array Array to be reshaped
56
+ * @param {number[]} sizes List of sizes for each dimension
57
+ * @returns {Array} Array whose data has been formatted to fit the
58
+ * specified dimensions
59
+ *
60
+ * @throws {DimensionError} If the product of the new dimension sizes does
61
+ * not equal that of the old ones
62
+ */
63
+ export declare function reshape<T = unknown>(array: NestedArray<T>, sizes: number[]): NestedArray<T>;
64
+ /**
65
+ * Replaces the wildcard -1 in the sizes array.
66
+ * @param {number[]} sizes List of sizes for each dimension. At most one wildcard.
67
+ * @param {number} currentLength Number of elements in the array.
68
+ * @throws {Error} If more than one wildcard or unable to replace it.
69
+ * @returns {number[]} The sizes array with wildcard replaced.
70
+ */
71
+ export declare function processSizesWildcard(sizes: number[], currentLength: number): number[];
72
+ /**
73
+ * Squeeze a multi dimensional array
74
+ * @param {Array} array
75
+ * @param {Array} [size]
76
+ * @returns {Array} returns the array itself
77
+ */
78
+ export declare function squeeze<T>(array: NestedArray<T>, size?: number[]): T | NestedArray<T>;
79
+ /**
80
+ * Unsqueeze a multi dimensional array: add dimensions when missing
81
+ *
82
+ * Parameter `size` will be mutated to match the new, unsqueezed matrix size.
83
+ *
84
+ * @param {Array} array
85
+ * @param {number} dims Desired number of dimensions of the array
86
+ * @param {number} [outer] Number of outer dimensions to be added
87
+ * @param {Array} [size] Current size of array.
88
+ * @returns {Array} returns the array itself
89
+ * @private
90
+ */
91
+ export declare function unsqueeze<T>(array: NestedArray<T>, dims: number, outer?: number, size?: number[]): NestedArray<T>;
92
+ /**
93
+ * Flatten a multi dimensional array, put all elements in a one dimensional
94
+ * array
95
+ * @param {Array} array A multi dimensional array
96
+ * @param {boolean} isRectangular Optional. If the array is rectangular (not jagged)
97
+ * @return {Array} The flattened array (1 dimensional)
98
+ */
99
+ export declare function flatten<T>(array: NestedArray<T>, isRectangular?: boolean): T[];
100
+ /**
101
+ * A safe map
102
+ * @param {Array} array
103
+ * @param {function} callback
104
+ */
105
+ export declare function map<T, U>(array: T[], callback: (value: T, index: number, array: T[]) => U): U[];
106
+ /**
107
+ * A safe forEach
108
+ * @param {Array} array
109
+ * @param {function} callback
110
+ */
111
+ export declare function forEach<T>(array: T[], callback: (value: T, index: number, array: T[]) => void): void;
112
+ /**
113
+ * A safe filter
114
+ * @param {Array} array
115
+ * @param {function} callback
116
+ */
117
+ export declare function filter<T>(array: T[], callback: (value: T, index: number, array: T[]) => boolean): T[];
118
+ /**
119
+ * Filter values in an array given a regular expression
120
+ * @param {Array} array
121
+ * @param {RegExp} regexp
122
+ * @return {Array} Returns the filtered array
123
+ * @private
124
+ */
125
+ export declare function filterRegExp(array: string[], regexp: RegExp): string[];
126
+ /**
127
+ * A safe join
128
+ * @param {Array} array
129
+ * @param {string} separator
130
+ */
131
+ export declare function join<T>(array: T[], separator: string): string;
132
+ /**
133
+ * Assign a numeric identifier to every element of a sorted array
134
+ * @param {Array} a An array
135
+ * @return {Array} An array of objects containing the original value and its identifier
136
+ */
137
+ export declare function identify<T>(a: T[]): IdentifiedValue<T>[];
138
+ /**
139
+ * Remove the numeric identifier from the elements
140
+ * @param {array} a An array
141
+ * @return {array} An array of values without identifiers
142
+ */
143
+ export declare function generalize<T>(a: IdentifiedValue<T>[]): T[];
144
+ /**
145
+ * Check the datatype of a given object
146
+ * This is a low level implementation that should only be used by
147
+ * parent Matrix classes such as SparseMatrix or DenseMatrix
148
+ * This method does not validate Array Matrix shape
149
+ * @param {Array} array
150
+ * @param {function} typeOf Callback function to use to determine the type of a value
151
+ * @return {string}
152
+ */
153
+ export declare function getArrayDataType(array: unknown[], typeOf: (value: unknown) => string): string | undefined;
154
+ /**
155
+ * Return the last item from an array
156
+ * @param {Array} array
157
+ * @returns {*}
158
+ */
159
+ export declare function last<T>(array: T[]): T;
160
+ /**
161
+ * Get all but the last element of array.
162
+ *
163
+ * KNOWN DIVERGENCE (Bucket B slice 2): only `expression/src/utils/array.ts` had
164
+ * this; `functions/src/utils/array.ts` never defined it, and it was dead code
165
+ * even in expression (unused outside its own definition). Re-exported from
166
+ * expression's shim only — see the module header.
167
+ * @param {Array} array
168
+ * @returns {Array}
169
+ */
170
+ export declare function initial<T>(array: T[]): T[];
171
+ /**
172
+ * Concatenates many arrays in the specified direction
173
+ * @param {...Array} arrays All the arrays to concatenate
174
+ * @param {number} concatDim The dimension on which to concatenate (zero-based)
175
+ * @returns {Array}
176
+ */
177
+ export declare function concat<T>(...args: [...NestedArray<T>[], number]): NestedArray<T>[];
178
+ /**
179
+ * Receives two or more sizes and gets the broadcasted size for both.
180
+ * @param {...number[]} sizes Sizes to broadcast together
181
+ * @returns {number[]} The broadcasted size
182
+ */
183
+ export declare function broadcastSizes(...sizes: number[][]): number[];
184
+ /**
185
+ * Checks if it's possible to broadcast a size to another size
186
+ * @param {number[]} size The size of the array to check
187
+ * @param {number[]} toSize The size of the array to validate if it can be broadcasted to
188
+ */
189
+ export declare function checkBroadcastingRules(size: number[], toSize: number[]): void;
190
+ /**
191
+ * Broadcasts a single array to a certain size
192
+ * @param {Array} array Array to be broadcasted
193
+ * @param {number[]} toSize Size to broadcast the array
194
+ * @returns {Array} The broadcasted array
195
+ */
196
+ export declare function broadcastTo<T>(array: NestedArray<T>, toSize: number[]): NestedArray<T>;
197
+ /**
198
+ * Broadcasts arrays and returns the broadcasted arrays in an array
199
+ * @param {...Array | any} arrays
200
+ * @returns {Array[]} The broadcasted arrays
201
+ */
202
+ export declare function broadcastArrays<T>(...arrays: NestedArray<T>[]): NestedArray<T>[];
203
+ /**
204
+ * Stretches a matrix up to a certain size in a certain dimension
205
+ * @param {Array} arrayToStretch
206
+ * @param {number[]} sizeToStretch
207
+ * @param {number} dimToStretch
208
+ * @returns {Array} The stretched array
209
+ */
210
+ export declare function stretch<T>(arrayToStretch: NestedArray<T>, sizeToStretch: number, dimToStretch: number): NestedArray<T>;
211
+ /**
212
+ * Retrieves a single element from an array given an index.
213
+ *
214
+ * @param {Array} array - The array from which to retrieve the value.
215
+ * @param {Array<number>} index - An array of indices specifying the position of the desired element in each dimension.
216
+ * @returns {*} - The value at the specified position in the array.
217
+ *
218
+ * @example
219
+ * const arr = [[[1, 2], [3, 4]], [[5, 6], [7, 8]]];
220
+ * const index = [1, 0, 1];
221
+ * console.log(get(arr, index)); // 6
222
+ */
223
+ export declare function get<T>(array: NestedArray<T>, index: number[]): T;
224
+ /**
225
+ * Recursively maps over each element of nested array using a provided callback function.
226
+ *
227
+ * @param {Array} array - The array to be mapped.
228
+ * @param {Function} callback - The function to execute on each element, taking three arguments:
229
+ * - `value` (any): The current element being processed in the array.
230
+ * - `index` (Array<number>): The index of the current element being processed in the array.
231
+ * - `array` (Array): The array `deepMap` was called upon.
232
+ * @param {boolean} [skipIndex=false] - If true, the callback function is called with only the value.
233
+ * @returns {Array} A new array with each element being the result of the callback function.
234
+ */
235
+ export declare function deepMap<T, U>(array: NestedArray<T>, callback: ((value: T, index: number[], array: NestedArray<T>) => U) | ((value: T) => U), skipIndex?: boolean): NestedArray<U>;
236
+ /**
237
+ * Recursively iterates over each element in a multi-dimensional array and applies a callback function.
238
+ *
239
+ * @param {Array} array - The multi-dimensional array to iterate over.
240
+ * @param {Function} callback - The function to execute for each element. It receives three arguments:
241
+ * - {any} value: The current element being processed in the array.
242
+ * - {Array<number>} index: The index of the current element in each dimension.
243
+ * - {Array} array: The original array being processed.
244
+ * @param {boolean} [skipIndex=false] - If true, the callback function is called with only the value.
245
+ */
246
+ export declare function deepForEach<T>(array: NestedArray<T>, callback: ((value: T, index: number[], array: NestedArray<T>) => void) | ((value: T) => void), skipIndex?: boolean): void;
247
+ /**
248
+ * Deep clones a multidimensional array
249
+ * @param {Array} array
250
+ * @returns {Array} cloned array
251
+ */
252
+ export declare function clone<T>(array: T[]): T[];
253
+ //# sourceMappingURL=array.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"array.d.ts","sourceRoot":"","sources":["../src/array.ts"],"names":[],"mappings":"AAsBA,OAAO,EAA4C,KAAK,EAAE,MAAM,EAAkB,MAAM,SAAS,CAAC;AAOlG,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI,CAAC,GAAG,WAAW,CAAC,C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,OAAe,GACzB,IAAI,CAsCN;AAED;;;;GAIG;AACH,wBAAgB,KAAK,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,GAAG,CAAC,EAAE,CAExC"}
@@ -0,0 +1,135 @@
1
+ /**
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.
7
+ */
8
+ export interface BigNumberValue {
9
+ e: number;
10
+ constructor: new (value: number | string) => BigNumberValue;
11
+ isFinite(): boolean;
12
+ isNaN(): boolean;
13
+ isZero(): boolean;
14
+ 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;
22
+ toNumber(): number;
23
+ toFixed(places?: number): string;
24
+ toExponential(places?: number): string;
25
+ toPrecision(sd?: number): string;
26
+ toSignificantDigits(sd?: number): BigNumberValue;
27
+ toBinary(): string;
28
+ toOctal(): string;
29
+ toHexadecimal(): string;
30
+ }
31
+ /**
32
+ * Convert a BigNumber to a formatted string representation.
33
+ *
34
+ * Syntax:
35
+ *
36
+ * format(value)
37
+ * format(value, options)
38
+ * format(value, precision)
39
+ * format(value, fn)
40
+ *
41
+ * Where:
42
+ *
43
+ * {number} value The value to be formatted
44
+ * {Object} options An object with formatting options. Available options:
45
+ * {string} notation
46
+ * Number notation. Choose from:
47
+ * 'fixed' Always use regular number notation.
48
+ * For example '123.40' and '14000000'
49
+ * 'exponential' Always use exponential notation.
50
+ * For example '1.234e+2' and '1.4e+7'
51
+ * 'auto' (default) Regular number notation for numbers
52
+ * having an absolute value between
53
+ * `lower` and `upper` bounds, and uses
54
+ * exponential notation elsewhere.
55
+ * Lower bound is included, upper bound
56
+ * is excluded.
57
+ * For example '123.4' and '1.4e7'.
58
+ * 'bin', 'oct, or
59
+ * 'hex' Format the number using binary, octal,
60
+ * or hexadecimal notation.
61
+ * For example '0b1101' and '0x10fe'.
62
+ * {number} wordSize The word size in bits to use for formatting
63
+ * in binary, octal, or hexadecimal notation.
64
+ * To be used only with 'bin', 'oct', or 'hex'
65
+ * values for 'notation' option. When this option
66
+ * is defined the value is formatted as a signed
67
+ * twos complement integer of the given word size
68
+ * and the size suffix is appended to the output.
69
+ * For example
70
+ * format(-1, {notation: 'hex', wordSize: 8}) === '0xffi8'.
71
+ * Default value is undefined.
72
+ * {number} precision A number between 0 and 16 to round
73
+ * the digits of the number.
74
+ * In case of notations 'exponential',
75
+ * 'engineering', and 'auto',
76
+ * `precision` defines the total
77
+ * number of significant digits returned.
78
+ * In case of notation 'fixed',
79
+ * `precision` defines the number of
80
+ * significant digits after the decimal
81
+ * point.
82
+ * `precision` is undefined by default.
83
+ * {number} lowerExp Exponent determining the lower boundary
84
+ * for formatting a value with an exponent
85
+ * when `notation='auto`.
86
+ * Default value is `-3`.
87
+ * {number} upperExp Exponent determining the upper boundary
88
+ * for formatting a value with an exponent
89
+ * when `notation='auto`.
90
+ * Default value is `5`.
91
+ * {Function} fn A custom formatting function. Can be used to override the
92
+ * built-in notations. Function `fn` is called with `value` as
93
+ * parameter and must return a string. Is useful for example to
94
+ * format all values inside a matrix in a particular way.
95
+ *
96
+ * Examples:
97
+ *
98
+ * format(6.4) // '6.4'
99
+ * format(1240000) // '1.24e6'
100
+ * format(1/3) // '0.3333333333333333'
101
+ * format(1/3, 3) // '0.333'
102
+ * format(21385, 2) // '21000'
103
+ * format(12e8, {notation: 'fixed'}) // returns '1200000000'
104
+ * format(2.3, {notation: 'fixed', precision: 4}) // returns '2.3000'
105
+ * format(52.8, {notation: 'exponential'}) // returns '5.28e+1'
106
+ * format(12400, {notation: 'engineering'}) // returns '12.400e+3'
107
+ *
108
+ * @param {BigNumber} value
109
+ * @param {Object | Function | number | BigNumber} [options]
110
+ * @return {string} str The formatted value
111
+ */
112
+ export declare function format(value: unknown, options?: unknown): string;
113
+ /**
114
+ * Format a BigNumber in engineering notation. Like '1.23e+6', '2.3e+0', '3.500e-3'
115
+ * @param {BigNumber} value
116
+ * @param {number} [precision] Optional number of significant figures to return.
117
+ */
118
+ export declare function toEngineering(value: BigNumberValue, precision?: number): string;
119
+ /**
120
+ * Format a number in exponential notation. Like '1.23e+5', '2.3e+0', '3.500e-3'
121
+ * @param {BigNumber} value
122
+ * @param {number} [precision] Number of digits in formatted output.
123
+ * If not provided, the maximum available digits
124
+ * is used.
125
+ * @returns {string} str
126
+ */
127
+ export declare function toExponential(value: BigNumberValue, precision?: number): string;
128
+ /**
129
+ * Format a number with fixed notation.
130
+ * @param {BigNumber} value
131
+ * @param {number} [precision=undefined] Optional number of decimals after the
132
+ * decimal point. Undefined by default.
133
+ */
134
+ export declare function toFixed(value: BigNumberValue, precision?: number): string;
135
+ //# sourceMappingURL=bignumber-formatter.d.ts.map
@@ -0,0 +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,GAAG,OAAO,CAAC;IACrD,QAAQ,CAAC,KAAK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