@danielsimonjr/mathts-core 0.14.3 → 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 (89) 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/collection.d.ts +67 -0
  8. package/dist/collection.d.ts.map +1 -0
  9. package/dist/config.d.ts +17 -0
  10. package/dist/config.d.ts.map +1 -0
  11. package/dist/constants.d.ts +30 -0
  12. package/dist/constants.d.ts.map +1 -0
  13. package/dist/customs.d.ts +44 -0
  14. package/dist/customs.d.ts.map +1 -0
  15. package/dist/error/DimensionError.d.ts +26 -0
  16. package/dist/error/DimensionError.d.ts.map +1 -0
  17. package/dist/error/IndexError.d.ts +33 -0
  18. package/dist/error/IndexError.d.ts.map +1 -0
  19. package/dist/error/MathjsError.d.ts +13 -0
  20. package/dist/error/MathjsError.d.ts.map +1 -0
  21. package/dist/factory/factory.d.ts +154 -0
  22. package/dist/factory/factory.d.ts.map +1 -0
  23. package/dist/factory/index.d.ts +6 -0
  24. package/dist/factory/index.d.ts.map +1 -0
  25. package/dist/factory.d.ts +112 -0
  26. package/dist/factory.d.ts.map +1 -0
  27. package/dist/index.d.ts +24 -2593
  28. package/dist/index.d.ts.map +1 -0
  29. package/dist/index.js +22 -13
  30. package/dist/internal.d.ts +33 -1344
  31. package/dist/internal.d.ts.map +1 -0
  32. package/dist/is.d.ts +102 -0
  33. package/dist/is.d.ts.map +1 -0
  34. package/dist/map.d.ts +113 -0
  35. package/dist/map.d.ts.map +1 -0
  36. package/dist/number.d.ts +314 -0
  37. package/dist/number.d.ts.map +1 -0
  38. package/dist/numeric/stable.d.ts +130 -0
  39. package/dist/numeric/stable.d.ts.map +1 -0
  40. package/dist/object.d.ts +119 -0
  41. package/dist/object.d.ts.map +1 -0
  42. package/dist/shared.d.ts +41 -0
  43. package/dist/shared.d.ts.map +1 -0
  44. package/dist/string.d.ts +70 -0
  45. package/dist/string.d.ts.map +1 -0
  46. package/dist/switch.d.ts +9 -0
  47. package/dist/switch.d.ts.map +1 -0
  48. package/dist/typed/index.d.ts +7 -0
  49. package/dist/typed/index.d.ts.map +1 -0
  50. package/dist/typed/mathts-typed.d.ts +246 -0
  51. package/dist/typed/mathts-typed.d.ts.map +1 -0
  52. package/dist/typed/type-bridge.d.ts +2 -0
  53. package/dist/typed/type-bridge.d.ts.map +1 -0
  54. package/dist/types/bignumber.d.ts +367 -0
  55. package/dist/types/bignumber.d.ts.map +1 -0
  56. package/dist/types/complex.d.ts +284 -0
  57. package/dist/types/complex.d.ts.map +1 -0
  58. package/dist/types/dual-rules.d.ts +129 -0
  59. package/dist/types/dual-rules.d.ts.map +1 -0
  60. package/dist/types/dual.d.ts +36 -0
  61. package/dist/types/dual.d.ts.map +1 -0
  62. package/dist/types/fraction.d.ts +215 -0
  63. package/dist/types/fraction.d.ts.map +1 -0
  64. package/dist/types/interfaces.d.ts +143 -0
  65. package/dist/types/interfaces.d.ts.map +1 -0
  66. package/dist/types/matrix/Range.d.ts +767 -0
  67. package/dist/types/matrix/Range.d.ts.map +1 -0
  68. package/dist/types/unit/Unit.d.ts +3 -0
  69. package/dist/types/unit/Unit.d.ts.map +1 -0
  70. package/dist/types/unit/dependencies.d.ts +4 -0
  71. package/dist/types/unit/dependencies.d.ts.map +1 -0
  72. package/dist/types/unit/errors.d.ts +18 -0
  73. package/dist/types/unit/errors.d.ts.map +1 -0
  74. package/dist/types/unit/index.d.ts +7 -0
  75. package/dist/types/unit/index.d.ts.map +1 -0
  76. package/dist/types/unit/unit-types.d.ts +231 -0
  77. package/dist/types/unit/unit-types.d.ts.map +1 -0
  78. package/dist/types/unit-definitions.d.ts +79 -0
  79. package/dist/types/unit-definitions.d.ts.map +1 -0
  80. package/dist/types/unit-prefixes.d.ts +29 -0
  81. package/dist/types/unit-prefixes.d.ts.map +1 -0
  82. package/dist/types/unit.d.ts +28 -0
  83. package/dist/types/unit.d.ts.map +1 -0
  84. package/dist/types/wasm-loader.d.ts +35 -0
  85. package/dist/types/wasm-loader.d.ts.map +1 -0
  86. package/dist/wasm-loader.d.ts +97 -0
  87. package/dist/wasm-loader.d.ts.map +1 -0
  88. package/package.json +8 -8
  89. package/dist/index-B4LIOfHN.d.ts +0 -449
