@danielsimonjr/mathts-compat 0.1.9 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +17 -0
- package/dist/index.js +33 -2
- package/package.json +4 -4
package/dist/index.d.ts
CHANGED
|
@@ -200,6 +200,21 @@ declare const shims: {
|
|
|
200
200
|
NaN: number;
|
|
201
201
|
};
|
|
202
202
|
|
|
203
|
+
/**
|
|
204
|
+
* GC12 — mathjs-style fluent `chain` API.
|
|
205
|
+
*
|
|
206
|
+
* chain(3).add(4).multiply(2).done() // 14
|
|
207
|
+
*
|
|
208
|
+
* Each math function `f` becomes a chain method that calls `f(value, ...args)`
|
|
209
|
+
* and returns a new chain wrapping the result. `.done()` / `.valueOf()` unwrap.
|
|
210
|
+
*/
|
|
211
|
+
interface Chain {
|
|
212
|
+
done(): unknown;
|
|
213
|
+
valueOf(): unknown;
|
|
214
|
+
toString(): string;
|
|
215
|
+
[method: string]: (...args: unknown[]) => Chain | unknown;
|
|
216
|
+
}
|
|
217
|
+
|
|
203
218
|
/**
|
|
204
219
|
* @danielsimonjr/mathts-compat - mathjs Compatibility Layer
|
|
205
220
|
*
|
|
@@ -245,6 +260,8 @@ interface MathInstance {
|
|
|
245
260
|
* `unknown` and can be narrowed by the caller.
|
|
246
261
|
*/
|
|
247
262
|
[name: string]: unknown;
|
|
263
|
+
/** Fluent chain: `math.chain(x).add(3).done()`. */
|
|
264
|
+
chain: (value: unknown) => Chain;
|
|
248
265
|
config: (newConfig?: Partial<MathJSConfig>) => MathJSConfig;
|
|
249
266
|
complex: typeof shims.complex;
|
|
250
267
|
fraction: typeof shims.fraction;
|
package/dist/index.js
CHANGED
|
@@ -378,6 +378,30 @@ var shims = {
|
|
|
378
378
|
NaN: NaN_
|
|
379
379
|
};
|
|
380
380
|
|
|
381
|
+
// src/chain.ts
|
|
382
|
+
function createChain(math) {
|
|
383
|
+
function chain(value) {
|
|
384
|
+
const base = {
|
|
385
|
+
done: () => value,
|
|
386
|
+
valueOf: () => value,
|
|
387
|
+
toString: () => String(value)
|
|
388
|
+
};
|
|
389
|
+
return new Proxy(base, {
|
|
390
|
+
get(target, prop) {
|
|
391
|
+
if (prop in target || typeof prop === "symbol") {
|
|
392
|
+
return target[prop];
|
|
393
|
+
}
|
|
394
|
+
const fn = math[prop];
|
|
395
|
+
if (typeof fn === "function") {
|
|
396
|
+
return (...args) => chain(fn(value, ...args));
|
|
397
|
+
}
|
|
398
|
+
return void 0;
|
|
399
|
+
}
|
|
400
|
+
});
|
|
401
|
+
}
|
|
402
|
+
return chain;
|
|
403
|
+
}
|
|
404
|
+
|
|
381
405
|
// src/index.ts
|
|
382
406
|
import * as mathFunctions from "@danielsimonjr/mathts-functions";
|
|
383
407
|
import {
|
|
@@ -405,7 +429,7 @@ var defaultConfig = {
|
|
|
405
429
|
};
|
|
406
430
|
function create(factories = all, config = {}) {
|
|
407
431
|
const currentConfig = { ...defaultConfig, ...config };
|
|
408
|
-
|
|
432
|
+
const instance = {
|
|
409
433
|
// Full @danielsimonjr/mathts-functions namespace — det, integrate, eigs,
|
|
410
434
|
// simplify, and the rest. The compat-specific shims below overlay it.
|
|
411
435
|
...factories,
|
|
@@ -485,8 +509,15 @@ function create(factories = all, config = {}) {
|
|
|
485
509
|
SQRT2: shims.SQRT2,
|
|
486
510
|
SQRT1_2: shims.SQRT1_2,
|
|
487
511
|
Infinity: shims.Infinity,
|
|
488
|
-
NaN: shims.NaN
|
|
512
|
+
NaN: shims.NaN,
|
|
513
|
+
// Placeholder; rebound below once `instance` exists so chain methods can
|
|
514
|
+
// resolve against the full surfaced namespace.
|
|
515
|
+
chain: (() => {
|
|
516
|
+
throw new Error("chain not initialized");
|
|
517
|
+
})
|
|
489
518
|
};
|
|
519
|
+
instance.chain = createChain(instance);
|
|
520
|
+
return instance;
|
|
490
521
|
}
|
|
491
522
|
var all = {
|
|
492
523
|
...mathFunctions
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@danielsimonjr/mathts-compat",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "mathjs compatibility layer for MathTS",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -25,9 +25,9 @@
|
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"@danielsimonjr/mathts-core": "^0.1.5",
|
|
28
|
-
"@danielsimonjr/mathts-functions": "^0.
|
|
29
|
-
"@danielsimonjr/mathts-matrix": "^0.1.
|
|
30
|
-
"@danielsimonjr/mathts-parallel": "^0.
|
|
28
|
+
"@danielsimonjr/mathts-functions": "^0.3.0",
|
|
29
|
+
"@danielsimonjr/mathts-matrix": "^0.1.10",
|
|
30
|
+
"@danielsimonjr/mathts-parallel": "^0.3.0"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"@types/node": "^25.5.2",
|