@danielsimonjr/mathts-core 0.14.3 → 0.15.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/arithmetic/scalar.d.ts +56 -0
- package/dist/arithmetic/scalar.d.ts.map +1 -0
- package/dist/array.d.ts +265 -0
- package/dist/array.d.ts.map +1 -0
- package/dist/bignumber-formatter.d.ts +135 -0
- package/dist/bignumber-formatter.d.ts.map +1 -0
- package/dist/collection.d.ts +67 -0
- package/dist/collection.d.ts.map +1 -0
- package/dist/config.d.ts +20 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/constants.d.ts +30 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/customs.d.ts +44 -0
- package/dist/customs.d.ts.map +1 -0
- package/dist/error/DimensionError.d.ts +28 -0
- package/dist/error/DimensionError.d.ts.map +1 -0
- package/dist/error/IndexError.d.ts +41 -0
- package/dist/error/IndexError.d.ts.map +1 -0
- package/dist/error/MathjsError.d.ts +13 -0
- package/dist/error/MathjsError.d.ts.map +1 -0
- package/dist/factory/factory.d.ts +154 -0
- package/dist/factory/factory.d.ts.map +1 -0
- package/dist/factory/index.d.ts +6 -0
- package/dist/factory/index.d.ts.map +1 -0
- package/dist/factory.d.ts +122 -0
- package/dist/factory.d.ts.map +1 -0
- package/dist/index.d.ts +24 -2593
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +36 -18
- package/dist/internal.d.ts +33 -1344
- package/dist/internal.d.ts.map +1 -0
- package/dist/internal.js +36 -6
- package/dist/is.d.ts +256 -0
- package/dist/is.d.ts.map +1 -0
- package/dist/map.d.ts +147 -0
- package/dist/map.d.ts.map +1 -0
- package/dist/number.d.ts +314 -0
- package/dist/number.d.ts.map +1 -0
- package/dist/numeric/stable.d.ts +130 -0
- package/dist/numeric/stable.d.ts.map +1 -0
- package/dist/object.d.ts +119 -0
- package/dist/object.d.ts.map +1 -0
- package/dist/shared.d.ts +41 -0
- package/dist/shared.d.ts.map +1 -0
- package/dist/string.d.ts +70 -0
- package/dist/string.d.ts.map +1 -0
- package/dist/switch.d.ts +9 -0
- package/dist/switch.d.ts.map +1 -0
- package/dist/typed/index.d.ts +7 -0
- package/dist/typed/index.d.ts.map +1 -0
- package/dist/typed/mathts-typed.d.ts +246 -0
- package/dist/typed/mathts-typed.d.ts.map +1 -0
- package/dist/typed/type-bridge.d.ts +9 -0
- package/dist/typed/type-bridge.d.ts.map +1 -0
- package/dist/types/bignumber.d.ts +370 -0
- package/dist/types/bignumber.d.ts.map +1 -0
- package/dist/types/complex.d.ts +284 -0
- package/dist/types/complex.d.ts.map +1 -0
- package/dist/types/dual-rules.d.ts +129 -0
- package/dist/types/dual-rules.d.ts.map +1 -0
- package/dist/types/dual.d.ts +39 -0
- package/dist/types/dual.d.ts.map +1 -0
- package/dist/types/fraction.d.ts +215 -0
- package/dist/types/fraction.d.ts.map +1 -0
- package/dist/types/interfaces.d.ts +143 -0
- package/dist/types/interfaces.d.ts.map +1 -0
- package/dist/types/matrix/Range.d.ts +767 -0
- package/dist/types/matrix/Range.d.ts.map +1 -0
- package/dist/types/unit/Unit.d.ts +3 -0
- package/dist/types/unit/Unit.d.ts.map +1 -0
- package/dist/types/unit/dependencies.d.ts +4 -0
- package/dist/types/unit/dependencies.d.ts.map +1 -0
- package/dist/types/unit/errors.d.ts +18 -0
- package/dist/types/unit/errors.d.ts.map +1 -0
- package/dist/types/unit/index.d.ts +7 -0
- package/dist/types/unit/index.d.ts.map +1 -0
- package/dist/types/unit/unit-types.d.ts +231 -0
- package/dist/types/unit/unit-types.d.ts.map +1 -0
- package/dist/types/unit-definitions.d.ts +79 -0
- package/dist/types/unit-definitions.d.ts.map +1 -0
- package/dist/types/unit-prefixes.d.ts +29 -0
- package/dist/types/unit-prefixes.d.ts.map +1 -0
- package/dist/types/unit.d.ts +28 -0
- package/dist/types/unit.d.ts.map +1 -0
- package/dist/types/wasm-loader.d.ts +35 -0
- package/dist/types/wasm-loader.d.ts.map +1 -0
- package/dist/wasm-loader.d.ts +97 -0
- package/dist/wasm-loader.d.ts.map +1 -0
- package/package.json +8 -8
- package/dist/index-B4LIOfHN.d.ts +0 -449
package/dist/string.d.ts
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { type FormatOptions } from './number.js';
|
|
2
|
+
/**
|
|
3
|
+
* Formatting options accepted by the generic `format` helper. Extends the
|
|
4
|
+
* numeric {@link FormatOptions} with the string-level `truncate` and the
|
|
5
|
+
* fraction rendering mode, or is a precision number, or a custom formatter.
|
|
6
|
+
*/
|
|
7
|
+
export type GeneralFormatOptions = number | ((value: unknown) => string) | (FormatOptions & {
|
|
8
|
+
truncate?: number;
|
|
9
|
+
fraction?: 'ratio' | 'decimal';
|
|
10
|
+
});
|
|
11
|
+
/**
|
|
12
|
+
* Format a value of any type into a string.
|
|
13
|
+
*
|
|
14
|
+
* Usage:
|
|
15
|
+
* math.format(value)
|
|
16
|
+
* math.format(value, precision)
|
|
17
|
+
* math.format(value, options)
|
|
18
|
+
*
|
|
19
|
+
* When value is a function:
|
|
20
|
+
*
|
|
21
|
+
* - When the function has a property `syntax`, it returns this
|
|
22
|
+
* syntax description.
|
|
23
|
+
* - In other cases, a string `'function'` is returned.
|
|
24
|
+
*
|
|
25
|
+
* When `value` is an Object:
|
|
26
|
+
*
|
|
27
|
+
* - When the object contains a property `format` being a function, this
|
|
28
|
+
* function is invoked as `value.format(options)` and the result is returned.
|
|
29
|
+
* - When the object has its own `toString` method, this method is invoked
|
|
30
|
+
* and the result is returned.
|
|
31
|
+
* - In other cases the function will loop over all object properties and
|
|
32
|
+
* return JSON object notation like '{"a": 2, "b": 3}'.
|
|
33
|
+
*
|
|
34
|
+
* Example usage:
|
|
35
|
+
* math.format(2/7) // '0.2857142857142857'
|
|
36
|
+
* math.format(math.pi, 3) // '3.14'
|
|
37
|
+
* math.format(new Complex(2, 3)) // '2 + 3i'
|
|
38
|
+
* math.format('hello') // '"hello"'
|
|
39
|
+
*
|
|
40
|
+
* @param value - Value to be stringified
|
|
41
|
+
* @param options - Optional.
|
|
42
|
+
* Formatting options. See src/utils/number.js:format for a
|
|
43
|
+
* description of the available options controlling number output.
|
|
44
|
+
* This generic "format" also supports the option property `truncate: NN`
|
|
45
|
+
* giving the maximum number NN of characters to return (if there would
|
|
46
|
+
* have been more, they are deleted and replaced by an ellipsis).
|
|
47
|
+
* @return {string} str
|
|
48
|
+
*/
|
|
49
|
+
export declare function format(value: unknown, options?: unknown): string;
|
|
50
|
+
/**
|
|
51
|
+
* Stringify a value into a string enclosed in double quotes.
|
|
52
|
+
* Unescaped double quotes and backslashes inside the value are escaped.
|
|
53
|
+
* @param value
|
|
54
|
+
* @return {string}
|
|
55
|
+
*/
|
|
56
|
+
export declare function stringify(value: unknown): string;
|
|
57
|
+
/**
|
|
58
|
+
* Escape special HTML characters
|
|
59
|
+
* @param value
|
|
60
|
+
* @return {string}
|
|
61
|
+
*/
|
|
62
|
+
export declare function escape(value: unknown): string;
|
|
63
|
+
/**
|
|
64
|
+
* Compare two strings
|
|
65
|
+
* @param x
|
|
66
|
+
* @param y
|
|
67
|
+
* @returns {number}
|
|
68
|
+
*/
|
|
69
|
+
export declare function compareText(x: unknown, y: unknown): number;
|
|
70
|
+
//# sourceMappingURL=string.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"string.d.ts","sourceRoot":"","sources":["../src/string.ts"],"names":[],"mappings":"AAoBA,OAAO,EAA0B,KAAK,aAAa,EAAE,MAAM,aAAa,CAAC;AAGzE;;;;GAIG;AACH,MAAM,MAAM,oBAAoB,GAC5B,MAAM,GACN,CAAC,CAAC,KAAK,EAAE,OAAO,KAAK,MAAM,CAAC,GAC5B,CAAC,aAAa,GAAG;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;CAChC,CAAC,CAAC;AASP;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,wBAAgB,MAAM,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,OAAO,GAAG,MAAM,CAShE;AA2DD;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAWhD;AAYD;;;;GAIG;AACH,wBAAgB,MAAM,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAU7C;AA8CD;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,GAAG,MAAM,CAoB1D"}
|
package/dist/switch.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Transpose a 2D array. Private helper used only by `core/src/collection.ts`'s
|
|
3
|
+
* `_reduce` (Bucket B slice 2 canonical) — mirrors `expression/src/utils/switch.ts`
|
|
4
|
+
* / `functions/src/utils/switch.ts`, which remain in place unchanged for now
|
|
5
|
+
* (not part of this slice's named scope). Not exported from `internal.ts`.
|
|
6
|
+
* @private
|
|
7
|
+
*/
|
|
8
|
+
export declare function _switch<T>(mat: T[][]): T[][];
|
|
9
|
+
//# sourceMappingURL=switch.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"switch.d.ts","sourceRoot":"","sources":["../src/switch.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,wBAAgB,OAAO,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,EAAE,GAAG,CAAC,EAAE,EAAE,CAa5C"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* typed-function integration exports
|
|
3
|
+
*/
|
|
4
|
+
export { mathTyped, createMathTSTyped, typed, create, createTypedFunction, TypeRegistry, MATHTS_TYPES, MATHTS_CONVERSIONS, isNumber, isBoolean, isString, isBigInt, isArray, isFunction, isObject, isNull, isUndefined, isComplex, isFraction, isBigNumber, isFloat64Array, isFloat32Array, isInt32Array, isUint32Array, isUint8Array, isMatrix, isDenseMatrix, isSparseMatrix, isUnit, initTypedWasm, isTypedWasmAvailable, } from './mathts-typed.js';
|
|
5
|
+
export type { TypedFunction, TypedInstance, TypeDef, ConversionDef, SignatureFunction, ReferTo, ReferToSelf, } from './mathts-typed.js';
|
|
6
|
+
export { registerNativeTypes } from './type-bridge.js';
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/typed/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAEL,SAAS,EACT,iBAAiB,EACjB,KAAK,EACL,MAAM,EACN,mBAAmB,EACnB,YAAY,EAGZ,YAAY,EACZ,kBAAkB,EAGlB,QAAQ,EACR,SAAS,EACT,QAAQ,EACR,QAAQ,EACR,OAAO,EACP,UAAU,EACV,QAAQ,EACR,MAAM,EACN,WAAW,EAGX,SAAS,EACT,UAAU,EACV,WAAW,EAGX,cAAc,EACd,cAAc,EACd,YAAY,EACZ,aAAa,EACb,YAAY,EAGZ,QAAQ,EACR,aAAa,EACb,cAAc,EAGd,MAAM,EAGN,aAAa,EACb,oBAAoB,GACrB,MAAM,mBAAmB,CAAC;AAE3B,YAAY,EACV,aAAa,EACb,aAAa,EACb,OAAO,EACP,aAAa,EACb,iBAAiB,EACjB,OAAO,EACP,WAAW,GACZ,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MathTS typed-function Integration
|
|
3
|
+
*
|
|
4
|
+
* Creates a configured typed-function instance with MathTS types
|
|
5
|
+
* for runtime type dispatch across numeric types, matrices, and more.
|
|
6
|
+
*
|
|
7
|
+
* This module directly uses the typed-function library API without
|
|
8
|
+
* any intermediate abstraction layers.
|
|
9
|
+
*
|
|
10
|
+
* Supports WASM-accelerated dispatch when available.
|
|
11
|
+
*
|
|
12
|
+
* @packageDocumentation
|
|
13
|
+
*/
|
|
14
|
+
import typed, { create } from 'typed-function';
|
|
15
|
+
import type { TypedFunction, TypedInstance, SignatureFunction, ReferTo, ReferToSelf } from 'typed-function';
|
|
16
|
+
/**
|
|
17
|
+
* Initialize WASM dispatch for typed-function (optional, improves performance)
|
|
18
|
+
*
|
|
19
|
+
* Uses the unified typed.init() API to enable WASM-accelerated dispatch
|
|
20
|
+
* with automatic fallback to pure JS when WASM is unavailable.
|
|
21
|
+
*
|
|
22
|
+
* @param options - Initialization options
|
|
23
|
+
* @returns Promise resolving to true if WASM was initialized successfully
|
|
24
|
+
*/
|
|
25
|
+
export declare function initTypedWasm(options?: {
|
|
26
|
+
preferWasm?: boolean;
|
|
27
|
+
}): Promise<boolean>;
|
|
28
|
+
/**
|
|
29
|
+
* Check if WASM dispatch is available
|
|
30
|
+
*/
|
|
31
|
+
export declare function isTypedWasmAvailable(): boolean;
|
|
32
|
+
import { Complex } from '../types/complex.js';
|
|
33
|
+
import { Fraction } from '../types/fraction.js';
|
|
34
|
+
import { BigNumber } from '../types/bignumber.js';
|
|
35
|
+
export type { TypedFunction, TypedInstance, SignatureFunction, ReferTo, ReferToSelf };
|
|
36
|
+
/**
|
|
37
|
+
* Any concrete implementation accepted when *declaring* a typed signature.
|
|
38
|
+
*
|
|
39
|
+
* typed-function's published `SignatureFunction` is `(...args: unknown[]) =>
|
|
40
|
+
* unknown`, which is correct for *internal/output* positions (where the stored
|
|
41
|
+
* impl is later CALLED with validated args) but wrong as an *input* type:
|
|
42
|
+
* under `strictFunctionTypes`, function parameters are contravariant, so a
|
|
43
|
+
* concrete impl such as `(a: number, b: number) => number` is NOT assignable
|
|
44
|
+
* to an `unknown[]` parameter list (`unknown` is not assignable to `number`).
|
|
45
|
+
* The correct top-type for "any function" in an input position uses `never`
|
|
46
|
+
* parameters — every function is assignable to it because `never` is
|
|
47
|
+
* assignable to every parameter type. This is exactly the set of values
|
|
48
|
+
* typed-function genuinely accepts when declaring signatures.
|
|
49
|
+
*/
|
|
50
|
+
export type SignatureImpl = (...args: never[]) => unknown;
|
|
51
|
+
/** Signature record accepted by the MathTS typed factory (see {@link SignatureImpl}). */
|
|
52
|
+
export type SignatureRecord = Record<string, SignatureImpl | ReferTo | ReferToSelf>;
|
|
53
|
+
/**
|
|
54
|
+
* The MathTS typed-function factory type.
|
|
55
|
+
*
|
|
56
|
+
* Structurally identical to typed-function's {@link TypedInstance} except its
|
|
57
|
+
* call signatures accept implementations declared with concrete parameter
|
|
58
|
+
* types (see {@link SignatureImpl}). All instance methods are inherited
|
|
59
|
+
* unchanged via `Omit<TypedInstance, never>` (a mapped type, which drops the
|
|
60
|
+
* overly-strict published call signatures while preserving every method).
|
|
61
|
+
*/
|
|
62
|
+
export interface MathTSTyped extends Omit<TypedInstance, never> {
|
|
63
|
+
(name: string, signatures: SignatureRecord): TypedFunction;
|
|
64
|
+
(signatures: SignatureRecord): TypedFunction;
|
|
65
|
+
(...args: Array<string | SignatureRecord | TypedFunction | (SignatureImpl & {
|
|
66
|
+
signature: string;
|
|
67
|
+
})>): TypedFunction;
|
|
68
|
+
referToSelf: (callback: (self: TypedFunction) => SignatureImpl) => ReferToSelf;
|
|
69
|
+
referTo: (...args: [...string[], (...fns: SignatureFunction[]) => SignatureImpl]) => ReferTo;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Type definition for typed-function
|
|
73
|
+
*/
|
|
74
|
+
export interface TypeDef {
|
|
75
|
+
name: string;
|
|
76
|
+
test: (x: unknown) => boolean;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Conversion definition for typed-function
|
|
80
|
+
*/
|
|
81
|
+
export interface ConversionDef {
|
|
82
|
+
from: string;
|
|
83
|
+
to: string;
|
|
84
|
+
convert: (value: unknown) => unknown;
|
|
85
|
+
}
|
|
86
|
+
export declare const isNumber: (x: unknown) => x is number;
|
|
87
|
+
export declare const isBoolean: (x: unknown) => x is boolean;
|
|
88
|
+
export declare const isString: (x: unknown) => x is string;
|
|
89
|
+
export declare const isBigInt: (x: unknown) => x is bigint;
|
|
90
|
+
export declare const isArray: (x: unknown) => x is unknown[];
|
|
91
|
+
export declare const isFunction: (x: unknown) => x is (...args: unknown[]) => unknown;
|
|
92
|
+
export declare const isObject: (x: unknown) => x is object;
|
|
93
|
+
export declare const isNull: (x: unknown) => x is null;
|
|
94
|
+
export declare const isUndefined: (x: unknown) => x is undefined;
|
|
95
|
+
export declare const isFloat64Array: (x: unknown) => x is Float64Array;
|
|
96
|
+
export declare const isFloat32Array: (x: unknown) => x is Float32Array;
|
|
97
|
+
export declare const isInt32Array: (x: unknown) => x is Int32Array;
|
|
98
|
+
export declare const isUint32Array: (x: unknown) => x is Uint32Array;
|
|
99
|
+
export declare const isUint8Array: (x: unknown) => x is Uint8Array;
|
|
100
|
+
/**
|
|
101
|
+
* Check if value is a Complex number
|
|
102
|
+
*/
|
|
103
|
+
export declare const isComplex: (x: unknown) => x is Complex;
|
|
104
|
+
/**
|
|
105
|
+
* Check if value is a Fraction
|
|
106
|
+
*/
|
|
107
|
+
export declare const isFraction: (x: unknown) => x is Fraction;
|
|
108
|
+
/**
|
|
109
|
+
* Check if value is a BigNumber
|
|
110
|
+
*/
|
|
111
|
+
export declare const isBigNumber: (x: unknown) => x is BigNumber;
|
|
112
|
+
/**
|
|
113
|
+
* Check if value is a Matrix (duck typing until Matrix class is implemented)
|
|
114
|
+
*/
|
|
115
|
+
export declare const isMatrix: (x: unknown) => boolean;
|
|
116
|
+
/**
|
|
117
|
+
* Check if value is a DenseMatrix
|
|
118
|
+
*/
|
|
119
|
+
export declare const isDenseMatrix: (x: unknown) => boolean;
|
|
120
|
+
/**
|
|
121
|
+
* Check if value is a SparseMatrix
|
|
122
|
+
*/
|
|
123
|
+
export declare const isSparseMatrix: (x: unknown) => boolean;
|
|
124
|
+
/**
|
|
125
|
+
* Check if value is a Unit
|
|
126
|
+
*
|
|
127
|
+
* Recognises both the native {@link Unit} class (which exposes `value`,
|
|
128
|
+
* `dimensions`, and `notation`) and the legacy duck-typed shape used by
|
|
129
|
+
* mathjs-compatibility shims (`{ value, unit, type }`).
|
|
130
|
+
*/
|
|
131
|
+
export declare const isUnit: (x: unknown) => boolean;
|
|
132
|
+
/**
|
|
133
|
+
* Extended type definition with optional WASM mask support
|
|
134
|
+
*/
|
|
135
|
+
export interface MathTSTypeDef extends TypeDef {
|
|
136
|
+
/** Optional WASM type mask for accelerated dispatch (auto-registered when WASM available) */
|
|
137
|
+
wasmMask?: number;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* MathTS-specific types to add to typed-function.
|
|
141
|
+
* Note: Most primitive types (number, boolean, string, etc.) are already built into typed-function
|
|
142
|
+
*
|
|
143
|
+
* When WASM is available, custom type masks are automatically registered for efficient dispatch.
|
|
144
|
+
*/
|
|
145
|
+
export declare const MATHTS_TYPES: MathTSTypeDef[];
|
|
146
|
+
export declare const MATHTS_CONVERSIONS: ConversionDef[];
|
|
147
|
+
/**
|
|
148
|
+
* Create a new MathTS typed instance
|
|
149
|
+
*
|
|
150
|
+
* This creates an isolated typed universe with MathTS types and conversions.
|
|
151
|
+
* Uses typed-function's addType() API which automatically registers WASM
|
|
152
|
+
* type masks when available.
|
|
153
|
+
*
|
|
154
|
+
* @returns A new typed-function instance configured for MathTS
|
|
155
|
+
*
|
|
156
|
+
* @example
|
|
157
|
+
* ```typescript
|
|
158
|
+
* const myTyped = createMathTSTyped();
|
|
159
|
+
*
|
|
160
|
+
* const add = myTyped('add', {
|
|
161
|
+
* 'number, number': (a, b) => a + b,
|
|
162
|
+
* 'Complex, Complex': (a, b) => a.add(b),
|
|
163
|
+
* 'Fraction, Fraction': (a, b) => a.add(b),
|
|
164
|
+
* 'BigNumber, BigNumber': (a, b) => a.add(b),
|
|
165
|
+
* });
|
|
166
|
+
* ```
|
|
167
|
+
*/
|
|
168
|
+
export declare function createMathTSTyped(): TypedInstance;
|
|
169
|
+
/**
|
|
170
|
+
* Default MathTS typed instance
|
|
171
|
+
*
|
|
172
|
+
* This is the primary typed-function instance used throughout MathTS.
|
|
173
|
+
* It comes pre-configured with all MathTS types and conversions.
|
|
174
|
+
*
|
|
175
|
+
* @example
|
|
176
|
+
* ```typescript
|
|
177
|
+
* import { mathTyped, Complex, Fraction, BigNumber } from '@danielsimonjr/mathts-core';
|
|
178
|
+
*
|
|
179
|
+
* // Create a polymorphic add function
|
|
180
|
+
* const add = mathTyped('add', {
|
|
181
|
+
* 'number, number': (a, b) => a + b,
|
|
182
|
+
* 'Complex, Complex': (a, b) => a.add(b),
|
|
183
|
+
* 'Fraction, Fraction': (a, b) => a.add(b),
|
|
184
|
+
* 'BigNumber, BigNumber': (a, b) => a.add(b),
|
|
185
|
+
* });
|
|
186
|
+
*
|
|
187
|
+
* // Works with automatic type coercion
|
|
188
|
+
* add(1, 2); // 3
|
|
189
|
+
* add(new Complex(1, 2), new Complex(3, 4)); // Complex(4, 6)
|
|
190
|
+
* add(new Fraction(1, 2), new Fraction(1, 3)); // Fraction(5, 6)
|
|
191
|
+
* add(1, new Complex(2, 3)); // Complex(3, 3) - auto-converts
|
|
192
|
+
* ```
|
|
193
|
+
*/
|
|
194
|
+
export declare const mathTyped: MathTSTyped;
|
|
195
|
+
/**
|
|
196
|
+
* The default typed-function export (for creating functions without MathTS types)
|
|
197
|
+
*/
|
|
198
|
+
export { typed };
|
|
199
|
+
/**
|
|
200
|
+
* Create a new typed-function instance (typed-function's create)
|
|
201
|
+
*/
|
|
202
|
+
export { create };
|
|
203
|
+
/**
|
|
204
|
+
* TypeRegistry class for managing custom type registrations
|
|
205
|
+
* This is a MathTS utility, not from typed-function
|
|
206
|
+
*/
|
|
207
|
+
export declare class TypeRegistry {
|
|
208
|
+
private types;
|
|
209
|
+
private conversions;
|
|
210
|
+
private instance;
|
|
211
|
+
/**
|
|
212
|
+
* Register a new type
|
|
213
|
+
*/
|
|
214
|
+
registerType<T>(name: string, test: (x: unknown) => x is T): this;
|
|
215
|
+
/**
|
|
216
|
+
* Register a type conversion
|
|
217
|
+
*/
|
|
218
|
+
registerConversion<From, To>(from: string, to: string, convert: (value: From) => To): this;
|
|
219
|
+
/**
|
|
220
|
+
* Check if a type is registered
|
|
221
|
+
*/
|
|
222
|
+
hasType(name: string): boolean;
|
|
223
|
+
/**
|
|
224
|
+
* Check if a conversion is registered
|
|
225
|
+
*/
|
|
226
|
+
hasConversion(from: string, to: string): boolean;
|
|
227
|
+
/**
|
|
228
|
+
* Get all registered type names
|
|
229
|
+
*/
|
|
230
|
+
getTypeNames(): string[];
|
|
231
|
+
/**
|
|
232
|
+
* Build a typed-function instance from the registry
|
|
233
|
+
*/
|
|
234
|
+
build(): TypedInstance;
|
|
235
|
+
/**
|
|
236
|
+
* Clear all registered types and conversions
|
|
237
|
+
*/
|
|
238
|
+
clear(): void;
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* Helper to create a typed function with the MathTS typed instance
|
|
242
|
+
*/
|
|
243
|
+
export declare function createTypedFunction<T>(name: string, signatures: {
|
|
244
|
+
[signature: string]: (...args: unknown[]) => T;
|
|
245
|
+
}, typedInstance?: TypedInstance): (...args: unknown[]) => T;
|
|
246
|
+
//# sourceMappingURL=mathts-typed.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mathts-typed.d.ts","sourceRoot":"","sources":["../../src/typed/mathts-typed.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,KAAK,EACV,aAAa,EACb,aAAa,EACb,iBAAiB,EACjB,OAAO,EACP,WAAW,EACZ,MAAM,gBAAgB,CAAC;AAMxB;;;;;;;;GAQG;AACH,wBAAsB,aAAa,CAAC,OAAO,GAAE;IAAE,UAAU,CAAC,EAAE,OAAO,CAAA;CAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAgB5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C,GAAG,IAAI,CAIhE;IAED;;OAEG;IACH,kBAAkB,CAAC,IAAI,EAAE,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,KAAK,EAAE,IAAI,KAAK,EAAE,GAAG,IAAI,CASzF;IAED;;OAEG;IACH,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAE7B;IAED;;OAEG;IACH,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,OAAO,CAE/C;IAED;;OAEG;IACH,YAAY,IAAI,MAAM,EAAE,CAEvB;IAED;;OAEG;IACH,KAAK,IAAI,aAAa,CAQrB;IAED;;OAEG;IACH,KAAK,IAAI,IAAI,CAIZ;CACF;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,CAAC,EACnC,IAAI,EAAE,MAAM,EACZ,UAAU,EAAE;IAAE,CAAC,SAAS,EAAE,MAAM,GAAG,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,CAAC,CAAA;CAAE,EAC9D,aAAa,GAAE,aAAyB,GACvC,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,CAAC,CAE3B"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Add duck-typing markers to the prototypes of the native Complex, Fraction and BigNumber classes.
|
|
3
|
+
*
|
|
4
|
+
* The function adds each marker only when the prototype does not have it.
|
|
5
|
+
* The markers are not writable, not enumerable and not configurable.
|
|
6
|
+
* Calls after the first call do nothing.
|
|
7
|
+
*/
|
|
8
|
+
export declare function registerNativeTypes(): void;
|
|
9
|
+
//# sourceMappingURL=type-bridge.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type-bridge.d.ts","sourceRoot":"","sources":["../../src/typed/type-bridge.ts"],"names":[],"mappings":"AAeA;;;;;;GAMG;AACH,wBAAgB,mBAAmB,IAAI,IAAI,CAyD1C"}
|