@@ -1,1345 +1,34 @@
1
- import { F as FactoryFunction, b as UnitConstructor, c as UnitDependencies, I as Index, M as Matrix$1 } from './index-B4LIOfHN.js';
2
- export { B as BaseUnitDef, d as BigNumber, e as BigNumberConstructor, C as Complex, f as ComplexConstructor, g as ComplexValue, h as ConverterFn, U as CoreUnit, j as CreateFunction, k as CreateUnitDefObject, l as CreateUnitOptions, D as DenseMatrix, m as DependencyName, n as FactoryMeta, o as Fraction, p as FractionConstructor, q as FractionValue, r as IndexDimension, L as LegacyFactory, N as Numeric, P as ParseOptions, s as PrefixDef, t as PrefixTable, R as Range, S as ScalarBinaryOp, u as ScalarUnaryOp, v as SparseMatrix, w as SubtractScalar, T as TypeConverters, x as Unit, y as UnitComponent, z as UnitConfig, A as UnitDef, E as UnitFormatOptions, a as UnitInstance, G as UnitJSON, H as UnitSystem, J as UnitSystemEntry, K as assertDependencies, O as create, Q as factory, V as isArray, W as isBigInt, X as isBigNumber, Y as isBoolean, Z as isCollection, _ as isComplex, $ as isDate, a0 as isDenseMatrix, a1 as isFactory, a2 as isFraction, a3 as isFunction, a4 as isIndex, a5 as isMap, a6 as isMatrix, a7 as isNull, a8 as isNumber, a9 as isObject, aa as isOptionalDependency, ab as isRange, ac as isRegExp, ad as isSparseMatrix, ae as isString, af as isUndefined, i as isUnit, ag as sortFactories, ah as stripOptionalNotation, ai as typeOf } from './index-B4LIOfHN.js';
3
-
4
- declare const createUnitClass: FactoryFunction<UnitConstructor>;
5
-
6
- /** The full dependency bundle for `createUnitClass`. */
7
- declare const unitDependencies: UnitDependencies;
8
-
9
1
  /**
10
- * Split value representation with sign, coefficients, and exponent
11
- */
12
- interface SplitValue {
13
- sign: '+' | '-' | '';
14
- coefficients: number[];
15
- exponent: number;
16
- }
17
- /**
18
- * Configuration for number type handling
19
- */
20
- interface NumberTypeConfig {
21
- number: 'number' | 'BigNumber' | 'bigint' | 'Fraction';
22
- numberFallback: 'number' | 'BigNumber';
23
- }
24
- /**
25
- * Format options for number formatting
26
- */
27
- interface FormatOptions {
28
- notation?: 'auto' | 'exponential' | 'fixed' | 'engineering' | 'bin' | 'oct' | 'hex';
29
- precision?: number;
30
- wordSize?: number;
31
- lowerExp?: number;
32
- upperExp?: number;
33
- }
34
- /**
35
- * Normalized format options
36
- */
37
- interface NormalizedFormatOptions {
38
- notation: 'auto' | 'exponential' | 'fixed' | 'engineering' | 'bin' | 'oct' | 'hex';
39
- precision: number | undefined;
40
- wordSize: number | undefined;
41
- }
42
- /**
43
- * Check if a number is integer
44
- * @param value The value to check
45
- * @return true if value is an integer
46
- */
47
- declare function isInteger(value: number | boolean): boolean;
48
- /**
49
- * Ensure the number type is compatible with the provided value.
50
- * If not, return 'number' instead.
51
- *
52
- * For example:
53
- *
54
- * safeNumberType('2.3', { number: 'bigint', numberFallback: 'number' })
55
- *
56
- * will return 'number' and not 'bigint' because trying to create a bigint with
57
- * value 2.3 would throw an exception.
58
- *
59
- * @param numberStr The number as a string
60
- * @param config Configuration with number type preferences
61
- * @returns The safe number type to use
62
- */
63
- declare function safeNumberType(numberStr: string, config: NumberTypeConfig): 'number' | 'BigNumber' | 'bigint' | 'Fraction';
64
- /**
65
- * Calculate the sign of a number
66
- * @param x The number
67
- * @returns 1 for positive, -1 for negative, 0 for zero
68
- */
69
- declare const sign: (x: number) => number;
70
- /**
71
- * Calculate the base-2 logarithm of a number
72
- * @param x The number
73
- * @returns The base-2 logarithm
74
- */
75
- declare const log2: (x: number) => number;
76
- /**
77
- * Calculate the base-10 logarithm of a number
78
- * @param x The number
79
- * @returns The base-10 logarithm
80
- */
81
- declare const log10: (x: number) => number;
82
- /**
83
- * Calculate the natural logarithm of a number + 1
84
- * @param x The number
85
- * @returns ln(x + 1)
86
- */
87
- declare const log1p: (x: number) => number;
88
- /**
89
- * Calculate cubic root for a number
90
- *
91
- * Code from es6-shim.js:
92
- * https://github.com/paulmillr/es6-shim/blob/master/es6-shim.js#L1564-L1577
93
- *
94
- * @param x The number
95
- * @returns The cubic root of x
96
- */
97
- declare const cbrt: (x: number) => number;
98
- /**
99
- * Calculates exponentiation minus 1
100
- * @param x The exponent
101
- * @return exp(x) - 1
102
- */
103
- declare const expm1: (x: number) => number;
104
- /**
105
- * Convert a number to a formatted string representation.
106
- *
107
- * Syntax:
108
- *
109
- * format(value)
110
- * format(value, options)
111
- * format(value, precision)
112
- * format(value, fn)
113
- *
114
- * Where:
115
- *
116
- * {number} value The value to be formatted
117
- * {Object} options An object with formatting options. Available options:
118
- * {string} notation
119
- * Number notation. Choose from:
120
- * 'fixed' Always use regular number notation.
121
- * For example '123.40' and '14000000'
122
- * 'exponential' Always use exponential notation.
123
- * For example '1.234e+2' and '1.4e+7'
124
- * 'engineering' Always use engineering notation.
125
- * For example '123.4e+0' and '14.0e+6'
126
- * 'auto' (default) Regular number notation for numbers
127
- * having an absolute value between
128
- * `lowerExp` and `upperExp` bounds, and
129
- * uses exponential notation elsewhere.
130
- * Lower bound is included, upper bound
131
- * is excluded.
132
- * For example '123.4' and '1.4e7'.
133
- * 'bin', 'oct, or
134
- * 'hex' Format the number using binary, octal,
135
- * or hexadecimal notation.
136
- * For example '0b1101' and '0x10fe'.
137
- * {number} wordSize The word size in bits to use for formatting
138
- * in binary, octal, or hexadecimal notation.
139
- * To be used only with 'bin', 'oct', or 'hex'
140
- * values for 'notation' option. When this option
141
- * is defined the value is formatted as a signed
142
- * twos complement integer of the given word size
143
- * and the size suffix is appended to the output.
144
- * For example
145
- * format(-1, {notation: 'hex', wordSize: 8}) === '0xffi8'.
146
- * Default value is undefined.
147
- * {number} precision A number between 0 and 16 to round
148
- * the digits of the number.
149
- * In case of notations 'exponential',
150
- * 'engineering', and 'auto',
151
- * `precision` defines the total
152
- * number of significant digits returned.
153
- * In case of notation 'fixed',
154
- * `precision` defines the number of
155
- * significant digits after the decimal
156
- * point.
157
- * `precision` is undefined by default,
158
- * not rounding any digits.
159
- * {number} lowerExp Exponent determining the lower boundary
160
- * for formatting a value with an exponent
161
- * when `notation='auto`.
162
- * Default value is `-3`.
163
- * {number} upperExp Exponent determining the upper boundary
164
- * for formatting a value with an exponent
165
- * when `notation='auto`.
166
- * Default value is `5`.
167
- * {Function} fn A custom formatting function. Can be used to override the
168
- * built-in notations. Function `fn` is called with `value` as
169
- * parameter and must return a string. Is useful for example to
170
- * format all values inside a matrix in a particular way.
171
- *
172
- * Examples:
173
- *
174
- * format(6.4) // '6.4'
175
- * format(1240000) // '1.24e6'
176
- * format(1/3) // '0.3333333333333333'
177
- * format(1/3, 3) // '0.333'
178
- * format(21385, 2) // '21000'
179
- * format(12.071, {notation: 'fixed'}) // '12'
180
- * format(2.3, {notation: 'fixed', precision: 2}) // '2.30'
181
- * format(52.8, {notation: 'exponential'}) // '5.28e+1'
182
- * format(12345678, {notation: 'engineering'}) // '12.345678e+6'
183
- *
184
- * @param value The number to format
185
- * @param options Optional formatting options or custom formatter function or precision
186
- * @return The formatted value
187
- */
188
- declare function format$2(value: number, options?: FormatOptions | ((value: number) => string) | number): string;
189
- /**
190
- * Normalize format options into an object:
191
- * {
192
- * notation: string,
193
- * precision: number | undefined,
194
- * wordSize: number | undefined
195
- * }
196
- * @param options The input options
197
- * @returns Normalized format options
198
- */
199
- declare function normalizeFormatOptions(options?: FormatOptions | number): NormalizedFormatOptions;
200
- /**
201
- * Split a number into sign, coefficients, and exponent
202
- * @param value The number or string to split
203
- * @return Object containing sign, coefficients, and exponent
204
- */
205
- declare function splitNumber(value: number | string): SplitValue;
206
- /**
207
- * Format a number in engineering notation. Like '1.23e+6', '2.3e+0', '3.500e-3'
208
- * @param value The number or string to format
209
- * @param precision Optional number of significant figures to return
210
- * @returns The formatted string
211
- */
212
- declare function toEngineering$1(value: number | string, precision?: number): string;
213
- /**
214
- * Format a number with fixed notation.
215
- * @param value The number or string to format
216
- * @param precision Optional number of decimals after the decimal point
217
- * @returns The formatted string
218
- */
219
- declare function toFixed$1(value: number | string, precision?: number): string;
220
- /**
221
- * Format a number in exponential notation. Like '1.23e+5', '2.3e+0', '3.500e-3'
222
- * @param value The number or string to format
223
- * @param precision Number of digits in formatted output
224
- * @returns The formatted string
225
- */
226
- declare function toExponential$1(value: number | string, precision?: number): string;
227
- /**
228
- * Format a number with a certain precision
229
- * @param value The number or string to format
230
- * @param precision Optional number of digits
231
- * @param options Optional formatting options (lowerExp, upperExp)
232
- * @return The formatted string
233
- */
234
- declare function toPrecision(value: number | string, precision?: number, options?: FormatOptions): string;
235
- /**
236
- * Round the number of digits of a number
237
- * @param split A value split with .splitNumber(value)
238
- * @param precision A positive integer
239
- * @return Object containing sign, coefficients, and exponent with rounded digits
240
- */
241
- declare function roundDigits(split: SplitValue, precision?: number): SplitValue;
242
- /**
243
- * Count the number of significant digits of a number.
244
- *
245
- * For example:
246
- * 2.34 returns 3
247
- * 0.0034 returns 2
248
- * 120.5e+30 returns 4
249
- *
250
- * @param value The number
251
- * @return Number of significant digits
252
- */
253
- declare function digits(value: number): number;
254
- /**
255
- * Compares two floating point numbers.
256
- * @param a First value to compare
257
- * @param b Second value to compare
258
- * @param relTol The relative tolerance, indicating the maximum allowed difference relative to the larger absolute value. Must be greater than 0.
259
- * @param absTol The minimum absolute tolerance, useful for comparisons near zero. Must be at least 0.
260
- * @return whether the two numbers are nearly equal
261
- *
262
- * @throws Error If `relTol` is less than or equal to 0.
263
- * @throws Error If `absTol` is less than 0.
264
- *
265
- * @example
266
- * nearlyEqual(1.000000001, 1.0, 1e-8); // true
267
- * nearlyEqual(1.000000002, 1.0, 0); // false
268
- * nearlyEqual(1.0, 1.009, undefined, 0.01); // true
269
- * nearlyEqual(0.000000001, 0.0, undefined, 1e-8); // true
270
- */
271
- declare function nearlyEqual(a: number, b: number, relTol?: number, absTol?: number): boolean;
272
- /**
273
- * Calculate the hyperbolic arccos of a number
274
- * @param x The number
275
- * @return The hyperbolic arccosine
276
- */
277
- declare const acosh: (x: number) => number;
278
- /**
279
- * Calculate the hyperbolic arcsine of a number
280
- * @param x The number
281
- * @return The hyperbolic arcsine
282
- */
283
- declare const asinh: (x: number) => number;
284
- /**
285
- * Calculate the hyperbolic arctangent of a number
286
- * @param x The number
287
- * @return The hyperbolic arctangent
288
- */
289
- declare const atanh: (x: number) => number;
290
- /**
291
- * Calculate the hyperbolic cosine of a number
292
- * @param x The number
293
- * @returns The hyperbolic cosine
294
- */
295
- declare const cosh: (x: number) => number;
296
- /**
297
- * Calculate the hyperbolic sine of a number
298
- * @param x The number
299
- * @returns The hyperbolic sine
300
- */
301
- declare const sinh: (x: number) => number;
302
- /**
303
- * Calculate the hyperbolic tangent of a number
304
- * @param x The number
305
- * @returns The hyperbolic tangent
306
- */
307
- declare const tanh: (x: number) => number;
308
- /**
309
- * Returns a value with the magnitude of x and the sign of y.
310
- * @param x The value providing the magnitude
311
- * @param y The value providing the sign
312
- * @returns Value with magnitude of x and sign of y
313
- */
314
- declare function copysign(x: number, y: number): number;
315
- /**
316
- * Check if x^y is 0 due to infinity
317
- * @param x The base
318
- * @param y The exponent
319
- * @returns true if x^y is 0 due to infinity
320
- */
321
- declare function isPowZeroAtInfinity(x: number, y: number): boolean;
322
-
323
- /**
324
- * Shared utility functions used across core utility modules.
325
- * This file must have ZERO imports from other core utility files
326
- * to serve as the base of the dependency graph and break circular imports.
327
- */
328
- /**
329
- * A safe hasOwnProperty
330
- * @param {Object} object
331
- * @param {string} property
332
- */
333
- declare function hasOwnProperty(object: unknown, property: string): boolean;
334
- /**
335
- * True when `text` ends with `search`. (Equivalent to `String.prototype.endsWith`;
336
- * kept as a named helper so relocated modules read the same as their mathjs origin.)
337
- */
338
- declare function endsWith(text: string, search: string): boolean;
339
- /**
340
- * Warn to the console at most once per distinct message, deduped for the process
341
- * lifetime. Used for deprecation notices (e.g. `Unit.toNumber`).
342
- */
343
- declare const warnOnce: (...args: unknown[]) => void;
344
- /** A function whose results are cached; clear the cache with `delete fn.cache`. */
345
- interface MemoizedFunction {
346
- (...args: unknown[]): unknown;
347
- cache?: Map<string, unknown>;
348
- }
349
- /**
350
- * Memoize a pure function, caching results in a `Map` keyed by a string hash of the
351
- * arguments (default `JSON.stringify`; override via `hasher`). Pass `limit` to bound
352
- * the cache to N most-recently-used entries (LRU eviction via `Map` insertion order —
353
- * on a hit the key is moved to the most-recent end; on overflow the oldest key is
354
- * dropped); omit for an unbounded cache. The cache is exposed as `fn.cache` and can be
355
- * reset with `delete fn.cache` — the next call lazily recreates it. (The relocated
356
- * `Unit` relies on that reset when `createUnit`/`deleteUnit` invalidate the unit-name
357
- * lookup cache, and passes `limit: 100` to bound the parse cache.)
358
- */
359
- declare function memoize(fn: (...args: unknown[]) => unknown, { hasher, limit }?: {
360
- hasher?: (args: unknown[]) => string;
361
- limit?: number;
362
- }): MemoizedFunction;
363
-
364
- /**
365
- * Clone an object
366
- *
367
- * clone(x)
368
- *
369
- * Can clone any primitive type, array, and object.
370
- * If x has a function clone, this function will be invoked to clone the object.
371
- *
372
- * @param {*} x
373
- * @return {*} clone
374
- */
375
- declare function clone$1<T>(x: T): T;
376
- /**
377
- * Apply map to all properties of an object
378
- * @param {Object} object
379
- * @param {function} callback
380
- * @return {Object} Returns a copy of the object with mapped properties
381
- */
382
- declare function mapObject<T, U>(object: Record<string, T>, callback: (value: T) => U): Record<string, U>;
383
- /**
384
- * Extend object a with the properties of object b
385
- * @param {Object} a
386
- * @param {Object} b
387
- * @return {Object} a
388
- */
389
- declare function extend<T extends Record<string, unknown>, U extends Record<string, unknown>>(a: T, b: U): T & U;
390
- /**
391
- * Deep extend an object a with the properties of object b
392
- * @param {Object} a
393
- * @param {Object} b
394
- * @returns {Object}
395
- */
396
- declare function deepExtend<T>(a: T, b: unknown): T;
397
- /**
398
- * Deep test equality of all fields in two pairs of arrays or objects.
399
- * Compares values and functions strictly (ie. 2 is not the same as '2').
400
- * @param {Array | Object} a
401
- * @param {Array | Object} b
402
- * @returns {boolean}
403
- */
404
- declare function deepStrictEqual(a: unknown, b: unknown): boolean;
405
- /**
406
- * Recursively flatten a nested object.
407
- * @param {Object} nestedObject
408
- * @return {Object} Returns the flattened object
409
- */
410
- declare function deepFlatten(nestedObject: Record<string, unknown>): Record<string, unknown>;
411
- /**
412
- * Test whether the current JavaScript engine supports Object.defineProperty
413
- * @returns {boolean} returns true if supported
414
- */
415
- declare function canDefineProperty(): boolean;
416
- /**
417
- * Attach a lazy loading property to a constant.
418
- * The given function `fn` is called once when the property is first requested.
419
- *
420
- * @param {Object} object Object where to add the property
421
- * @param {string} prop Property name
422
- * @param {Function} valueResolver Function returning the property value. Called
423
- * without arguments.
424
- */
425
- declare function lazy<T>(object: Record<string, unknown>, prop: string, valueResolver: () => T): void;
426
- /**
427
- * Traverse a path into an object.
428
- * When a namespace is missing, it will be created
429
- * @param {Object} object
430
- * @param {string | string[]} path A dot separated string like 'name.space'
431
- * @return {Object} Returns the object at the end of the path
432
- */
433
- declare function traverse(object: Record<string, unknown>, path: string | string[]): Record<string, unknown>;
434
-
435
- /**
436
- * Test whether an object is a factory. a factory has fields:
437
- *
438
- * - factory: function (type: Object, config: Object, load: function, typed: function [, math: Object]) (required)
439
- * - name: string (optional)
440
- * - path: string A dot separated path (optional)
441
- * - math: boolean If true (false by default), the math namespace is passed
442
- * as fifth argument of the factory function
443
- *
444
- * @param {*} object
445
- * @returns {boolean}
446
- */
447
- declare function isLegacyFactory(object: unknown): boolean;
448
- /**
449
- * Get a nested property from an object
450
- * @param {Object} object
451
- * @param {string | string[]} path
452
- * @returns {Object}
453
- */
454
- declare function get$1(object: Record<string, unknown>, path: string | string[]): unknown;
455
- /**
456
- * Set a nested property in an object
457
- * Mutates the object itself
458
- * If the path doesn't exist, it will be created
459
- * @param {Object} object
460
- * @param {string | string[]} path
461
- * @param {*} value
462
- * @returns {Object}
463
- */
464
- declare function set<T extends Record<string, unknown>>(object: T, path: string | string[], value: unknown): T;
465
- /**
466
- * Create an object composed of the picked object properties
467
- * @param {Object} object
468
- * @param {string[]} properties
469
- * @param {function} [transform] Optional value to transform a value when picking it
470
- * @return {Object}
471
- */
472
- declare function pick(object: Record<string, unknown>, properties: string[], transform?: (value: unknown, key: string) => unknown): Record<string, unknown>;
473
- /**
474
- * Shallow version of pick, creating an object composed of the picked object properties
475
- * but not for nested properties
476
- * @param {Object} object
477
- * @param {string[]} properties
478
- * @return {Object}
479
- */
480
- declare function pickShallow(object: Record<string, unknown>, properties: string[]): Record<string, unknown>;
481
-
482
- /**
483
- * Configuration interface for math.js
484
- */
485
- interface ConfigOptions {
486
- relTol: number;
487
- absTol: number;
488
- matrix: 'Matrix' | 'Array';
489
- number: 'number' | 'BigNumber' | 'bigint' | 'Fraction';
490
- numberFallback: 'number' | 'BigNumber';
491
- precision: number;
492
- predictable: boolean;
493
- randomSeed: string | null;
494
- legacySubset: boolean;
495
- }
496
- type MathJsConfig = ConfigOptions;
497
- declare const DEFAULT_CONFIG: ConfigOptions;
498
-
499
- /**
500
- * Custom error type for Mathjs errors
501
- * @extends Error
502
- */
503
- declare class MathjsError extends Error {
504
- isMathjsError: true;
505
- /**
506
- * Create a MathjsError
507
- * @param message Error message
508
- */
509
- constructor(message: string);
510
- }
511
-
512
- /**
513
- * Create a range error with the message:
514
- * 'Dimension mismatch (<actual size> != <expected size>)'
515
- * Or with a custom message when called with a single string argument.
516
- *
517
- * The single canonical `DimensionError` for the whole monorepo (Bucket B, commit 1),
518
- * exposed via the `@danielsimonjr/mathts-core/internal` subpath. `expression/src/error/
519
- * DimensionError.ts` and `functions/src/error/DimensionError.ts` are now thin
520
- * re-export shims of this class — a `DimensionError` thrown in one package is
521
- * `instanceof DimensionError` in any other, since there is only ever one class
522
- * identity. `core/src/array.ts` (and the ~20 other call sites across matrix algos,
523
- * subset, resize, concat, reshape, ...) all throw this same class.
524
- */
525
- declare class DimensionError extends RangeError {
526
- actual?: number | number[];
527
- expected?: number | number[];
528
- relation?: string;
529
- isDimensionError: true;
530
- /**
531
- * @param actual - The actual size or custom error message
532
- * @param expected - The expected size (optional if actual is a custom message)
533
- * @param relation - Optional relation between actual and expected size: '!=', '<', etc.
534
- */
535
- constructor(actual: number | number[] | string, expected?: number | number[], relation?: string);
536
- }
537
-
538
- /**
539
- * Custom error type for index out of range errors.
540
- *
541
- * The single canonical `IndexError` for the whole monorepo (Bucket B, commit 1),
542
- * exposed via the `@danielsimonjr/mathts-core/internal` subpath. `expression/src/error/
543
- * IndexError.ts` and `functions/src/error/IndexError.ts` are now thin re-export shims
544
- * of this class — an `IndexError` thrown in one package is `instanceof IndexError`
545
- * in any other, since there is only ever one class identity. `core/src/array.ts` /
546
- * `core/src/collection.ts` (and the many other call sites across concat, subset,
547
- * cumsum, mapSlices, ...) all throw this same class.
548
- *
549
- * @extends RangeError
550
- */
551
- declare class IndexError extends RangeError {
552
- index: number;
553
- min: number | undefined;
554
- max: number | undefined;
555
- isIndexError: true;
556
- /**
557
- * Create an IndexError
558
- *
559
- * Can be called in two ways:
560
- * - IndexError(index, max) - assumes min=0
561
- * - IndexError(index, min, max)
562
- *
563
- * @param index The actual index
564
- * @param min Minimum index (included), or max if only 2 args provided
565
- * @param max Maximum index (excluded)
566
- */
567
- constructor(index: number, min?: number, max?: number);
568
- }
569
- declare function createIndexError(index: number, min?: number, max?: number): IndexError;
570
-
571
- /**
572
- * Formatting options accepted by the generic `format` helper. Extends the
573
- * numeric {@link FormatOptions} with the string-level `truncate` and the
574
- * fraction rendering mode, or is a precision number, or a custom formatter.
575
- */
576
- type GeneralFormatOptions = number | ((value: unknown) => string) | (FormatOptions & {
577
- truncate?: number;
578
- fraction?: 'ratio' | 'decimal';
579
- });
580
- /**
581
- * Format a value of any type into a string.
582
- *
583
- * Usage:
584
- * math.format(value)
585
- * math.format(value, precision)
586
- * math.format(value, options)
587
- *
588
- * When value is a function:
589
- *
590
- * - When the function has a property `syntax`, it returns this
591
- * syntax description.
592
- * - In other cases, a string `'function'` is returned.
593
- *
594
- * When `value` is an Object:
595
- *
596
- * - When the object contains a property `format` being a function, this
597
- * function is invoked as `value.format(options)` and the result is returned.
598
- * - When the object has its own `toString` method, this method is invoked
599
- * and the result is returned.
600
- * - In other cases the function will loop over all object properties and
601
- * return JSON object notation like '{"a": 2, "b": 3}'.
602
- *
603
- * Example usage:
604
- * math.format(2/7) // '0.2857142857142857'
605
- * math.format(math.pi, 3) // '3.14'
606
- * math.format(new Complex(2, 3)) // '2 + 3i'
607
- * math.format('hello') // '"hello"'
608
- *
609
- * @param {*} value Value to be stringified
610
- * @param {Object | number | Function} [options]
611
- * Formatting options. See src/utils/number.js:format for a
612
- * description of the available options controlling number output.
613
- * This generic "format" also supports the option property `truncate: NN`
614
- * giving the maximum number NN of characters to return (if there would
615
- * have been more, they are deleted and replaced by an ellipsis).
616
- * @return {string} str
617
- */
618
- declare function format$1(value: unknown, options?: unknown): string;
619
- /**
620
- * Stringify a value into a string enclosed in double quotes.
621
- * Unescaped double quotes and backslashes inside the value are escaped.
622
- * @param {*} value
623
- * @return {string}
624
- */
625
- declare function stringify(value: unknown): string;
626
- /**
627
- * Escape special HTML characters
628
- * @param {*} value
629
- * @return {string}
630
- */
631
- declare function escape(value: unknown): string;
632
- /**
633
- * Compare two strings
634
- * @param {string} x
635
- * @param {string} y
636
- * @returns {number}
637
- */
638
- declare function compareText(x: unknown, y: unknown): number;
639
-
640
- /**
641
- * Structural contract for the BigNumber values handled by this formatter.
642
- * Captures exactly the methods/properties used here. The configured BigNumber
643
- * implementation (e.g. decimal.js) provides these; the project's `BigNumber`
644
- * type alias points at a minimal local Decimal that does not declare them all,
645
- * so we model the runtime contract explicitly.
646
- */
647
- interface BigNumberValue {
648
- e: number;
649
- constructor: new (value: number | string) => BigNumberValue;
650
- isFinite(): boolean;
651
- isNaN(): boolean;
652
- isZero(): boolean;
653
- isInteger(): boolean;
654
- gt(other: number | BigNumberValue): boolean;
655
- greaterThan(other: number | BigNumberValue): boolean;
656
- lessThan(other: number | BigNumberValue): boolean;
657
- add(other: number | BigNumberValue): BigNumberValue;
658
- sub(other: number | BigNumberValue): BigNumberValue;
659
- mul(other: number | BigNumberValue): BigNumberValue;
660
- pow(exp: number | BigNumberValue): BigNumberValue;
661
- toNumber(): number;
662
- toFixed(places?: number): string;
663
- toExponential(places?: number): string;
664
- toPrecision(sd?: number): string;
665
- toSignificantDigits(sd?: number): BigNumberValue;
666
- toBinary(): string;
667
- toOctal(): string;
668
- toHexadecimal(): string;
669
- }
670
- /**
671
- * Convert a BigNumber to a formatted string representation.
672
- *
673
- * Syntax:
674
- *
675
- * format(value)
676
- * format(value, options)
677
- * format(value, precision)
678
- * format(value, fn)
679
- *
680
- * Where:
681
- *
682
- * {number} value The value to be formatted
683
- * {Object} options An object with formatting options. Available options:
684
- * {string} notation
685
- * Number notation. Choose from:
686
- * 'fixed' Always use regular number notation.
687
- * For example '123.40' and '14000000'
688
- * 'exponential' Always use exponential notation.
689
- * For example '1.234e+2' and '1.4e+7'
690
- * 'auto' (default) Regular number notation for numbers
691
- * having an absolute value between
692
- * `lower` and `upper` bounds, and uses
693
- * exponential notation elsewhere.
694
- * Lower bound is included, upper bound
695
- * is excluded.
696
- * For example '123.4' and '1.4e7'.
697
- * 'bin', 'oct, or
698
- * 'hex' Format the number using binary, octal,
699
- * or hexadecimal notation.
700
- * For example '0b1101' and '0x10fe'.
701
- * {number} wordSize The word size in bits to use for formatting
702
- * in binary, octal, or hexadecimal notation.
703
- * To be used only with 'bin', 'oct', or 'hex'
704
- * values for 'notation' option. When this option
705
- * is defined the value is formatted as a signed
706
- * twos complement integer of the given word size
707
- * and the size suffix is appended to the output.
708
- * For example
709
- * format(-1, {notation: 'hex', wordSize: 8}) === '0xffi8'.
710
- * Default value is undefined.
711
- * {number} precision A number between 0 and 16 to round
712
- * the digits of the number.
713
- * In case of notations 'exponential',
714
- * 'engineering', and 'auto',
715
- * `precision` defines the total
716
- * number of significant digits returned.
717
- * In case of notation 'fixed',
718
- * `precision` defines the number of
719
- * significant digits after the decimal
720
- * point.
721
- * `precision` is undefined by default.
722
- * {number} lowerExp Exponent determining the lower boundary
723
- * for formatting a value with an exponent
724
- * when `notation='auto`.
725
- * Default value is `-3`.
726
- * {number} upperExp Exponent determining the upper boundary
727
- * for formatting a value with an exponent
728
- * when `notation='auto`.
729
- * Default value is `5`.
730
- * {Function} fn A custom formatting function. Can be used to override the
731
- * built-in notations. Function `fn` is called with `value` as
732
- * parameter and must return a string. Is useful for example to
733
- * format all values inside a matrix in a particular way.
734
- *
735
- * Examples:
736
- *
737
- * format(6.4) // '6.4'
738
- * format(1240000) // '1.24e6'
739
- * format(1/3) // '0.3333333333333333'
740
- * format(1/3, 3) // '0.333'
741
- * format(21385, 2) // '21000'
742
- * format(12e8, {notation: 'fixed'}) // returns '1200000000'
743
- * format(2.3, {notation: 'fixed', precision: 4}) // returns '2.3000'
744
- * format(52.8, {notation: 'exponential'}) // returns '5.28e+1'
745
- * format(12400, {notation: 'engineering'}) // returns '12.400e+3'
746
- *
747
- * @param {BigNumber} value
748
- * @param {Object | Function | number | BigNumber} [options]
749
- * @return {string} str The formatted value
750
- */
751
- declare function format(value: unknown, options?: unknown): string;
752
- /**
753
- * Format a BigNumber in engineering notation. Like '1.23e+6', '2.3e+0', '3.500e-3'
754
- * @param {BigNumber} value
755
- * @param {number} [precision] Optional number of significant figures to return.
756
- */
757
- declare function toEngineering(value: BigNumberValue, precision?: number): string;
758
- /**
759
- * Format a number in exponential notation. Like '1.23e+5', '2.3e+0', '3.500e-3'
760
- * @param {BigNumber} value
761
- * @param {number} [precision] Number of digits in formatted output.
762
- * If not provided, the maximum available digits
763
- * is used.
764
- * @returns {string} str
765
- */
766
- declare function toExponential(value: BigNumberValue, precision?: number): string;
767
- /**
768
- * Format a number with fixed notation.
769
- * @param {BigNumber} value
770
- * @param {number} [precision=undefined] Optional number of decimals after the
771
- * decimal point. Undefined by default.
772
- */
773
- declare function toFixed(value: BigNumberValue, precision?: number): string;
774
-
775
- type NestedArray<T> = T | NestedArray<T>[];
776
- interface IdentifiedValue<T> {
777
- value: T;
778
- identifier: number;
779
- }
780
- /**
781
- * Calculate the size of a multi dimensional array.
782
- * This function checks the size of the first entry, it does not validate
783
- * whether all dimensions match. (use function `validate` for that)
784
- * @param {Array} x
785
- * @return {number[]} size
786
- */
787
- declare function arraySize<T>(x: NestedArray<T>): number[];
788
- /**
789
- * Validate whether each element in a multi dimensional array has
790
- * a size corresponding to the provided size array.
791
- * @param {Array} array Array to be validated
792
- * @param {number[]} size Array with the size of each dimension
793
- * @throws DimensionError
794
- */
795
- declare function validate<T>(array: NestedArray<T>, size: number[]): void;
796
- /**
797
- * Validate whether the source of the index matches the size of the Array
798
- * @param {Array | Matrix} value Array to be validated
799
- * @param {Index} index Index with the source information to validate
800
- * @throws DimensionError
801
- */
802
- declare function validateIndexSourceSize(value: unknown[] | Matrix$1, index: Index): void;
803
- /**
804
- * Test whether index is an integer number with index >= 0 and index < length
805
- * when length is provided
806
- * @param {number} index Zero-based index
807
- * @param {number} [length] Length of the array
808
- */
809
- declare function validateIndex(index: number | undefined, length?: number): void;
810
- /**
811
- * Test if an index has empty values
812
- * @param {Index} index Zero-based index
813
- */
814
- declare function isEmptyIndex(index: Index): boolean;
815
- /**
816
- * Resize a multi dimensional array. The resized array is returned.
817
- * @param {Array | number} array Array to be resized
818
- * @param {number[]} size Array with the size of each dimension
819
- * @param {*} [defaultValue=0] Value to be filled in new entries,
820
- * zero by default. Specify for example `null`,
821
- * to clearly see entries that are not explicitly
822
- * set.
823
- * @return {Array} array The resized array
824
- */
825
- declare function resize<T = unknown>(array: T | T[] | NestedArray<T>, size: number[], defaultValue?: T): NestedArray<T>;
826
- /**
827
- * Re-shape a multi dimensional array to fit the specified dimensions
828
- * @param {Array} array Array to be reshaped
829
- * @param {number[]} sizes List of sizes for each dimension
830
- * @returns {Array} Array whose data has been formatted to fit the
831
- * specified dimensions
832
- *
833
- * @throws {DimensionError} If the product of the new dimension sizes does
834
- * not equal that of the old ones
835
- */
836
- declare function reshape<T = unknown>(array: NestedArray<T>, sizes: number[]): NestedArray<T>;
837
- /**
838
- * Replaces the wildcard -1 in the sizes array.
839
- * @param {number[]} sizes List of sizes for each dimension. At most one wildcard.
840
- * @param {number} currentLength Number of elements in the array.
841
- * @throws {Error} If more than one wildcard or unable to replace it.
842
- * @returns {number[]} The sizes array with wildcard replaced.
843
- */
844
- declare function processSizesWildcard(sizes: number[], currentLength: number): number[];
845
- /**
846
- * Squeeze a multi dimensional array
847
- * @param {Array} array
848
- * @param {Array} [size]
849
- * @returns {Array} returns the array itself
850
- */
851
- declare function squeeze<T>(array: NestedArray<T>, size?: number[]): T | NestedArray<T>;
852
- /**
853
- * Unsqueeze a multi dimensional array: add dimensions when missing
854
- *
855
- * Parameter `size` will be mutated to match the new, unsqueezed matrix size.
856
- *
857
- * @param {Array} array
858
- * @param {number} dims Desired number of dimensions of the array
859
- * @param {number} [outer] Number of outer dimensions to be added
860
- * @param {Array} [size] Current size of array.
861
- * @returns {Array} returns the array itself
862
- * @private
863
- */
864
- declare function unsqueeze<T>(array: NestedArray<T>, dims: number, outer?: number, size?: number[]): NestedArray<T>;
865
- /**
866
- * Flatten a multi dimensional array, put all elements in a one dimensional
867
- * array
868
- * @param {Array} array A multi dimensional array
869
- * @param {boolean} isRectangular Optional. If the array is rectangular (not jagged)
870
- * @return {Array} The flattened array (1 dimensional)
871
- */
872
- declare function flatten<T>(array: NestedArray<T>, isRectangular?: boolean): T[];
873
- /**
874
- * A safe map
875
- * @param {Array} array
876
- * @param {function} callback
877
- */
878
- declare function map<T, U>(array: T[], callback: (value: T, index: number, array: T[]) => U): U[];
879
- /**
880
- * A safe forEach
881
- * @param {Array} array
882
- * @param {function} callback
883
- */
884
- declare function forEach<T>(array: T[], callback: (value: T, index: number, array: T[]) => void): void;
885
- /**
886
- * A safe filter
887
- * @param {Array} array
888
- * @param {function} callback
889
- */
890
- declare function filter<T>(array: T[], callback: (value: T, index: number, array: T[]) => boolean): T[];
891
- /**
892
- * Filter values in an array given a regular expression
893
- * @param {Array} array
894
- * @param {RegExp} regexp
895
- * @return {Array} Returns the filtered array
896
- * @private
897
- */
898
- declare function filterRegExp(array: string[], regexp: RegExp): string[];
899
- /**
900
- * A safe join
901
- * @param {Array} array
902
- * @param {string} separator
903
- */
904
- declare function join<T>(array: T[], separator: string): string;
905
- /**
906
- * Assign a numeric identifier to every element of a sorted array
907
- * @param {Array} a An array
908
- * @return {Array} An array of objects containing the original value and its identifier
909
- */
910
- declare function identify<T>(a: T[]): IdentifiedValue<T>[];
911
- /**
912
- * Remove the numeric identifier from the elements
913
- * @param {array} a An array
914
- * @return {array} An array of values without identifiers
915
- */
916
- declare function generalize<T>(a: IdentifiedValue<T>[]): T[];
917
- /**
918
- * Check the datatype of a given object
919
- * This is a low level implementation that should only be used by
920
- * parent Matrix classes such as SparseMatrix or DenseMatrix
921
- * This method does not validate Array Matrix shape
922
- * @param {Array} array
923
- * @param {function} typeOf Callback function to use to determine the type of a value
924
- * @return {string}
925
- */
926
- declare function getArrayDataType(array: unknown[], typeOf: (value: unknown) => string): string | undefined;
927
- /**
928
- * Return the last item from an array
929
- * @param {Array} array
930
- * @returns {*}
931
- */
932
- declare function last<T>(array: T[]): T;
933
- /**
934
- * Get all but the last element of array.
935
- *
936
- * KNOWN DIVERGENCE (Bucket B slice 2): only `expression/src/utils/array.ts` had
937
- * this; `functions/src/utils/array.ts` never defined it, and it was dead code
938
- * even in expression (unused outside its own definition). Re-exported from
939
- * expression's shim only — see the module header.
940
- * @param {Array} array
941
- * @returns {Array}
942
- */
943
- declare function initial<T>(array: T[]): T[];
944
- /**
945
- * Concatenates many arrays in the specified direction
946
- * @param {...Array} arrays All the arrays to concatenate
947
- * @param {number} concatDim The dimension on which to concatenate (zero-based)
948
- * @returns {Array}
949
- */
950
- declare function concat<T>(...args: [...NestedArray<T>[], number]): NestedArray<T>[];
951
- /**
952
- * Receives two or more sizes and gets the broadcasted size for both.
953
- * @param {...number[]} sizes Sizes to broadcast together
954
- * @returns {number[]} The broadcasted size
955
- */
956
- declare function broadcastSizes(...sizes: number[][]): number[];
957
- /**
958
- * Checks if it's possible to broadcast a size to another size
959
- * @param {number[]} size The size of the array to check
960
- * @param {number[]} toSize The size of the array to validate if it can be broadcasted to
961
- */
962
- declare function checkBroadcastingRules(size: number[], toSize: number[]): void;
963
- /**
964
- * Broadcasts a single array to a certain size
965
- * @param {Array} array Array to be broadcasted
966
- * @param {number[]} toSize Size to broadcast the array
967
- * @returns {Array} The broadcasted array
968
- */
969
- declare function broadcastTo<T>(array: NestedArray<T>, toSize: number[]): NestedArray<T>;
970
- /**
971
- * Broadcasts arrays and returns the broadcasted arrays in an array
972
- * @param {...Array | any} arrays
973
- * @returns {Array[]} The broadcasted arrays
974
- */
975
- declare function broadcastArrays<T>(...arrays: NestedArray<T>[]): NestedArray<T>[];
976
- /**
977
- * Stretches a matrix up to a certain size in a certain dimension
978
- * @param {Array} arrayToStretch
979
- * @param {number[]} sizeToStretch
980
- * @param {number} dimToStretch
981
- * @returns {Array} The stretched array
982
- */
983
- declare function stretch<T>(arrayToStretch: NestedArray<T>, sizeToStretch: number, dimToStretch: number): NestedArray<T>;
984
- /**
985
- * Retrieves a single element from an array given an index.
986
- *
987
- * @param {Array} array - The array from which to retrieve the value.
988
- * @param {Array<number>} index - An array of indices specifying the position of the desired element in each dimension.
989
- * @returns {*} - The value at the specified position in the array.
990
- *
991
- * @example
992
- * const arr = [[[1, 2], [3, 4]], [[5, 6], [7, 8]]];
993
- * const index = [1, 0, 1];
994
- * console.log(get(arr, index)); // 6
995
- */
996
- declare function get<T>(array: NestedArray<T>, index: number[]): T;
997
- /**
998
- * Recursively maps over each element of nested array using a provided callback function.
999
- *
1000
- * @param {Array} array - The array to be mapped.
1001
- * @param {Function} callback - The function to execute on each element, taking three arguments:
1002
- * - `value` (any): The current element being processed in the array.
1003
- * - `index` (Array<number>): The index of the current element being processed in the array.
1004
- * - `array` (Array): The array `deepMap` was called upon.
1005
- * @param {boolean} [skipIndex=false] - If true, the callback function is called with only the value.
1006
- * @returns {Array} A new array with each element being the result of the callback function.
1007
- */
1008
- declare function deepMap$1<T, U>(array: NestedArray<T>, callback: ((value: T, index: number[], array: NestedArray<T>) => U) | ((value: T) => U), skipIndex?: boolean): NestedArray<U>;
1009
- /**
1010
- * Recursively iterates over each element in a multi-dimensional array and applies a callback function.
1011
- *
1012
- * @param {Array} array - The multi-dimensional array to iterate over.
1013
- * @param {Function} callback - The function to execute for each element. It receives three arguments:
1014
- * - {any} value: The current element being processed in the array.
1015
- * - {Array<number>} index: The index of the current element in each dimension.
1016
- * - {Array} array: The original array being processed.
1017
- * @param {boolean} [skipIndex=false] - If true, the callback function is called with only the value.
1018
- */
1019
- declare function deepForEach$1<T>(array: NestedArray<T>, callback: ((value: T, index: number[], array: NestedArray<T>) => void) | ((value: T) => void), skipIndex?: boolean): void;
1020
- /**
1021
- * Deep clones a multidimensional array
1022
- * @param {Array} array
1023
- * @returns {Array} cloned array
1024
- */
1025
- declare function clone<T>(array: T[]): T[];
1026
-
1027
- interface Matrix<T = unknown> {
1028
- forEach(callback: (value: T) => void, skipZeros: boolean, recurse: boolean): void;
1029
- map<U>(callback: (value: T) => U, skipZeros: boolean, recurse: boolean): Matrix<U>;
1030
- size(): number[];
1031
- valueOf(): T[];
1032
- create(data: T[], datatype?: string): Matrix<T>;
1033
- datatype(): string | undefined;
1034
- }
1035
- interface SparseMatrix<T = unknown> {
1036
- _values: T[];
1037
- _index: number[];
1038
- _ptr: number[];
1039
- }
1040
- /**
1041
- * Test whether an array contains collections
1042
- * @param array - Array to test
1043
- * @returns Returns true when the array contains one or multiple
1044
- * collections (Arrays or Matrices). Returns false otherwise.
1045
- */
1046
- declare function containsCollections(array: unknown[]): boolean;
1047
- /**
1048
- * Recursively loop over all elements in a given multi dimensional array
1049
- * and invoke the callback on each of the elements.
1050
- * @param array - Array or Matrix to iterate over
1051
- * @param callback - The callback method is invoked with one parameter: the current element in the array
1052
- */
1053
- declare function deepForEach<T>(array: T[] | Matrix<T>, callback: (value: T) => void): void;
1054
- /**
1055
- * Execute the callback function element wise for each element in array and any
1056
- * nested array
1057
- * Returns an array with the results
1058
- * @param array - Array or Matrix to map over
1059
- * @param callback - The callback is called with two parameters:
1060
- * value1 and value2, which contain the current
1061
- * element of both arrays.
1062
- * @param skipZeros - Invoke callback function for non-zero values only.
1063
- *
1064
- * @return Mapped result
1065
- */
1066
- declare function deepMap<T, U>(array: T[] | Matrix<T>, callback: (value: T) => U, skipZeros?: boolean): U[] | Matrix<U>;
1067
- /**
1068
- * Reduce a given matrix or array to a new matrix or
1069
- * array with one less dimension, applying the given
1070
- * callback in the selected dimension.
1071
- * @param mat - Array or Matrix to reduce
1072
- * @param dim - Dimension to reduce
1073
- * @param callback - Callback function
1074
- * @return Reduced result
1075
- */
1076
- declare function reduce<T, U>(mat: T[] | Matrix<T>, dim: number, callback: (acc: U | T, val: T) => U): U[] | Matrix<U>;
1077
- /**
1078
- * Scatter function for sparse matrix operations
1079
- * @param a - Sparse matrix
1080
- * @param j - Column index
1081
- * @param w - Work array for marking visited rows
1082
- * @param x - Work array for storing values
1083
- * @param u - Work array for marking updated rows
1084
- * @param mark - Current mark value
1085
- * @param cindex - Column index array to update
1086
- * @param f - Binary function to apply
1087
- * @param inverse - Whether to inverse the function arguments
1088
- * @param update - Whether to update existing values
1089
- * @param value - Value to use in binary function
1090
- */
1091
- declare function scatter<T>(a: SparseMatrix<T>, j: number, w: number[], x: T[] | null, u: number[], mark: number, cindex: number[], f?: (a: T, b: T) => T, inverse?: boolean, update?: boolean, value?: T): void;
1092
-
1093
- /**
1094
- * Transpose a 2D array. Private helper used only by `core/src/collection.ts`'s
1095
- * `_reduce` (Bucket B slice 2 canonical) — mirrors `expression/src/utils/switch.ts`
1096
- * / `functions/src/utils/switch.ts`, which remain in place unchanged for now
1097
- * (not part of this slice's named scope). Not exported from `internal.ts`.
1098
- * @private
1099
- */
1100
- declare function _switch<T>(mat: T[][]): T[][];
1101
-
1102
- /**
1103
- * A map facade on a bare object.
1104
- *
1105
- * The small number of methods needed to implement a scope,
1106
- * forwarding on to the SafeProperty functions. Over time, the codebase
1107
- * will stop using this method, as all objects will be Maps, rather than
1108
- * more security prone objects.
1109
- */
1110
- /**
1111
- * The iterator type `Map` itself declares, derived from the installed TS lib
1112
- * rather than hard-coded: older libs say `IterableIterator<[K, V]>`, TS >= 5.6
1113
- * says `MapIterator<[K, V]>` (which additionally requires `[Symbol.dispose]`).
1114
- * Deriving it keeps `implements Map<K, V>` honest on every TS version.
1115
- */
1116
- type MapEntryIterator<K, V> = ReturnType<Map<K, V>[typeof Symbol.iterator]>;
1117
- declare class ObjectWrappingMap<K = string, V = unknown> implements Map<K, V> {
1118
- wrappedObject: Record<string, V>;
1119
- readonly [Symbol.toStringTag]: string;
1120
- constructor(object: Record<string, V>);
1121
- /**
1122
- * Declared as a real method rather than assigned in the constructor through a
1123
- * cast. The old form satisfied the runtime but never appeared in the emitted
1124
- * type, so `implements Map<K, V>` was a lie that only surfaced downstream:
1125
- * consumers compiling with `skipLibCheck: false` got TS2420 ("incorrectly
1126
- * implements interface 'Map'... '[Symbol.iterator]' is missing").
1127
- */
1128
- [Symbol.iterator](): MapEntryIterator<K, V>;
1129
- keys(): IterableIterator<K>;
1130
- get(key: K): V | undefined;
1131
- set(key: K, value: V): this;
1132
- has(key: K): boolean;
1133
- entries(): IterableIterator<[K, V]>;
1134
- values(): IterableIterator<V>;
1135
- forEach(callback: (value: V, key: K, map: Map<K, V>) => void): void;
1136
- delete(key: K): boolean;
1137
- clear(): void;
1138
- get size(): number;
1139
- }
1140
- /**
1141
- * Create a map with two partitions: a and b.
1142
- * The set with bKeys determines which keys/values are read/written to map b,
1143
- * all other values are read/written to map a
1144
- *
1145
- * For example:
1146
- *
1147
- * const a = new Map()
1148
- * const b = new Map()
1149
- * const p = new PartitionedMap(a, b, new Set(['x', 'y']))
1150
- *
1151
- * In this case, values `x` and `y` are read/written to map `b`,
1152
- * all other values are read/written to map `a`.
1153
- */
1154
- declare class PartitionedMap<K = unknown, V = unknown> implements Map<K, V> {
1155
- a: Map<K, V>;
1156
- b: Map<K, V>;
1157
- bKeys: Set<K>;
1158
- readonly [Symbol.toStringTag]: string;
1159
- /**
1160
- * @param a - Primary map
1161
- * @param b - Secondary map
1162
- * @param bKeys - Set of keys that should be read/written to map b
1163
- */
1164
- constructor(a: Map<K, V>, b: Map<K, V>, bKeys: Set<K>);
1165
- /** See the note on `ObjectWrappingMap[Symbol.iterator]` — same fix. */
1166
- [Symbol.iterator](): MapEntryIterator<K, V>;
1167
- get(key: K): V | undefined;
1168
- set(key: K, value: V): this;
1169
- has(key: K): boolean;
1170
- keys(): IterableIterator<K>;
1171
- values(): IterableIterator<V>;
1172
- entries(): IterableIterator<[K, V]>;
1173
- forEach(callback: (value: V, key: K, map: Map<K, V>) => void): void;
1174
- delete(key: K): boolean;
1175
- clear(): void;
1176
- get size(): number;
1177
- }
1178
- /**
1179
- * Creates an empty map, or whatever your platform's polyfill is.
1180
- *
1181
- * @returns an empty Map or Map like object.
1182
- */
1183
- declare function createEmptyMap<K = string, V = unknown>(): Map<K, V>;
1184
- /**
1185
- * Creates a Map from the given object.
1186
- *
1187
- * @param mapOrObject - Map or object to convert
1188
- * @returns Map instance
1189
- */
1190
- declare function createMap<K = string, V = unknown>(mapOrObject?: Map<K, V> | Record<string, V> | null): Map<K, V>;
1191
- /**
1192
- * Unwraps a map into an object.
1193
- *
1194
- * @param map - Map to convert to object
1195
- * @returns Plain object
1196
- */
1197
- declare function toObject<V = unknown>(map: Map<unknown, V>): Record<string, V>;
1198
- /**
1199
- * Copies the contents of key-value pairs from each `objects` in to `map`.
1200
- *
1201
- * Object is `objects` can be a `Map` or object.
1202
- *
1203
- * This is the `Map` analog to `Object.assign`.
1204
- */
1205
- declare function assign<K = unknown, V = unknown>(map: Map<K, V>, ...objects: (Map<K, V> | Record<string, V> | null | undefined)[]): Map<K, V>;
1206
- /**
1207
- * Returns `true` if `object` is an {@link ObjectWrappingMap}.
1208
- *
1209
- * Defined here, next to the class it guards, so `is.ts` need not import
1210
- * `map.ts` — that import was the sole edge closing the `is`/`map` cycle.
1211
- */
1212
- declare function isObjectWrappingMap(object: unknown): object is ObjectWrappingMap;
1213
-
1214
- /**
1215
- * Shared type-only shapes for the two independent WASM loader implementations
1216
- * (`functions/src/wasm/WasmLoader.ts` and `matrix/src/backends/WasmLoader.ts`).
1217
- *
1218
- * Both packages bind to the same `mathts-as.wasm` AssemblyScript binary but each
1219
- * declares its own package-scoped subset of the exported function ABI (`WasmModule`
1220
- * genuinely differs between the two — matrix only needs matrix-relevant exports,
1221
- * functions needs the full breadth including signal/geometry/special-function
1222
- * kernels — so `WasmModule` stays local to each package). `LoadingMetrics` (perf
1223
- * timings) and `WasmManifest` (the SHA-384 integrity manifest shape) were,
1224
- * however, byte-for-byte identical copies with no principled reason to diverge;
1225
- * consolidated here (cross-package type-dedup pass,
1226
- * docs/Architecture/duplicate-symbols.json).
1227
- *
1228
- * @module @danielsimonjr/mathts-core/types/wasm-loader
1229
- */
1230
- /**
1231
- * Loading performance metrics for a WASM module load/instantiate cycle.
1232
- */
1233
- interface LoadingMetrics {
1234
- fileReadMs: number;
1235
- compileMs: number;
1236
- instantiateMs: number;
1237
- totalMs: number;
1238
- fromCache: boolean;
1239
- }
1240
- /**
1241
- * SHA-384 integrity manifest: maps a `.wasm` filename to its
1242
- * `"sha384-<base64 digest>"` value (SRI-style), as generated by
1243
- * `tools/generate-wasm-manifest.mjs`.
1244
- */
1245
- interface WasmManifest {
1246
- [fileName: string]: string;
1247
- }
1248
-
1249
- /**
1250
- * Shared WASM-loader runtime logic — SHA-384 integrity verification + packaged
1251
- * artifact path resolution — consolidated here so `functions` and `matrix` build
1252
- * on ONE copy instead of maintaining byte-identical forks.
1253
- *
1254
- * Why core: `matrix` cannot import from `functions` (functions depends on matrix,
1255
- * which would invert the edge and create a cycle), so the historical solution was
1256
- * to duplicate this logic in both packages. Both packages already depend on
1257
- * `core`, so `@danielsimonjr/mathts-core/internal` is a home reachable from both
1258
- * WITHOUT introducing a cycle. Exposed ONLY via the `/internal` subpath (never the
1259
- * browser-facing `.` entry); every filesystem/crypto access uses a LAZY dynamic
1260
- * `import()` so this module stays browser-safe (no static `node:` imports).
1261
- *
1262
- * SECURITY INVARIANT (CLAUDE.md "Security Invariants" #1): the SHA-384
1263
- * hash-and-compare-before-instantiate is preserved BYTE-FOR-BYTE from the former
1264
- * per-package `integrity.ts` copies — same algorithm, same fail-closed/soft-warn
1265
- * behavior. Do NOT bypass, weaken to a non-cryptographic check, or skip on
1266
- * streaming compile paths. Regression-covered by
1267
- * `functions/tests/security/wasm-integrity.test.ts` and
1268
- * `matrix/tests/security/wasm-integrity.test.ts`.
1269
- *
1270
- * The build pipeline writes a JSON manifest beside the .wasm artefact:
1271
- *
1272
- * {
1273
- * "mathts-as.wasm": "sha384-<base64-of-binary-digest>"
1274
- * }
1275
- *
1276
- * At load time the runtime hashes the freshly read buffer with SHA-384 and
1277
- * compares against the manifest. A mismatch throws — preventing silent
1278
- * code-injection if the .wasm artefact is tampered with on disk or in transit
1279
- * (e.g. a CDN/MITM compromise).
1280
- *
1281
- * Browser path uses `crypto.subtle.digest('SHA-384', buf)`.
1282
- * Node path uses `crypto.createHash('sha384').update(buf).digest()`.
1283
- *
1284
- * If the manifest is missing or has no entry for the given file, we emit a
1285
- * console warning and fall through. This keeps existing unsigned builds usable
1286
- * while making signed builds tamper-evident.
1287
- *
1288
- * @module @danielsimonjr/mathts-core/internal (wasm-loader)
1289
- */
1290
-
1291
- /**
1292
- * Compute the SHA-384 digest of a buffer and return base64 encoding,
1293
- * prefixed with "sha384-" to match SRI conventions.
1294
- */
1295
- declare function sha384OfBuffer(buffer: ArrayBuffer | Uint8Array): Promise<string>;
1296
- /**
1297
- * Load the manifest sitting next to the .wasm artefact.
1298
- *
1299
- * @param wasmPath Resolved path or URL to the .wasm file.
1300
- * @returns parsed manifest, or `null` if the manifest cannot be located.
1301
- */
1302
- declare function loadWasmManifest(wasmPath: string): Promise<WasmManifest | null>;
1303
- /**
1304
- * Verify a freshly loaded WASM buffer against the manifest.
1305
- *
1306
- * @throws Error if the buffer's SHA-384 differs from the manifest entry.
1307
- */
1308
- declare function verifyWasmIntegrity(buffer: ArrayBuffer | Uint8Array, wasmPath: string, options?: {
1309
- manifest?: WasmManifest | null;
1310
- required?: boolean;
1311
- }): Promise<void>;
1312
- /**
1313
- * Robustly locate a packaged `.wasm` artifact across both the monorepo-source
1314
- * layout and the published-package layout (Node only).
1315
- *
1316
- * The historical loaders hard-coded `../../../lib/wasm/<file>` relative to
1317
- * `import.meta.url`, which only resolved for the monorepo source layout and
1318
- * pointed outside the package once bundled/published — so the wasm was never
1319
- * found and every consumer silently fell back to JS. This walks up from the
1320
- * calling module's directory probing `<dir>/wasm/<file>` and
1321
- * `<dir>/dist/wasm/<file>` at each level, matching bundled dist, unbundled dist,
1322
- * and monorepo source.
1323
- *
1324
- * The caller injects its OWN `metaUrl` (its `import.meta.url`) so resolution is
1325
- * relative to the calling package, not to core.
1326
- *
1327
- * @returns absolute path to the artifact, or `null` if not found.
1328
- */
1329
- declare function resolvePackagedWasm(metaUrl: string, wasmFile: string): Promise<string | null>;
1330
- /**
1331
- * Canonical fallback location for the packaged wasm when {@link resolvePackagedWasm}
1332
- * finds nothing: `<packageRoot>/dist/wasm/<wasmFile>`, with the package root found
1333
- * by walking up from `metaUrl` to the nearest `package.json`. This replaces the
1334
- * historical `../../../lib/wasm/<file>` fabrication, which was only correct for the
1335
- * pre-bundling source layout. The returned path is where the binary SHOULD be, so
1336
- * the missing-binary warning tells the user exactly what to build.
1337
- *
1338
- * In browser mode (no filesystem) it returns the bundle-relative `./wasm/<file>`
1339
- * URL — correct for a served `dist/`, which is the only layout browsers see.
1340
- */
1341
- declare function defaultWasmLocation(metaUrl: string, wasmFile: string, opts?: {
1342
- browser?: boolean;
1343
- }): Promise<string>;
1344
-
1345
- export { type BigNumberValue, type ConfigOptions, DEFAULT_CONFIG, DimensionError, FactoryFunction, type FormatOptions, type GeneralFormatOptions, type IdentifiedValue, Index, IndexError, type LoadingMetrics, type MathJsConfig, MathjsError, Matrix$1 as Matrix, type MemoizedFunction, type NestedArray, type NormalizedFormatOptions, type NumberTypeConfig, ObjectWrappingMap, PartitionedMap, type SplitValue, UnitConstructor, UnitDependencies, type WasmManifest, _switch, acosh, arraySize, asinh, assign as assignMap, atanh, broadcastArrays, broadcastSizes, broadcastTo, canDefineProperty, cbrt, checkBroadcastingRules, clone$1 as clone, clone as cloneArray, compareText, concat, containsCollections, copysign, cosh, createEmptyMap, createIndexError, createMap, createUnitClass, deepExtend, deepFlatten, deepForEach, deepForEach$1 as deepForEachArray, deepMap, deepMap$1 as deepMapArray, deepStrictEqual, defaultWasmLocation, digits, endsWith, escape, expm1, extend, filter, filterRegExp, flatten, forEach, format$2 as format, format as formatBigNumber, format$1 as formatGeneric, generalize, get$1 as get, getArrayDataType, get as getArrayElement, hasOwnProperty, identify, initial, isEmptyIndex, isInteger, isLegacyFactory, isObjectWrappingMap, isPowZeroAtInfinity, join, last, lazy, loadWasmManifest, log10, log1p, log2, map, mapObject, memoize, nearlyEqual, normalizeFormatOptions, pick, pickShallow, processSizesWildcard, reduce, reshape, resize, resolvePackagedWasm, roundDigits, safeNumberType, scatter, set, sha384OfBuffer, sign, sinh, splitNumber, squeeze, stretch, stringify, tanh, toEngineering$1 as toEngineering, toEngineering as toEngineeringBigNumber, toExponential$1 as toExponential, toExponential as toExponentialBigNumber, toFixed$1 as toFixed, toFixed as toFixedBigNumber, toObject, toPrecision, traverse, unitDependencies, unsqueeze, validate, validateIndex, validateIndexSourceSize, verifyWasmIntegrity, warnOnce };
2
+ * Internal shared utilities, exposed via the `@danielsimonjr/mathts-core/internal`
3
+ * subpath export so downstream packages (functions, expression) build on ONE copy
4
+ * of the type guards, number formatting/parsing, and object helpers instead of each
5
+ * maintaining a drifting fork.
6
+ *
7
+ * This is deliberately NOT part of core's main public API (`.`), which stays focused
8
+ * on the numeric types, typed-function integration, and factory. These are lower-level
9
+ * helpers shared across the monorepo. See the `project-all-libraries-build-on-core`
10
+ * principle: keep the implementation in the standard layer once and let it propagate.
11
+ */
12
+ export * from './is.js';
13
+ export * from './number.js';
14
+ export * from './object.js';
15
+ export { hasOwnProperty, endsWith, warnOnce, memoize } from './shared.js';
16
+ export type { MemoizedFunction } from './shared.js';
17
+ export type { ConfigOptions, MathJsConfig } from './config.js';
18
+ export { DEFAULT_CONFIG } from './config.js';
19
+ export { MathjsError } from './error/MathjsError.js';
20
+ export { DimensionError } from './error/DimensionError.js';
21
+ export { IndexError, createIndexError } from './error/IndexError.js';
22
+ export * from './factory.js';
23
+ export { format as formatGeneric, stringify, escape, compareText, type GeneralFormatOptions, } from './string.js';
24
+ export { format as formatBigNumber, toEngineering as toEngineeringBigNumber, toExponential as toExponentialBigNumber, toFixed as toFixedBigNumber, type BigNumberValue, } from './bignumber-formatter.js';
25
+ export type * from './types/unit/unit-types.js';
26
+ export { createUnitClass, unitDependencies, Unit as CoreUnit } from './types/unit/index.js';
27
+ export type { NestedArray, IdentifiedValue } from './array.js';
28
+ export { arraySize, validate, validateIndexSourceSize, validateIndex, isEmptyIndex, resize, reshape, processSizesWildcard, squeeze, unsqueeze, flatten, map, forEach, filter, filterRegExp, join, identify, generalize, getArrayDataType, last, initial, concat, broadcastSizes, checkBroadcastingRules, broadcastTo, broadcastArrays, stretch, get as getArrayElement, deepMap as deepMapArray, deepForEach as deepForEachArray, clone as cloneArray, } from './array.js';
29
+ export { containsCollections, deepMap, deepForEach, reduce, scatter } from './collection.js';
30
+ export { _switch } from './switch.js';
31
+ export { ObjectWrappingMap, PartitionedMap, createEmptyMap, createMap, toObject, assign as assignMap, isObjectWrappingMap, } from './map.js';
32
+ export type { LoadingMetrics, WasmManifest } from './types/wasm-loader.js';
33
+ export { sha384OfBuffer, loadWasmManifest, verifyWasmIntegrity, resolvePackagedWasm, defaultWasmLocation, } from './wasm-loader.js';
34
+ //# sourceMappingURL=internal.d.ts.map